:root {
    --primary: #2364aa;
    --primary-strong: #0d3b66;
    --accent: #f4a261;
    --success: #2a9d8f;
    --danger: #d1495b;
    --bg: #eef3f7;
    --card: #ffffff;
    --card-alt: #f7fafc;
    --text: #16212b;
    --subtext: #586776;
    --border: #d5e1ea;
    --shadow: 0 18px 50px rgba(13, 59, 102, 0.08);
    --axis: #90a1b2;
    --target: #f6c453;
    --limit: #ba68c8;
    --work: #2196f3;
    --business: #ff9800;
    --gap-hover: rgba(22, 33, 43, 0.06);
    --stat-bg: rgba(35, 100, 170, 0.08);
    --timeline-bg: rgba(127, 127, 127, 0.15);
    --tooltip-bg: #ffffff;
    --deduction-stripe: rgba(209, 73, 91, 0.35);
    --banner-info: #dbeafe;
    --banner-info-text: #1d4ed8;
    --banner-error: #fee2e2;
    --banner-error-text: #b91c1c;
}

body.dark-mode {
    --primary: #6ea8fe;
    --primary-strong: #9ec5fe;
    --accent: #f6bd60;
    --success: #4dd4c6;
    --danger: #ff758f;
    --bg: #0f1720;
    --card: #1a2430;
    --card-alt: #212d3a;
    --text: #ebf1f6;
    --subtext: #9eb0c3;
    --border: #304252;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    --axis: #72869b;
    --target: #ffd166;
    --limit: #e879f9;
    --work: #5ab0ff;
    --business: #ffb74d;
    --gap-hover: rgba(255, 255, 255, 0.08);
    --stat-bg: rgba(255, 255, 255, 0.06);
    --timeline-bg: rgba(255, 255, 255, 0.08);
    --tooltip-bg: #0f1720;
    --deduction-stripe: rgba(255, 117, 143, 0.45);
    --banner-info: rgba(110, 168, 254, 0.15);
    --banner-info-text: #c7dcff;
    --banner-error: rgba(255, 117, 143, 0.16);
    --banner-error-text: #ffd0d8;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(244, 162, 97, 0.22), transparent 30%),
        linear-gradient(180deg, rgba(35, 100, 170, 0.06), transparent 22%),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI", sans-serif;
}

button,
input,
select,
a {
    font: inherit;
}

.hidden {
    display: none !important;
}

.page-shell {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 40px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.status-banner {
    margin-bottom: 16px;
    padding: 14px 18px;
    border-radius: 16px;
    border: 1px solid transparent;
}

.status-banner.info {
    background: var(--banner-info);
    color: var(--banner-info-text);
}

.status-banner.error {
    background: var(--banner-error);
    color: var(--banner-error-text);
}

.eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
}

.lead,
.muted,
.history-item small,
.empty-copy,
.auth-notes,
.upload-copy,
.sidebar p,
.blocks-header p {
    color: var(--subtext);
}

.auth-shell {
    min-height: calc(100vh - 64px);
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(540px, 100%);
    padding: 34px;
}

.auth-card h1 {
    margin: 0 0 12px;
    font-size: clamp(2rem, 4vw, 2.8rem);
    line-height: 1.05;
}

.stack-form {
    display: grid;
    gap: 14px;
    margin-top: 28px;
}

.stack-form label,
.form-grid label {
    display: grid;
    gap: 8px;
}

.stack-form span,
.form-grid span {
    font-size: 0.92rem;
    font-weight: 600;
}

input,
select {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--card-alt);
    color: var(--text);
    border-radius: 14px;
    padding: 12px 14px;
}

input:focus,
select:focus,
button:focus,
a:focus {
    outline: 2px solid rgba(35, 100, 170, 0.28);
    outline-offset: 2px;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.link-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 999px;
    border: 1px solid transparent;
    padding: 11px 18px;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.primary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover,
.link-btn:hover {
    transform: translateY(-1px);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-strong));
    color: white;
}

