:root {
    --bg: #09111f;
    --bg-accent: #101c31;
    --surface: rgba(10, 18, 32, 0.94);
    --surface-strong: #111c2e;
    --surface-soft: #162338;
    --surface-elevated: #1a2940;
    --border: #233551;
    --border-strong: #31507b;
    --text: #edf3ff;
    --text-muted: #9fb0cb;
    --primary: #7ab6ff;
    --primary-strong: #5f9df0;
    --success: #34c38f;
    --success-strong: #249c70;
    --warning: #f7b84b;
    --warning-strong: #de9e39;
    --danger: #f46a6a;
    --danger-strong: #d95454;
    --critical: #f46a6a;
    --high: #ff9252;
    --medium: #f7b84b;
    --low: #34c38f;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: radial-gradient(circle at top, #183256 0%, var(--bg) 52%, #060b14 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text);
}

button, input, select, textarea { font: inherit; }

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid rgba(122, 182, 255, 0.14);
    border-radius: 20px;
    box-shadow: var(--shadow);
    overflow: hidden;
    backdrop-filter: blur(12px);
}

.header {
    background: linear-gradient(135deg, #132845 0%, #1b3f69 55%, #24578f 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

.header h1 { font-size: clamp(2rem, 3vw, 2.6rem); margin-bottom: 10px; }
.header p { font-size: 1rem; opacity: 0.9; }

.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    padding: 20px 30px;
    background: var(--surface-strong);
    border-bottom: 1px solid var(--border);
}

.stat-card {
    background: linear-gradient(180deg, rgba(26, 41, 64, 0.96) 0%, rgba(17, 28, 46, 0.96) 100%);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(122, 182, 255, 0.12);
}

.stat-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: 0.9rem; margin-top: 5px; }

.controls {
    padding: 20px 30px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: end;
}

.filter-group { display: flex; flex-direction: column; gap: 8px; min-width: 150px; }
.search-group { flex: 1 1 280px; min-width: 240px; }
.filter-group label { font-weight: 600; color: var(--text-muted); }

select,
input[type="text"],
textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s;
    background: var(--surface-soft);
    color: var(--text);
}

select:focus,
input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(122, 182, 255, 0.18);
}

