:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #17212b;
    --muted: #64748b;
    --line: #d8e0ea;
    --line-soft: #edf1f5;
    --accent: #0b766f;
    --accent-dark: #075e59;
    --accent-soft: #e8f5f3;
    --danger: #b42318;
    --warning: #b54708;
    --good: #087443;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent-dark);
    text-decoration: none;
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 248px;
    padding: 22px 16px;
    background: #fbfcfd;
    border-right: 1px solid var(--line);
    position: sticky;
    top: 0;
    height: 100vh;
}

.content-shell {
    flex: 1;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 26px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #0f172a;
    color: #ffffff;
    display: grid;
    place-items: center;
    font-weight: 900;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    margin-top: 2px;
}

.nav-list {
    display: grid;
    gap: 6px;
}

.nav-list a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #334155;
    padding: 11px 12px;
    border-radius: 8px;
    font-weight: 700;
}

.nav-list a span {
    font-size: 11px;
    color: #718096;
}

.nav-list a:hover,
.nav-list a.active {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

.topbar {
    min-height: 88px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 22px 32px 16px;
    background: rgba(244, 246, 248, 0.9);
    border-bottom: 1px solid var(--line-soft);
    position: sticky;
    top: 0;
    z-index: 2;
    backdrop-filter: blur(12px);
}

.topbar h1 {
    font-size: 26px;
    margin: 3px 0 0;
    letter-spacing: 0;
}

.eyebrow {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-chip {
    border: 1px solid var(--line);
    background: #ffffff;
    padding: 8px 11px;
    border-radius: 999px;
    color: #334155;
    font-weight: 700;
}

.page {
    width: min(1220px, calc(100% - 48px));
    margin: 24px auto 64px;
}

h1 {
    font-size: 28px;
    margin: 0 0 20px;
}

h2 {
    font-size: 18px;
    margin: 0 0 14px;
}

.grid {
    display: grid;
    gap: 16px;
}

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

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

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

.page-stack {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.page > .page-stack:first-child {
    margin-top: 0;
}

.task-card-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.panel,
.card {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
}

.panel {
    box-shadow: var(--shadow);
    border-color: transparent;
}

.metric {
    display: grid;
    gap: 6px;
    min-height: 126px;
    align-content: space-between;
    position: relative;
    overflow: hidden;
}

.metric::after {
    content: "";
    position: absolute;
    right: 16px;
    top: 18px;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--accent);
}

.metric strong {
    font-size: 32px;
    line-height: 1.1;
    letter-spacing: 0;
}

.muted {
    color: var(--muted);
}

.flash {
    padding: 13px 15px;
    border-radius: 8px;
    margin-bottom: 18px;
    border: 1px solid #b7dfd9;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 700;
}

.flash.error {
    color: var(--danger);
    background: #fff1f0;
}

form {
    margin: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 12px;
}

.compact-form {
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
    align-items: end;
}

label {
    min-width: 0;
    display: grid;
    gap: 6px;
    font-weight: 700;
    color: #334155;
    font-size: 13px;
}

input,
select,
textarea,
button {
    min-width: 0;
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    max-width: 100%;
    inline-size: 100%;
    max-inline-size: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 11px;
    background: #ffffff;
    color: var(--text);
}

input:not(
    [type="date"],
    [type="time"],
    [type="datetime-local"],
    [type="month"],
    [type="week"]
),
select,
textarea {
    display: block;
}

::-webkit-datetime-edit,
::-webkit-datetime-edit-fields-wrapper,
::-webkit-datetime-edit-text,
::-webkit-datetime-edit-minute-field,
::-webkit-datetime-edit-hour-field,
::-webkit-datetime-edit-meridiem-field,
::-webkit-datetime-edit-day-field,
::-webkit-datetime-edit-month-field,
::-webkit-datetime-edit-year-field {
    padding: 0;
}

input::-webkit-inner-spin-button {
    height: auto;
}

textarea {
    min-height: 86px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 3px solid rgba(11, 118, 111, 0.16);
    border-color: var(--accent);
}

button,
.button {
    border: 0;
    border-radius: 8px;
    padding: 9px 14px;
    background: var(--accent);
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    font-weight: 800;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

button:hover,
.button:hover {
    background: var(--accent-dark);
    box-shadow: 0 10px 22px rgba(11, 118, 111, 0.18);
    transform: translateY(-1px);
}

button.secondary,
.button.secondary {
    background: #e2e8f0;
    color: #1f2933;
}

button.danger {
    background: var(--danger);
}

button.ghost {
    background: #ffffff;
    color: #334155;
    border: 1px solid var(--line);
}

.small-button {
    min-height: 34px;
    padding: 7px 11px;
    font-size: 13px;
}

.icon-button {
    width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 8px;
    font-size: 22px;
    line-height: 1;
}

.actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 12px;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.section-head p {
    margin: -6px 0 0;
}

.table-wrap {
    max-height: 420px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.table-wrap.small {
    max-height: 260px;
}

.table-wrap table {
    border: 0;
    border-radius: 0;
}

.table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.compact-table th,
.compact-table td {
    padding: 9px 10px;
    font-size: 13px;
}

th,
td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: top;
}

th {
    background: var(--panel-soft);
    color: #334155;
    font-weight: 700;
    font-size: 13px;
}

tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover td {
    background: #fbfcfd;
}

.positive {
    color: var(--good);
    font-weight: 700;
}

.negative {
    color: var(--danger);
    font-weight: 700;
}

.priority {
    border-left: 4px solid var(--warning);
}

.login-box {
    max-width: 420px;
    margin: 6vh auto;
}

.stack {
    display: grid;
    gap: 16px;
}

.scroll-list {
    max-height: 360px;
    overflow: auto;
    padding-right: 4px;
}

.quick-list {
    max-height: 520px;
    overflow: auto;
    padding-right: 6px;
    scrollbar-gutter: stable;
}

.quick-list .card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
        "name points action"
        "category points action";
    align-items: center;
    gap: 3px 12px;
    padding: 10px 12px;
}

.quick-list .card > strong {
    grid-area: name;
}

.quick-list .card > .positive,
.quick-list .card > .negative {
    grid-area: points;
    white-space: nowrap;
}

.quick-list .card .muted {
    grid-area: category;
    font-size: 13px;
}

.quick-list .card .actions {
    grid-area: action;
    margin-top: 0;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: end;
    flex-wrap: wrap;
}

.inline-form label {
    min-width: 150px;
}

.modal {
    width: min(900px, calc(100vw - 32px));
    max-height: min(86vh, 760px);
    padding: 0;
    border: 0;
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.26);
    overflow: auto;
}

.modal::backdrop {
    background: rgba(15, 23, 42, 0.38);
    backdrop-filter: blur(3px);
}

.modal-narrow {
    width: min(560px, calc(100vw - 32px));
}

.modal-form {
    padding: 18px;
    background: #ffffff;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line-soft);
}

.modal-head h3 {
    margin: 0;
    font-size: 18px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--line-soft);
    flex-wrap: wrap;
}

