:root {
    --primary: #0052cc;
    --primary-hover: #0065ff;
    --bg-page: #f4f5f7;
    --bg-card: #ffffff;
    --text-main: #172b4d;
    --text-sec: #5e6c84;
    --border: #dfe1e6;
    --radius: 8px;
    --shadow-card: 0 1px 2px rgba(9, 30, 66, 0.25);
    --shadow-hover: 0 4px 8px rgba(9, 30, 66, 0.25);
    
    /* Status Colors (Pastel) */
    --st-todo-bg: #dfe1e6; --st-todo-tx: #42526e;
    --st-prog-bg: #deebff; --st-prog-tx: #0052cc;
    --st-done-bg: #e3fcef; --st-done-tx: #006644;
    --st-wait-bg: #fffae6; --st-wait-tx: #ff8b00;
}

/* --- RESET & BASE --- */
.ap-wrap * { box-sizing: border-box; }
.ap-wrap { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; 
    color: var(--text-main); 
    max-width: 1400px; 
    margin: 0 auto; 
    padding: 20px;
}

/* --- HEADER & TOOLBAR --- */
.ap-head-row { 
    display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 25px; padding-bottom: 20px; border-bottom: 1px solid var(--border); 
}
.ap-head-row h2 { margin: 0; font-size: 24px; font-weight: 600; color: var(--text-main); }

.ap-toolbar { 
    display: flex; gap: 15px; margin-bottom: 25px; 
    background: var(--bg-card); padding: 10px 20px; 
    border-radius: var(--radius); border: 1px solid var(--border);
    align-items: center; flex-wrap: wrap; 
}

