:root {
    color-scheme: dark;
    --ink: #f6f1ff;
    --muted: #aaa0b7;
    --canvas: #110d18;
    --canvas-raised: #181120;
    --panel: #20172b;
    --panel-2: #2a1d38;
    --line: rgba(211, 190, 235, .14);
    --purple: #a970ff;
    --purple-strong: #8950e8;
    --orange: #ff9b4a;
    --orange-strong: #f07824;
    --danger: #ff6f87;
    --success: #73d6a0;
    --shadow: 0 22px 60px rgba(3, 1, 8, .28);
}

* { box-sizing: border-box; }

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 78% -10%, rgba(137, 80, 232, .19), transparent 32rem),
        radial-gradient(circle at -10% 50%, rgba(255, 155, 74, .07), transparent 26rem),
        var(--canvas);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

a { color: #c9a8ff; }
a:hover { color: #e1d0ff; }

.app-shell { max-width: 1140px; }
.app-header {
    padding-top: env(safe-area-inset-top);
    background: rgba(17, 13, 24, .87);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(18px);
}
.navbar { min-height: 68px; }
.navbar-brand { color: var(--ink); font-weight: 750; letter-spacing: -.02em; }
.navbar-brand:hover { color: var(--ink); }
.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    color: var(--orange);
    background: linear-gradient(145deg, rgba(255, 155, 74, .18), rgba(169, 112, 255, .16));
    border: 1px solid rgba(255, 155, 74, .25);
    border-radius: 12px;
}
.desktop-nav { gap: .3rem; }
.desktop-nav .nav-link {
    padding: .55rem .9rem;
    color: var(--muted);
    border-radius: 10px;
    font-weight: 650;
}
.desktop-nav .nav-link:hover { color: var(--ink); background: rgba(255,255,255,.04); }
.desktop-nav .nav-link.active { color: var(--ink); background: rgba(169, 112, 255, .14); }

.page-wrap { padding-top: 2.25rem; padding-bottom: 4rem; }
.page-heading { margin-bottom: 1.6rem; }
.page-heading h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.15rem); font-weight: 780; letter-spacing: -.05em; }
.page-heading > p:last-child { max-width: 680px; margin: .55rem 0 0; color: var(--muted); }
.heading-inline { display: flex; align-items: end; justify-content: space-between; gap: 1.5rem; }
.eyebrow {
    margin: 0 0 .35rem;
    color: var(--orange);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .11em;
    text-transform: uppercase;
}
.last-dose {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: .32rem;
    padding: .8rem 1.1rem;
    color: #d4c9dd;
    background: rgba(255, 155, 74, .045);
    border: 1px solid rgba(255, 155, 74, .42);
    border-radius: 14px;
    box-shadow: inset 0 0 24px rgba(255, 155, 74, .025);
    font-size: 1.12rem;
    font-weight: 650;
    text-align: center;
}
.last-dose strong { color: var(--ink); font-size: 1.42rem; letter-spacing: -.025em; }
.last-dose-divider { color: #75667f; }
.last-dose-since { color: var(--orange); font-size: 1.12rem; font-weight: 800; }

.card-panel {
    background: linear-gradient(145deg, rgba(36, 25, 49, .96), rgba(28, 20, 38, .96));
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
}
.dose-composer { position: relative; padding: 1.35rem; overflow: hidden; }
.dose-composer::before {
    position: absolute;
    top: 0;
    left: 1.5rem;
    width: 7rem;
    height: 2px;
    background: linear-gradient(90deg, var(--orange), var(--purple));
    content: "";
}

.form-label { margin-bottom: .45rem; color: #d9cedf; font-size: .9rem; font-weight: 650; }
.form-control, .form-select {
    color: var(--ink);
    background-color: rgba(8, 5, 12, .4);
    border-color: rgba(211, 190, 235, .2);
    border-radius: 11px;
}
.form-control:focus, .form-select:focus {
    color: var(--ink);
    background-color: rgba(8, 5, 12, .58);
    border-color: var(--purple);
    box-shadow: 0 0 0 .22rem rgba(169, 112, 255, .14);
}
.form-control::placeholder { color: #7f748b; }
.form-check-input { background-color: #463653; border-color: #685478; }
.form-check-input:checked { background-color: var(--purple-strong); border-color: var(--purple); }

.btn { border-radius: 11px; font-weight: 750; }
.btn-accent {
    color: #1c0e03;
    background: linear-gradient(135deg, var(--orange), #ffb15f);
    border-color: transparent;
    box-shadow: 0 8px 22px rgba(240, 120, 36, .2);
}
.btn-accent:hover, .btn-accent:focus { color: #1c0e03; background: #ffb15f; border-color: transparent; transform: translateY(-1px); }
.btn-accent small { display: block; min-height: .8rem; font-size: .68rem; font-weight: 800; line-height: .8rem; }
.btn-ghost { color: #d8cce2; background: rgba(255,255,255,.045); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--ink); background: rgba(255,255,255,.08); border-color: rgba(211, 190, 235, .28); }
.btn-delete { color: #ff9bab; background: transparent; border: 1px solid rgba(255, 111, 135, .18); }
.btn-delete:hover { color: #fff; background: rgba(255, 111, 135, .18); border-color: rgba(255, 111, 135, .32); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: .9rem; }
.section-heading h2 { margin: 0; font-size: 1.25rem; font-weight: 760; letter-spacing: -.02em; }
.section-heading a { font-size: .9rem; font-weight: 700; text-decoration: none; }
.section-note { color: var(--muted); font-size: .85rem; }
.totals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.total-card {
    padding: 1.2rem;
    background: linear-gradient(155deg, rgba(47, 31, 64, .94), rgba(27, 19, 37, .94));
    border: 1px solid var(--line);
    border-radius: 18px;
}
.total-card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.total-card-head h3 { margin: 0; font-size: 1rem; font-weight: 750; }
.total-card-head span { color: var(--muted); font-size: .78rem; }
.window { display: flex; flex-direction: column; gap: .12rem; }
.window > span { color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.window strong { font-size: 1.25rem; }
.window strong small { color: var(--muted); font-size: .72em; }
.primary-window { margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.primary-window strong { color: var(--orange); font-size: 2rem; letter-spacing: -.04em; }
.window-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.dose-list { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; }
.dose-row {
    position: relative;
    display: grid;
    grid-template-columns: 120px minmax(0, 1fr) 100px 34px;
    gap: 1rem;
    align-items: center;
    min-height: 84px;
    padding: .9rem 1rem;
    background: rgba(31, 22, 42, .72);
    border-bottom: 1px solid var(--line);
}
.dose-row:last-child { border-bottom: 0; }
.dose-row:hover { background: rgba(40, 28, 54, .84); }
.dose-time { display: flex; flex-direction: column; }
.dose-time strong { font-size: .95rem; }
.dose-time span { color: var(--muted); font-size: .76rem; }
.dose-detail { min-width: 0; }
.dose-detail h3 { margin: 0 0 .15rem; font-size: 1rem; font-weight: 750; }
.dose-detail p { margin: 0; overflow: hidden; color: var(--muted); font-size: .83rem; text-overflow: ellipsis; white-space: nowrap; }
.dose-total { display: flex; align-items: baseline; justify-content: end; gap: .25rem; color: var(--orange); }
.dose-total strong { font-size: 1.35rem; }
.dose-total span { font-size: .75rem; font-weight: 700; }
.dose-delete button { width: 32px; height: 32px; padding: 0; color: #8f8299; background: transparent; border: 0; border-radius: 8px; font-size: 1.35rem; }
.dose-delete button:hover { color: var(--danger); background: rgba(255,111,135,.1); }

.management-grid { display: grid; grid-template-columns: minmax(290px, .75fr) minmax(420px, 1.25fr); gap: 1.25rem; align-items: start; }
.form-card, .list-card { padding: 1.3rem; }
.form-card { position: sticky; top: 92px; }
.form-card h2, .list-card h2 { margin: 0 0 1.2rem; font-size: 1.2rem; font-weight: 760; }
.list-card-heading { display: flex; align-items: center; justify-content: space-between; }
.list-card-heading span { display: grid; min-width: 30px; height: 30px; padding: 0 .5rem; place-items: center; color: #e0d4e8; background: var(--panel-2); border-radius: 10px; font-size: .78rem; font-weight: 750; }
.entity-list { margin: 0 -1.3rem -1.3rem; }
.entity-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.3rem; border-top: 1px solid var(--line); }
.entity-row.row-focus { animation: focusGlow 1.7s ease-out; }
.entity-main { min-width: 0; }
.entity-title { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.entity-title h3 { margin: 0; font-size: 1rem; font-weight: 720; }
.entity-main p { margin: .25rem 0 0; overflow-wrap: anywhere; color: var(--muted); font-size: .84rem; }
.entity-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.status-active { color: var(--success); background: rgba(115, 214, 160, .1); border: 1px solid rgba(115, 214, 160, .17); }
.status-inactive { color: #aaa0b7; background: rgba(170, 160, 183, .08); border: 1px solid rgba(170, 160, 183, .12); }
.empty-copy { margin: 1rem 0 0; color: var(--muted); }
.empty-compact { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem; }
.empty-compact h2 { margin: 0 0 .2rem; font-size: 1.1rem; }
.empty-compact p { color: var(--muted); }
.empty-state { max-width: 680px; margin: 10vh auto 0; padding: 2rem; text-align: center; }
.empty-state h1 { margin: 1rem 0 .5rem; font-size: 1.6rem; }
.empty-state p { color: var(--muted); }
.empty-icon { display: grid; width: 50px; height: 50px; margin: 0 auto; place-items: center; color: #251106; background: var(--orange); border-radius: 15px; font-size: 1.5rem; font-weight: 900; }
.empty-state details { margin-top: 1.3rem; text-align: left; }
.empty-state pre { max-height: 180px; margin-top: .75rem; padding: 1rem; overflow: auto; color: #ffb3bf; background: #100b16; border-radius: 10px; white-space: pre-wrap; }
.history-filter { width: min(100%, 260px); }
.history-pages { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: 1rem; color: var(--muted); font-size: .85rem; }
.page-link { color: #d9c8e8; background: var(--panel); border-color: var(--line); }
.page-link:hover { color: var(--ink); background: var(--panel-2); border-color: rgba(211,190,235,.24); }
.page-item.disabled .page-link { color: #776c82; background: rgba(32,23,43,.6); border-color: var(--line); }

.alert { border-radius: 14px; }
.alert-success { color: #c9f4da; background: rgba(39, 115, 72, .25); border-color: rgba(115,214,160,.22); }
.alert-danger { color: #ffd0d7; background: rgba(125, 38, 56, .25); border-color: rgba(255,111,135,.22); }

.mobile-nav {
    position: fixed;
    z-index: 1030;
    right: .75rem;
    bottom: calc(.75rem + env(safe-area-inset-bottom));
    left: .75rem;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: .38rem;
    background: rgba(27, 19, 37, .94);
    border: 1px solid rgba(211, 190, 235, .18);
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(0,0,0,.45);
    backdrop-filter: blur(20px);
}
.mobile-nav a { display: flex; flex-direction: column; align-items: center; gap: .05rem; padding: .4rem .2rem; color: #988da4; border-radius: 12px; text-decoration: none; }
.mobile-nav a > span { display: grid; width: 24px; height: 24px; place-items: center; font-size: 1rem; font-weight: 800; }
.mobile-nav small { font-size: .68rem; font-weight: 700; }
.mobile-nav a.active { color: #1c0e03; background: var(--orange); }

@keyframes focusGlow {
    0% { background: rgba(169,112,255,.26); }
    100% { background: transparent; }
}

@media (max-width: 767.98px) {
    body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
    .navbar { min-height: 60px; }
    .page-wrap { padding-top: 1.35rem; padding-bottom: 2rem; }
    .page-heading { margin-bottom: 1.15rem; }
    .page-heading h1 { font-size: 2.05rem; }
    .heading-inline { align-items: stretch; flex-direction: column; gap: .85rem; }
    .last-dose { width: 100%; padding: 1rem; font-size: 1.25rem; }
    .last-dose strong { font-size: 1.75rem; }
    .last-dose-divider { display: none; }
    .last-dose-since { flex-basis: 100%; font-size: 1.32rem; }
    .dose-composer { padding: 1rem; border-radius: 17px; }
    .totals-grid { grid-template-columns: 1fr; }
    .management-grid { grid-template-columns: 1fr; }
    .form-card { position: static; }
    .entity-row { align-items: start; flex-direction: column; }
    .entity-actions { width: 100%; }
    .entity-actions .btn { flex: 1; }
    .entity-actions form { display: flex; flex: 1; }
    .entity-actions form .btn { width: 100%; }
    .dose-row { grid-template-columns: 70px minmax(0, 1fr) 64px 28px; gap: .45rem; min-height: 78px; padding: .8rem; }
    .dose-time strong { font-size: .84rem; }
    .dose-time span { font-size: .67rem; }
    .dose-detail p { font-size: .76rem; }
    .dose-total strong { font-size: 1.1rem; }
    .dose-delete button { width: 28px; height: 28px; }
    .empty-compact { align-items: stretch; flex-direction: column; }
    .history-filter { width: 100%; }
}

@media (display-mode: fullscreen) {
    body {
        min-height: 100dvh;
        padding-right: env(safe-area-inset-right);
        padding-left: env(safe-area-inset-left);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .01ms !important; }
}