.ghost-btn,
.link-btn {
    border-color: var(--border);
    background: transparent;
    color: var(--text);
}

.danger-btn {
    background: rgba(209, 73, 91, 0.12);
    border-color: rgba(209, 73, 91, 0.2);
    color: var(--danger);
}

.app-shell {
    display: grid;
    gap: 18px;
}

.topbar {
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.topbar h1,
.sidebar h2,
.empty-state h2,
.editor-head h2,
.blocks-header h3 {
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--subtext);
}

.toggle input {
    width: auto;
}

.user-chip {
    padding: 10px 14px;
    border-radius: 999px;
    background: var(--card-alt);
    border: 1px solid var(--border);
    color: var(--subtext);
}

.layout {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 18px;
}

.sidebar {
    padding: 22px;
    align-self: start;
    position: sticky;
    top: 18px;
}

.sidebar-header,
.history-header,
.blocks-header,
.editor-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 22px 0;
}

.upload-area {
    display: grid;
    gap: 8px;
    border: 2px dashed var(--border);
    border-radius: 20px;
    padding: 20px;
    background: linear-gradient(180deg, rgba(35, 100, 170, 0.05), transparent);
    cursor: pointer;
    transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease,
        box-shadow 0.16s ease;
}

.upload-area:hover,
.upload-area:focus-within {
    border-color: rgba(35, 100, 170, 0.55);
    background: linear-gradient(180deg, rgba(35, 100, 170, 0.1), transparent);
}

.upload-area.drag-active {
    border-color: var(--primary);
    background: linear-gradient(180deg, rgba(35, 100, 170, 0.16), rgba(244, 162, 97, 0.08));
    box-shadow: inset 0 0 0 1px rgba(35, 100, 170, 0.18);
    transform: translateY(-1px);
}

.upload-area input {
    display: none;
}

.upload-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.history-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.history-item {
    width: 100%;
    text-align: left;
    padding: 14px 16px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--card-alt);
    color: var(--text);
    cursor: pointer;
}

.history-item.active {
    border-color: rgba(35, 100, 170, 0.45);
    box-shadow: inset 0 0 0 1px rgba(35, 100, 170, 0.2);
}

.history-item strong {
    display: block;
    margin-bottom: 4px;
}

.main-panel {
    display: grid;
    gap: 18px;
}

.empty-state,
.editor-card,
.blocks-card,
#dashboardCard,
#editorCard {
    padding: 24px;
}

.empty-state {
    display: grid;
    gap: 18px;
}

.steps {
    margin: 0;
    padding-left: 20px;
    display: grid;
    gap: 8px;
}

.editor-title-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.dirty-badge,
.archive-badge {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.dirty-badge {
    background: rgba(244, 162, 97, 0.18);
    color: var(--accent);
}

.archive-badge {
    background: rgba(35, 100, 170, 0.16);
    color: var(--primary);
}

.editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 22px 0;
}

.editor-toolbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 22px;
}

.blocks-card {
    background: var(--card-alt);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 18px;
}

.blocks-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.blocks-editor {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.block-row {
    display: grid;
    grid-template-columns: minmax(110px, 1fr) minmax(110px, 1fr) minmax(120px, 1fr) auto;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--card);
}

