:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --text: #1a2332;
    --muted: #5c6b7a;
    --border: #dde3ea;
    --primary: #0f4c81;
    --primary-soft: #e8f1f8;
    --done: #1f7a4d;
    --done-soft: #e8f6ee;
    --current: #b45309;
    --current-soft: #fff4e5;
    --future: #475569;
    --future-soft: #f1f5f9;
    --blocked: #b42318;
    --blocked-soft: #fdecea;
    --shadow: 0 10px 30px rgba(15, 28, 45, 0.08);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #eef3f7 0%, var(--bg) 220px);
    line-height: 1.5;
}

.container {
    width: min(1100px, calc(100% - 2rem));
    margin: 0 auto;
}

.site-header {
    padding: 2rem 0 1rem;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.eyebrow {
    margin: 0 0 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    color: var(--muted);
    font-weight: 700;
}

h1 {
    margin: 0;
    font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.subtitle {
    margin: 0.5rem 0 0;
    color: var(--muted);
    max-width: 60ch;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.dashboard {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    padding: 1.25rem;
}

.stat-card h2,
.edit-toolbar h2,
.modal h2 {
    margin: 0 0 1rem;
    font-size: 1rem;
}

.stat-list,
.legend {
    list-style: none;
    margin: 0;
    padding: 0;
}

.stat-list li,
.legend li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.dot-done { background: var(--done); }
.dot-progress { background: var(--current); }
.dot-pending { background: #64748b; }
.dot-blocked { background: var(--blocked); }

.progress-ring {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    margin: 0.5rem 0 1rem;
    background:
        radial-gradient(closest-side, white 78%, transparent 80% 100%),
        conic-gradient(var(--primary) calc(var(--percent) * 1%), #e2e8f0 0);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
}

.progress-bar {
    height: 8px;
    background: #e8edf2;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.35rem;
}

.progress-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #2d7cc1);
}

.muted {
    color: var(--muted);
    margin: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-edit {
    background: var(--primary-soft);
    color: var(--primary);
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 0.65rem 1rem;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
}

.btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.85rem;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-secondary {
    background: #e8eef5;
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
}

.pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
}

.pill-done { background: var(--done-soft); color: var(--done); }
.pill-current { background: var(--current-soft); color: var(--current); }
.pill-future { background: var(--future-soft); color: var(--future); }
.pill-blocked { background: var(--blocked-soft); color: var(--blocked); }

.schedule-warnings {
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border-color: #f0d7a7;
    background: #fffaf0;
}

.schedule-warnings h2 {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
    color: #9a6700;
}

.schedule-warnings ul {
    margin: 0;
    padding-left: 1.2rem;
    color: #7a5c00;
    font-size: 0.9rem;
}

.edit-toolbar {
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    border-color: #c9daf0;
    background: #f8fbff;
}

.toolbar-grid {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.timeline {
    position: relative;
    margin-bottom: 3rem;
}

.timeline::before {
    display: none;
}

.timeline-module {
    margin: 0 0 0.5rem;
    position: relative;
    box-shadow: none;
}

.module-block {
    margin-bottom: 0.75rem;
}

.module-block .timeline-module {
    border-radius: var(--radius);
    overflow: hidden;
}

.module-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

.module-header:hover {
    background: #f8fafc;
}

.module-header:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}

.module-toggle-icon {
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    display: grid;
    place-items: center;
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 4px;
    margin-top: 0.15rem;
}

.module-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.module-head-main {
    flex: 1;
    min-width: 200px;
}

.module-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.module-block.is-expanded .module-desc {
    -webkit-line-clamp: unset;
}

.module-meta {
    min-width: 180px;
}

.module-tasks {
    padding-left: 1.25rem;
    position: relative;
}

.module-tasks::before {
    content: "";
    position: absolute;
    left: 0.45rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(var(--border), #c9d4e1);
}

.module-block.is-expanded .module-tasks {
    padding-top: 0.25rem;
    padding-bottom: 0.5rem;
}

.module-id,
.task-id {
    margin: 0 0 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 600;
}

.module-head h2,
.task-head h3 {
    margin: 0 0 0.35rem;
}

.module-meta {
    min-width: 220px;
}

.module-notes,
.task-notes {
    margin: 0.75rem 0 0;
    font-size: 0.92rem;
}

.timeline-item {
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
    position: relative;
}

.timeline-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    margin-top: 1.35rem;
    background: #94a3b8;
    border: 3px solid var(--surface);
    box-shadow: 0 0 0 2px #cbd5e1;
    z-index: 1;
}

.timeline-content {
    padding: 1rem 1.1rem;
}

.state-done .timeline-marker { background: var(--done); box-shadow: 0 0 0 2px #9fd4b4; }
.state-current .timeline-marker { background: var(--current); box-shadow: 0 0 0 2px #f2c98d; }
.state-future .timeline-marker { background: #64748b; }
.state-blocked .timeline-marker { background: var(--blocked); box-shadow: 0 0 0 2px #f1a9a3; }

.state-done .timeline-content { border-left: 4px solid var(--done); }
.state-current .timeline-content,
.is-current-task .timeline-content {
    border-left: 4px solid var(--current);
    background: linear-gradient(90deg, var(--current-soft), #fff 45%);
    box-shadow: 0 0 0 1px rgba(180, 83, 9, 0.15), var(--shadow);
}
.state-future .timeline-content { border-left: 4px solid #94a3b8; }
.state-blocked .timeline-content { border-left: 4px solid var(--blocked); background: linear-gradient(90deg, var(--blocked-soft), #fff 45%); }

.is-current-task .timeline-marker {
    width: 18px;
    height: 18px;
    margin-top: 1.25rem;
    background: var(--current);
    box-shadow: 0 0 0 3px #f2c98d, 0 0 0 6px rgba(180, 83, 9, 0.12);
    animation: pulse-current 2.5s ease-in-out infinite;
}

.pill-current-strong {
    font-size: 0.82rem;
    padding: 0.3rem 0.65rem;
    box-shadow: 0 0 0 1px rgba(180, 83, 9, 0.2);
}

.task-description {
    margin: 0;
    color: var(--muted);
    font-size: 0.92rem;
}

@keyframes pulse-current {
    0%, 100% { box-shadow: 0 0 0 3px #f2c98d, 0 0 0 6px rgba(180, 83, 9, 0.12); }
    50% { box-shadow: 0 0 0 3px #f2c98d, 0 0 0 10px rgba(180, 83, 9, 0.06); }
}

#btn-goto-current {
    font-weight: 600;
}

.task-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.task-badges {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    align-content: flex-start;
}

.task-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin: 1rem 0 0;
}

.task-meta div {
    background: #f8fafc;
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
}

.task-meta dt {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.task-meta dd {
    margin: 0.15rem 0 0;
    font-weight: 600;
}

.task-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.modal {
    border: none;
    border-radius: 16px;
    padding: 0;
    width: min(520px, calc(100vw - 2rem));
    box-shadow: var(--shadow);
}

.modal::backdrop {
    background: rgba(15, 23, 42, 0.45);
}

.modal form {
    padding: 1.25rem;
}

.modal label {
    display: block;
    margin-bottom: 0.85rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.modal input,
.modal textarea,
.modal select {
    width: 100%;
    margin-top: 0.35rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
    font: inherit;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.hint {
    font-size: 0.85rem;
    color: var(--muted);
    margin: 0;
}

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    background: #102a43;
    color: #fff;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 1000;
}

.toast.error {
    background: var(--blocked);
}

.is-current-task.scroll-highlight .timeline-content {
    animation: flash-current 0.6s ease 2;
}

@keyframes flash-current {
    0%, 100% { box-shadow: 0 0 0 1px rgba(180, 83, 9, 0.15), var(--shadow); }
    50% { box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.35), var(--shadow); }
}

@media (max-width: 700px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .header-inner,
    .module-head,
    .task-head {
        flex-direction: column;
    }
}