input::placeholder,
textarea::placeholder { color: #7890b4; }

#taskDescription { width: 100% !important; display: block; resize: none !important; min-height: 200px !important; }
#newNoteText { width: 100% !important; display: block; resize: none !important; min-height: 200px !important; }

/* Note editor in edit task */
.note-editor { width: 100% !important; display: block; resize: none !important; min-height: 200px !important; }


.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #07111f; }
.btn-primary:hover { background: var(--primary-strong); }
.btn-success { background: var(--success); color: #06150f; }
.btn-success:hover { background: var(--success-strong); }
.btn-warning { background: var(--warning); color: #251606; }
.btn-warning:hover { background: var(--warning-strong); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-strong); }
.btn:not(.btn-primary):not(.btn-success):not(.btn-warning):not(.btn-danger) {
    background: var(--surface-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}

.content { padding: 30px; min-height: 300px; }
.empty-state {
    color: var(--text-muted);
    padding: 30px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    text-align: center;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: min(420px, calc(100vw - 48px));
    padding: 14px 16px;
    border: 1px solid;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    background: var(--surface-strong);
}

.toast.is-error {
    color: #ffb3b3;
    background: #2a1620;
    border-color: rgba(244, 106, 106, 0.5);
}

.toast.is-success {
    color: #9ae6c2;
    background: #10261f;
    border-color: rgba(52, 195, 143, 0.5);
}

.toast-close {
    margin-left: auto;
    background: none;
    border: 0;
    color: inherit;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.phase-section { margin-bottom: 36px; }
.phase-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-strong);
}

.phase-title { font-size: 1.5rem; font-weight: 700; }

.phase-badge {
    padding: 5px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}

.badge-pre { background: rgba(81, 164, 255, 0.18); color: #95c9ff; }
.badge-tday { background: rgba(247, 184, 75, 0.18); color: #ffd489; }
.badge-post { background: rgba(52, 195, 143, 0.18); color: #88e0b8; }

.task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.task-card {
    background: linear-gradient(180deg, rgba(22, 35, 56, 0.98) 0%, rgba(17, 28, 46, 0.98) 100%);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(122, 182, 255, 0.1);
    border-left: 5px solid var(--border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.task-card:hover { transform: translateY(-3px); box-shadow: 0 14px 28px rgba(0, 0, 0, 0.28); }
.task-card.completed { opacity: 0.8; }
.task-card.critical { border-left-color: var(--critical); }
.task-card.high { border-left-color: var(--high); }
.task-card.medium { border-left-color: var(--medium); }
.task-card.low { border-left-color: var(--low); }

.task-header {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.task-title { font-size: 1.08rem; font-weight: 700; }
.task-id {
    background: rgba(122, 182, 255, 0.12);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    white-space: nowrap;
}

.task-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.meta-tag {
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.tag-owner { background: rgba(81, 164, 255, 0.16); color: #95c9ff; }
.tag-category { background: rgba(122, 182, 255, 0.1); color: #d6e1f5; }
.tag-priority-critical { background: rgba(244, 106, 106, 0.18); color: #ffaaaa; }
.tag-priority-high { background: rgba(255, 146, 82, 0.2); color: #ffbe8a; }
.tag-priority-medium { background: rgba(247, 184, 75, 0.18); color: #ffd489; }
.tag-priority-low { background: rgba(52, 195, 143, 0.18); color: #88e0b8; }

.timeline,
.task-status,
.task-note-count {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.task-description {
    color: #d6e1f5;
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 12px;
}

.task-card-hint {
    margin-top: 16px;
    font-size: 0.78rem;
    color: #7890b4;
}

.progress-section {
    background: var(--surface-strong);
    padding: 20px 30px 30px;
    border-top: 1px solid var(--border);
}

.progress-top {
    border-top: 0;
    border-bottom: 1px solid var(--border);
}

.card-status-select {
    margin-left: 6px;
    padding: 3px 8px;
    color: var(--text);
    background: var(--surface-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    cursor: pointer;
}

.progress-bar-container {
    position: relative;
    background: rgba(122, 182, 255, 0.1);
    border-radius: 10px;
    height: 30px;
    overflow: hidden;
    margin-top: 10px;
    border: 1px solid rgba(122, 182, 255, 0.08);
}

.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #2f6fb8 0%, #5b9df7 100%);
    transition: width 0.3s ease;
}

.progress-label {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin-top: 20px;
    padding: 15px;
    background: rgba(9, 17, 31, 0.55);
    border-radius: 8px;
    border: 1px solid rgba(122, 182, 255, 0.08);
}

.legend-item { display: flex; align-items: center; gap: 8px; color: var(--text-muted); }
.legend-color { width: 18px; height: 18px; border-radius: 4px; }
.legend-color.critical { background: var(--critical); }
.legend-color.high { background: var(--high); }
.legend-color.medium { background: var(--medium); }
.legend-color.low { background: var(--low); }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 12, 0.78);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.modal {
    background: linear-gradient(180deg, rgba(17, 28, 46, 0.98) 0%, rgba(10, 18, 32, 0.98) 100%);
    border: 1px solid rgba(122, 182, 255, 0.14);
    border-radius: 16px;
    box-shadow: var(--shadow);
    width: min(1100px, 100%);
    max-height: 90vh;
    overflow: auto;
    padding: 28px;
}

.modal-wide { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr); gap: 24px; }
.modal-wide.create-mode { grid-template-columns: minmax(320px, 640px); justify-content: center; }
.modal-wide.create-mode #taskForm { width: 100%; margin: 0 auto; }
.modal-header { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 1.5rem; font-weight: 700; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
}

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 8px; color: var(--text-muted); font-weight: 600; }
.form-span-2 { grid-column: span 2; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 8px;
}

.notes-panel {
    background: rgba(9, 17, 31, 0.55);
    border: 1px solid rgba(122, 182, 255, 0.08);
    border-radius: 14px;
    padding: 18px;
}

.notes-panel-header { margin-bottom: 14px; }
.notes-panel-header h3 { margin-bottom: 6px; }
.notes-panel-header p { color: var(--text-muted); font-size: 0.92rem; }

.note-entry-form { margin-bottom: 20px; }
.note-entry-form label { display: block; margin-bottom: 8px; color: var(--text-muted); font-weight: 600; }
.note-form-actions { display: flex; justify-content: flex-end; margin-top: 10px; }

.notes-history { display: flex; flex-direction: column; gap: 14px; }

.note-item {
    border: 1px solid rgba(122, 182, 255, 0.08);
    border-radius: 12px;
    padding: 14px;
    background: rgba(17, 28, 46, 0.72);
}

.note-meta { margin-bottom: 8px; color: var(--text-muted); font-size: 0.82rem; }
.note-editor { min-height: 90px; }
.note-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

.hidden { display: none !important; }

.main-nav {
    display: inline-flex;
    gap: 8px;
    margin-top: 6px;
    padding: 4px;
    background: rgba(9, 17, 31, 0.45);
    border-radius: 999px;
}

.nav-link {
    padding: 8px 22px;
    border-radius: 999px;
    color: #cfe0ff;
    text-decoration: none;
    font-weight: 600;
}

.nav-link:hover { background: rgba(122, 182, 255, 0.18); }
.nav-link.is-active { background: var(--primary-strong); color: #07101f; }

.kpi-page { padding: 30px; }

.kpi-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    text-align: center;
}

.kpi-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.kpi-label { margin-top: 2px; font-weight: 600; }
.kpi-hint { margin-top: 4px; font-size: 0.8rem; color: var(--text-muted); }
.kpi-card.is-danger .kpi-value { color: var(--danger); }
.kpi-card.is-warning .kpi-value { color: var(--warning); }
.kpi-card.is-ok .kpi-value { color: var(--success); }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.kpi-panel {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 20px;
}

.kpi-panel h2 { font-size: 1.05rem; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { margin-bottom: 0; }
.kpi-note { margin-bottom: 12px; font-size: 0.82rem; color: var(--text-muted); }
.seg-toggle { display: inline-flex; padding: 3px; background: var(--surface-elevated); border-radius: 999px; }
.seg-btn { padding: 4px 14px; border: 0; border-radius: 999px; background: none; color: var(--text-muted); cursor: pointer; font-weight: 600; }
.seg-btn.is-active { background: var(--primary-strong); color: #07101f; }

.donut-wrap { display: flex; align-items: center; gap: 24px; }
.donut-wrap svg { width: 150px; height: 150px; flex: none; }
.chart-legend { list-style: none; display: grid; gap: 8px; color: var(--text-muted); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; }

.hbars { display: grid; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: 110px 1fr 56px; align-items: center; gap: 10px; font-size: 0.88rem; }
.hbar-label { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { display: flex; height: 16px; background: var(--surface-elevated); border-radius: 8px; overflow: hidden; }
.hbar-seg { height: 100%; }
.hbar-value { text-align: right; font-weight: 600; }
.seg-done { background: var(--success); }
.seg-open { background: #5b6b86; }
.seg-critical { background: var(--critical); }
.seg-high { background: var(--high); }
.seg-medium { background: var(--medium); }
.seg-low { background: var(--low); }

.kpi-list { list-style: none; display: grid; gap: 10px; max-height: 320px; overflow: auto; }
.kpi-list li { display: grid; gap: 2px; padding: 10px 12px; background: var(--surface-soft); border-radius: 10px; }
.kpi-list-title { font-weight: 600; }
.kpi-list-meta, .kpi-empty { font-size: 0.82rem; color: var(--text-muted); }

@media (max-width: 900px) {
    .modal-wide { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    body { padding: 12px; }
    .controls { align-items: stretch; }
    .filter-group, .search-group { width: 100%; }
    .form-row { grid-template-columns: 1fr; }
    .form-span-2 { grid-column: auto; }
}
