:root {
    --bg: #f4efe6;
    --paper: #fffaf2;
    --paper-strong: #fffdf8;
    --line: #d8cdb8;
    --line-strong: #baaa88;
    --text: #2b241a;
    --muted: #6f6351;
    --accent: #1d6b57;
    --accent-strong: #134d3f;
    --warning: #8f4b2f;
    --shadow: 0 18px 50px rgba(64, 39, 8, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.7), transparent 28%),
        linear-gradient(180deg, #efe7da 0%, var(--bg) 100%);
    color: var(--text);
}

.page-shell {
    max-width: 1440px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.session-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.session-label {
    color: var(--muted);
    font-size: 0.92rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.hero {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: end;
    margin-bottom: 20px;
}

.eyebrow {
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.8rem;
    color: var(--muted);
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 10px;
    font-size: clamp(2.4rem, 5vw, 4.4rem);
    line-height: 0.95;
}

.hero-copy {
    max-width: 56rem;
    font-size: 1.05rem;
    color: var(--muted);
}

.days-form,
.custom-form,
.history-form {
    display: grid;
    gap: 10px;
}

.days-form select,
input,
button {
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    font: inherit;
}

select,
input {
    padding: 10px 12px;
    background: var(--paper-strong);
    color: var(--text);
}

button {
    padding: 11px 14px;
    background: var(--accent);
    color: #f5f3ed;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease;
}

button:hover {
    background: var(--accent-strong);
    transform: translateY(-1px);
}

.secondary-button {
    background: transparent;
    color: var(--accent-strong);
}

.secondary-button:hover {
    background: rgba(29, 107, 87, 0.08);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 18px;
    align-items: stretch;
}

.card {
    background: rgba(255, 250, 242, 0.88);
    border: 1px solid rgba(186, 170, 136, 0.7);
    border-radius: 24px;
    padding: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(3px);
}

.entry-stack {
    display: grid;
    gap: 18px;
    min-height: 100%;
}

.quick-card,
.history-card {
    height: 100%;
}

.timer-card {
    display: flex;
    align-items: stretch;
    min-height: 0;
    background:
        radial-gradient(circle at top right, rgba(29, 107, 87, 0.16), transparent 34%),
        linear-gradient(180deg, rgba(255, 250, 242, 0.96) 0%, rgba(241, 231, 216, 0.92) 100%);
}

.timer-card-content {
    display: grid;
    align-content: center;
    gap: 10px;
    width: 100%;
}

.timer-eyebrow {
    margin-bottom: 0;
}

.dose-elapsed {
    margin: 0;
    font-size: clamp(2.8rem, 7vw, 5.2rem);
    line-height: 0.9;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.04em;
}

.dose-elapsed-empty {
    color: var(--muted);
}

.timer-copy,
.timer-meta {
    margin-bottom: 0;
}

.timer-copy {
    color: var(--muted);
    max-width: 28rem;
}

.timer-meta {
    font-weight: 600;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 18px 0;
}

.quick-grid button {
    padding: 18px 10px;
    font-size: 1.2rem;
}

.inline-fields {
    display: flex;
    gap: 10px;
}

.inline-fields input {
    width: 110px;
}

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

.secondary-link {
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 600;
}

.secondary-link:hover {
    text-decoration: underline;
}

.history-list {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid rgba(186, 170, 136, 0.7);
}

.history-list h3 {
    margin: 0 0 12px;
    font-size: 1rem;
}

.history-list-items {
    display: grid;
    gap: 10px;
    max-height: 260px;
    overflow-y: auto;
    padding-right: 4px;
}

.history-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid rgba(186, 170, 136, 0.7);
    border-radius: 14px;
    background: rgba(255, 253, 248, 0.92);
}

.history-item strong,
.history-item span {
    display: block;
}

.history-item span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.92rem;
}

.history-item-active {
    border-color: rgba(29, 107, 87, 0.55);
    box-shadow: inset 0 0 0 1px rgba(29, 107, 87, 0.18);
}