.row-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.row-actions form {
    display: inline-flex;
}

.record-summary {
    display: grid;
    gap: 4px;
    padding: 12px;
    margin-bottom: 14px;
    border-radius: 8px;
    background: var(--panel-soft);
    border: 1px solid var(--line-soft);
}

.record-summary span {
    color: var(--muted);
    font-size: 13px;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 32px;
    padding: 18px 2px 0;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.chart-box {
    min-height: 0;
}

.chart-frame {
    position: relative;
    height: 260px;
    max-height: 260px;
    width: 100%;
    overflow: hidden;
}

.chart-frame canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    max-height: 260px !important;
}

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        padding: 12px;
    }

    .brand {
        margin-bottom: 10px;
    }

    .nav-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        overflow-x: visible;
        padding-bottom: 2px;
    }

    .nav-list a {
        white-space: normal;
        min-width: 0;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
        padding: 18px 16px 12px;
        position: static;
    }

    .topbar h1 {
        font-size: 22px;
    }

    .user-actions {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .grid.cols-2,
    .grid.cols-3,
    .grid.cols-4,
    .form-grid,
    .compact-form {
        grid-template-columns: 1fr;
    }

    .page {
        width: calc(100% - 20px);
        margin-top: 12px;
        margin-bottom: 40px;
    }

    .panel,
    .card {
        padding: 14px;
    }

    .metric {
        min-height: 104px;
    }

    .metric strong {
        font-size: 28px;
    }

    .inline-form {
        display: grid;
    }

    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    th,
    td {
        padding: 10px 11px;
        min-width: 116px;
    }

    .compact-table th,
    .compact-table td {
        min-width: 94px;
    }

    .modal {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 24px);
        border-radius: 10px;
    }

    .modal-form {
        padding: 14px;
    }

    .modal-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .modal-actions button,
    .actions .button,
    .actions button {
        width: 100%;
    }

    .quick-list {
        max-height: 430px;
    }

    .quick-list .card .actions button {
        width: auto;
    }

    .site-footer {
        display: grid;
        gap: 6px;
        margin-top: 24px;
        padding-bottom: 4px;
    }

    .chart-frame {
        height: 220px;
        max-height: 220px;
    }

    .chart-frame canvas {
        max-height: 220px !important;
    }
}

@media (hover: none) and (pointer: coarse) and (min-width: 821px) and (max-width: 1180px) {
    .form-grid.date-form,
    .compact-form.date-form,
    .date-form .form-grid,
    .date-form .compact-form {
        grid-template-columns: minmax(0, 1fr);
    }
}