.ap-filter { 
    padding: 8px 12px; border: 1px solid var(--border); 
    border-radius: 4px; font-size: 14px; color: var(--text-main); 
    background-color: #fafbfc; min-width: 160px; cursor: pointer;
}
.ap-filter:hover { background-color: #ebecf0; }

/* TABS */
.ap-tabs { display: flex; gap: 5px; background: #ebecf0; padding: 4px; border-radius: 6px; }
.ap-tab-btn { 
    background: transparent; border: none; font-size: 14px; font-weight: 500; 
    cursor: pointer; padding: 6px 16px; color: var(--text-sec); 
    border-radius: 4px; transition: all 0.2s; 
}
.ap-tab-btn:hover { color: var(--text-main); background: rgba(255,255,255,0.5); }
.ap-tab-btn.active { background: var(--bg-card); color: var(--primary); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* --- KANBAN BOARD --- */
.ap-board { 
    display: flex; gap: 20px; overflow-x: auto; 
    padding-bottom: 20px; align-items: flex-start; height: 78vh; 
}

.ap-col { 
    flex: 1; min-width: 250px; max-width: 250px;
    background: var(--bg-page); border-radius: 12px; 
    padding: 12px; display: flex; flex-direction: column; 
    max-height: 100%; border: 1px solid transparent;
}

.ap-col-h { 
    font-weight: 700; margin: 0 0 15px 5px; color: var(--text-sec); 
    text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; 
    display: flex; justify-content: space-between; align-items: center;
}

.ap-col-list { 
    flex: 1; overflow-y: auto; padding: 2px 5px; min-height: 100px; 
}

/* --- CARDS --- */
.ap-card { 
    background: var(--bg-card); padding: 16px; margin-bottom: 12px; 
    border-radius: 8px; box-shadow: var(--shadow-card); 
    border: 1px solid transparent; border-left: 4px solid #ccc; 
    cursor: pointer; transition: all 0.2s cubic-bezier(0.2, 0, 0, 1); 
    position: relative; 
}
.ap-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: var(--primary-hover); }

/* Priority Colors */
.ap-card.p-high { border-left-color: #ff5630; }
.ap-card.p-normal { border-left-color: #36b37e; } /* Verde per normale è meglio del blu */
.ap-card.p-low { border-left-color: #6554c0; }

.ap-card-t { 
    font-weight: 600; display: block; margin-bottom: 10px; 
    color: var(--text-main); font-size: 15px; line-height: 1.4; 
}

.ap-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }

/* Badges & Avatars */
.ap-cl { 
    background: #ebecf0; color: var(--text-sec); 
    padding: 2px 8px; border-radius: 10px; 
    font-size: 11px; font-weight: 600; 
}
.ap-av img { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.1); width: 24px; height: 24px; }
.ap-rec-icon { position: absolute; top: 12px; right: 12px; font-size: 12px; opacity: 0.5; }

/* --- MODAL (IMPROVED) --- */
.ap-modal-ov { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(23, 43, 77, 0.6); backdrop-filter: blur(2px);
    z-index: 99999; display: none; align-items: center; justify-content: center; 
}

.ap-modal { 
    background: var(--bg-card); width: 95%; max-width: 1100px; 
    height: 90vh; border-radius: 12px; 
    box-shadow: 0 0 0 1px rgba(9,30,66,0.08), 0 20px 60px rgba(9,30,66,0.4); 
    display: flex; flex-direction: column; overflow: hidden; 
}

.ap-m-head { 
    height: 70px; min-height: 70px; padding: 0 30px; 
    border-bottom: 1px solid var(--border); display: flex; 
    justify-content: space-between; align-items: center; 
    background: #fff; flex-shrink: 0; 
}
.ap-m-head h3 { margin: 0; font-size: 18px; color: var(--text-sec); font-weight: 500; }

.ap-m-body { height: calc(90vh - 70px); display: flex; overflow: hidden; width: 100%; } 

/* Contenuto Principale (Sinistra) */
.ap-m-main { 
    flex: 3; height: 100%; overflow-y: auto; 
    padding: 40px; background: #fff; 
}
.ap-m-main h2 { font-size: 26px; margin-bottom: 20px; line-height: 1.3; color: var(--text-main); }
.ap-m-main p { font-size: 15px; line-height: 1.6; color: #444; }

/* Sidebar (Destra) */
.ap-m-side { 
    flex: 1; min-width: 320px; max-width: 400px; 
    height: 100%; overflow-y: auto; 
    background: #fafbfc; border-left: 1px solid var(--border); 
    padding: 30px; 
}

/* Input Fields in Sidebar */
.ap-edit-group { margin-bottom: 20px; }
.ap-edit-label { font-size: 11px; text-transform: uppercase; font-weight: 700; color: var(--text-sec); margin-bottom: 6px; display: block; letter-spacing: 0.5px; }
.ap-edit-input { 
    width: 100%; padding: 10px; border: 1px solid #dfe1e6; 
    border-radius: 4px; background: #fff; font-size: 14px; 
    color: var(--text-main); transition: border 0.2s, box-shadow 0.2s;
}
.ap-edit-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(76, 154, 255, 0.3); outline: none; }
.ap-edit-input:hover { background-color: #ebecf0; }

/* Checklist Styling */
.ap-chk-item { 
    display: flex; align-items: center; margin-bottom: 8px; 
    padding: 8px 12px; border-radius: 6px; background: #fff; 
    border: 1px solid transparent; transition: all 0.2s; 
}
.ap-chk-item:hover { background: #f4f5f7; border-color: #dfe1e6; }
.ap-chk-done span { text-decoration: line-through; color: #a5adba; }
.ap-chk-del { margin-left: auto; color: #de350b; cursor: pointer; opacity: 0; font-size: 14px; }
.ap-chk-item:hover .ap-chk-del { opacity: 1; }
.ap-chk-bar { height: 8px; background: #ebecf0; border-radius: 4px; margin: 15px 0; overflow: hidden; }
.ap-chk-prog { height: 100%; background: #36b37e; transition: width 0.4s ease; }

/* Comments */
.ap-comm { 
    background: #fff; border: 1px solid var(--border); 
    padding: 15px; margin-bottom: 15px; border-radius: 8px; 
    font-size: 14px; 
}
.ap-comm strong { color: var(--text-main); font-weight: 600; }
.ap-new-comm textarea { 
    width: 100%; padding: 12px; border: 1px solid var(--border); 
    border-radius: 6px; min-height: 80px; font-family: inherit; font-size: 14px;
    margin-bottom: 10px;
}
.ap-new-comm textarea:focus { border-color: var(--primary); outline: none; }

/* Buttons */
.ap-btn { 
    padding: 8px 16px; background: var(--primary); color: #fff; 
    border: none; border-radius: 4px; font-weight: 600; cursor: pointer; 
    transition: background 0.1s; font-size: 13px;
}
.ap-btn:hover { background: var(--primary-hover); }

/* Status Badges in Sidebar */
.ap-badge { padding: 4px 8px; border-radius: 4px; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.ap-status-todo { background: var(--st-todo-bg); color: var(--st-todo-tx); }
.ap-status-progress { background: var(--st-prog-bg); color: var(--st-prog-tx); }
.ap-status-review_int { background: #fff0b3; color: #172b4d; }
.ap-status-done { background: var(--st-done-bg); color: var(--st-done-tx); }

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c7d0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a5adba; }

/* Animation Flash */
.ap-saved-flash { animation: flash 1s ease-out; }
@keyframes flash { 0% { background-color: #e3fcef; border-color: #36b37e; } 100% { background-color: #fff; border-color: #dfe1e6; } }

/* Mobile */
@media (max-width: 768px) {
    .ap-m-body { flex-direction: column; height: auto !important; overflow-y: auto; }
    .ap-m-main, .ap-m-side { height: auto !important; width: 100%; border: none; }
    .ap-modal { height: 100%; max-height: 100%; border-radius: 0; }
    .ap-toolbar { flex-direction: column; align-items: stretch; }
}