.flash-stack {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.flash {
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid;
}

.flash-success {
    background: rgba(29, 107, 87, 0.12);
    border-color: rgba(29, 107, 87, 0.35);
}

.flash-error {
    background: rgba(143, 75, 47, 0.1);
    border-color: rgba(143, 75, 47, 0.35);
}

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

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

.auth-title {
    margin-bottom: 12px;
}

.auth-copy {
    color: var(--muted);
    margin-bottom: 22px;
}

.auth-form {
    display: grid;
    gap: 12px;
}

.table-header {
    margin-bottom: 16px;
}

.totals-card {
    margin-top: 18px;
}

.timeline-wrap {
    overflow-x: auto;
}

.timeline {
    width: 100%;
    min-width: 720px;
    border-collapse: separate;
    border-spacing: 0;
}

.timeline th,
.timeline td {
    padding: 10px;
    vertical-align: top;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.timeline thead th:first-child,
.timeline tbody th {
    width: 68px;
    min-width: 68px;
    max-width: 68px;
    padding: 10px 8px;
    white-space: nowrap;
}

.timeline thead th:not(:first-child),
.timeline tbody td {
    min-width: 92px;
}

.timeline thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f1e7d8;
}

.timeline th:first-child,
.timeline td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #f7f0e3;
}

.timeline thead th:first-child {
    z-index: 3;
}

.timeline thead span,
.timeline thead strong {
    display: block;
}

.timeline tbody th {
    text-align: left;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.88rem;
}

.timeline td.empty {
    background: rgba(255, 255, 255, 0.32);
}

.timeline td.has-events {
    background: rgba(29, 107, 87, 0.08);
}

.dose-chip {
    display: grid;
    gap: 2px;
    margin-bottom: 8px;
    padding: 8px 9px;
    border-left: 3px solid var(--accent);
    border-radius: 10px;
    background: rgba(255, 253, 248, 0.95);
    font-size: 0.92rem;
}

.dose-chip:last-child {
    margin-bottom: 0;
}

.chip-link {
    color: var(--accent-strong);
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
}

.chip-link:hover {
    text-decoration: underline;
}

.daily-total-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.day-total-tile {
    display: grid;
    gap: 6px;
    padding: 14px;
    border: 1px solid rgba(186, 170, 136, 0.7);
    border-radius: 16px;
    background: rgba(255, 253, 248, 0.92);
}

.day-total-tile strong {
    font-size: 1.35rem;
}

.day-total-label {
    color: var(--muted);
    font-size: 0.92rem;
}

.chart-wrap {
    overflow-x: auto;
    padding: 10px 0 2px;
}

.daily-chart {
    width: 100%;
    min-width: 680px;
    height: auto;
    display: block;
}

.chart-gridline {
    stroke: rgba(111, 99, 81, 0.18);
    stroke-width: 1;
}

.chart-baseline {
    stroke: rgba(111, 99, 81, 0.35);
    stroke-width: 1.25;
}

.chart-area {
    fill: rgba(29, 107, 87, 0.12);
}

.chart-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-point {
    fill: var(--accent);
    stroke: #fffaf2;
    stroke-width: 2;
}

.chart-axis-label {
    fill: var(--muted);
    font-size: 0.82rem;
}

.chart-point-label {
    fill: var(--text);
    font-size: 0.84rem;
    font-weight: 700;
}

@media (min-width: 901px) {
    .entry-stack {
        grid-template-rows: auto 1fr;
    }
}

@media (max-width: 900px) {
    .session-bar,
    .hero,
    .card-grid,
    .inline-fields {
        grid-template-columns: 1fr;
        display: grid;
    }

    .hero {
        align-items: start;
    }

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

    .timeline {
        min-width: 308px;
    }

    .timeline th,
    .timeline td {
        padding: 8px 6px;
    }

    .timeline thead th:first-child,
    .timeline tbody th {
        width: 52px;
        min-width: 52px;
        max-width: 52px;
        padding: 8px 6px;
        font-size: 0.78rem;
    }

    .timeline thead th:not(:first-child),
    .timeline tbody td {
        min-width: 84px;
    }

    .timeline thead span,
    .timeline thead strong {
        font-size: 0.76rem;
        line-height: 1.15;
    }

    .dose-chip {
        padding: 7px 8px;
        font-size: 0.82rem;
    }

    .chip-link {
        font-size: 0.75rem;
    }

    .entry-stack {
        min-height: auto;
    }

    .timer-card-content {
        align-content: start;
    }

    .inline-fields input {
        width: 100%;
    }

    .history-item {
        align-items: start;
        grid-template-columns: 1fr;
        display: grid;
    }
}