.block-row .remove-block {
    white-space: nowrap;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-box {
    background: var(--stat-bg);
    padding: 12px;
    border-radius: 18px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 86px;
}

.val {
    font-size: 1.14rem;
    font-weight: 700;
    color: var(--text);
}

.lbl {
    font-size: 0.8rem;
    color: var(--subtext);
}

.sub-val {
    font-size: 0.78rem;
    color: var(--subtext);
    margin-top: 4px;
}

.target-box {
    cursor: pointer;
}

.target-box:hover {
    box-shadow: inset 0 0 0 1px var(--target);
}

.reset-hint {
    display: none;
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 0.68rem;
    color: var(--primary);
}

.has-override .reset-hint {
    display: block;
}

.legend {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
    font-size: 0.82rem;
    color: var(--subtext);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.work-dot {
    background: var(--work);
}

.business-dot {
    background: var(--business);
}

.pause-dot {
    border: 1px solid var(--axis);
    background: transparent;
}

.limit-dot {
    background: var(--limit);
}

.timeline-wrapper {
    margin: 42px 0 28px;
    position: relative;
}

.timeline {
    height: 52px;
    background: var(--timeline-bg);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.block {
    position: absolute;
    height: 100%;
    background: var(--work);
    border-right: 1px solid rgba(255, 255, 255, 0.18);
    z-index: 2;
}

.block.business {
    background: var(--business);
}

.block.live {
    border: none;
}

.gap {
    position: absolute;
    height: 100%;
    background: transparent;
    z-index: 1;
}

.gap:hover {
    background: var(--gap-hover);
}

.deduction-warning {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    background: repeating-linear-gradient(
        -45deg,
        var(--deduction-stripe),
        var(--deduction-stripe) 10px,
        transparent 10px,
        transparent 20px
    );
    z-index: 3;
    border-left: 2px solid var(--danger);
}

.marker-now {
    position: absolute;
    height: 100%;
    width: 2px;
    background: var(--danger);
    top: 0;
    z-index: 6;
    display: none;
}

.marker-target {
    position: absolute;
    height: 100%;
    width: 2px;
    top: 0;
    z-index: 5;
    display: none;
}

.marker-target-line {
    width: 100%;
    height: 100%;
    background: var(--target);
}

.marker-target-label {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--target);
    color: #222;
    padding: 4px 8px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    display: flex;
    gap: 6px;
    align-items: center;
}

.marker-reset-x {
    cursor: pointer;
}

.marker-limit {
    position: absolute;
    height: 120%;
    top: -10%;
    width: 3px;
    background: var(--limit);
    z-index: 4;
    display: none;
    box-shadow: 0 0 6px var(--limit);
}

.marker-limit::after {
    content: "MAX 10h";
    position: absolute;
    top: -28px;
    right: 0;
    background: var(--limit);
    color: #111;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
}

.marker-std,
.guide-line {
    position: absolute;
    height: 100%;
    width: 1px;
    top: 0;
    display: none;
}

.marker-std {
    border-left: 2px dashed var(--target);
    z-index: 3;
}

.guide-line {
    border-left: 1px dashed var(--axis);
    z-index: 7;
}

.tooltip-prognosis {
    position: absolute;
    top: -110px;
    left: 0;
    transform: translateX(-50%);
    background: var(--tooltip-bg);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.84rem;
    display: none;
    z-index: 20;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    min-width: 190px;
    line-height: 1.5;
}

.timeline-axis {
    position: relative;
    height: 24px;
    margin-top: 8px;
    font-size: 0.76rem;
    color: var(--axis);
}

.tick {
    position: absolute;
    transform: translateX(-50%);
}

.tick::before {
    content: "|";
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.35;
}

.prog-container {
    height: 32px;
    background: var(--stat-bg);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.prog-bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.25s ease;
}

.prog-text {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.45);
}

.result-text {
    margin-top: 12px;
    min-height: 1.3em;
    font-weight: 700;
}

@media (max-width: 1080px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .page-shell {
        width: min(100% - 20px, 100%);
        padding-top: 14px;
    }

    .auth-card,
    .sidebar,
    #editorCard,
    #dashboardCard,
    .empty-state {
        padding: 18px;
    }

    .topbar,
    .editor-head,
    .blocks-header,
    .history-header {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-actions,
    .editor-actions,
    .blocks-actions {
        justify-content: stretch;
    }

    .topbar-actions > *,
    .editor-actions > *,
    .blocks-actions > * {
        width: 100%;
    }

    .form-grid,
    .stats,
    .block-row {
        grid-template-columns: 1fr;
    }

    .timeline-wrapper {
        margin-top: 32px;
    }
}
