:root {
    color-scheme: light;
    --ink: #1d302d;
    --muted: #64736f;
    --line: #e1e8e4;
    --paper: #ffffff;
    --canvas: #f5f7f4;
    --green: #256b56;
    --green-dark: #1d5545;
    --green-pale: #e9f4ed;
    --amber: #8d5b08;
    --amber-pale: #fff3d8;
    --red: #a53d39;
    --red-pale: #fff0ef;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 15px; line-height: 1.55; }
a { color: inherit; }
button, input { font: inherit; }
.topbar { height: 68px; padding: 0 max(24px, calc((100% - 1120px) / 2)); display: flex; align-items: center; justify-content: space-between; background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; gap: 10px; align-items: center; font-weight: 750; font-size: 17px; text-decoration: none; letter-spacing: -.3px; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: var(--green); color: white; font-size: 23px; line-height: 1; }
.topbar-account { display: flex; align-items: center; gap: 20px; color: var(--muted); font-size: 14px; }
.page { width: min(100% - 48px, 1120px); min-height: calc(100vh - 128px); margin: 0 auto; padding: 48px 0 64px; }
.footer { padding: 18px 24px 24px; color: var(--muted); text-align: center; font-size: 12px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(29px, 4vw, 38px); line-height: 1.15; letter-spacing: -1.2px; }
h2 { margin-bottom: 6px; font-size: 19px; line-height: 1.3; letter-spacing: -.3px; }
h2 small { color: var(--muted); font-size: 14px; font-weight: 500; }
.eyebrow { margin-bottom: 8px; color: var(--green); font-size: 11px; font-weight: 750; letter-spacing: 1.25px; }
.muted, .field-help { color: var(--muted); }
.muted { margin-bottom: 0; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-heading p { max-width: 650px; }
.compact-heading { margin-top: 20px; margin-bottom: 24px; }
.back-link { display: inline-block; margin: -8px 0 20px; color: var(--green); font-size: 14px; font-weight: 650; text-decoration: none; }
.button { display: inline-flex; min-height: 43px; align-items: center; justify-content: center; padding: 10px 16px; border: 1px solid transparent; border-radius: 9px; cursor: pointer; font-weight: 680; text-decoration: none; transition: background .15s, border-color .15s; }
.button-primary { background: var(--green); color: #fff; }
.button-primary:hover { background: var(--green-dark); }
.button-secondary { border-color: var(--line); background: var(--paper); color: var(--ink); }
.button-secondary:hover { border-color: #b7c8bf; background: #f9fbf9; }
.button-wide { width: 100%; }
.link-button { padding: 0; border: 0; background: none; color: var(--green); cursor: pointer; font-weight: 650; }
.link-button:hover { text-decoration: underline; }
.card, .summary-card { border: 1px solid var(--line); border-radius: 15px; background: var(--paper); box-shadow: 0 3px 12px rgb(22 51 41 / 3%); }
.notice { margin-bottom: 24px; padding: 14px 17px; border: 1px solid var(--line); border-radius: 10px; }
.notice-success { border-color: #bfddc9; background: var(--green-pale); color: var(--green-dark); }
.notice-error { border-color: #edc7c3; background: var(--red-pale); color: #772e2b; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.summary-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 0 0 20px; }
.summary-card { display: flex; align-items: center; justify-content: space-between; padding: 16px 19px; }
.summary-label { color: var(--muted); font-size: 13px; }
.summary-card strong { font-size: 22px; }
.medication-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.medication-card { display: block; padding: 20px; color: inherit; text-decoration: none; transition: border-color .15s, transform .15s, box-shadow .15s; }
.medication-card:hover { transform: translateY(-2px); border-color: #bdd2c5; box-shadow: 0 8px 20px rgb(22 51 41 / 7%); }
.medication-card-top, .section-heading, .card-footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.medication-card-top h2 { margin-bottom: 2px; }
.medication-card-top .muted { font-size: 13px; }
.status { flex: 0 0 auto; padding: 5px 9px; border-radius: 100px; font-size: 11px; font-weight: 700; }
.status-ok { background: var(--green-pale); color: var(--green-dark); }
.status-due { background: var(--amber-pale); color: var(--amber); }
.card-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 22px 0 18px; }
.card-metrics > div { display: flex; flex-direction: column; gap: 4px; }
.metric-label { color: var(--muted); font-size: 12px; }
.card-metrics strong { font-size: 20px; }
.card-metrics strong small { color: var(--muted); font-size: 12px; font-weight: 550; }
.card-footer { align-items: center; padding-top: 13px; border-top: 1px solid #edf1ee; color: var(--green); font-size: 13px; font-weight: 650; }
.calculation-note { margin: 18px 0 0; color: var(--muted); font-size: 13px; }
.empty-state { padding: 50px 24px; text-align: center; }
.empty-icon { display: grid; width: 50px; height: 50px; place-items: center; margin: 0 auto 15px; border-radius: 15px; background: var(--green-pale); color: var(--green); font-size: 30px; }
.empty-state p { max-width: 470px; margin: 0 auto 20px; }
.login-wrap { width: min(100%, 410px); margin: 6vh auto 0; }
.login-wrap h1 { font-size: 32px; }
.login-wrap > .muted { margin-bottom: 22px; }
.form-stack { display: grid; gap: 18px; padding: 25px; }
label { display: grid; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 650; }
input { width: 100%; min-height: 43px; padding: 9px 11px; border: 1px solid #cfdad4; border-radius: 8px; outline: none; background: #fff; color: var(--ink); font-weight: 450; }
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(37 107 86 / 12%); }
.checkbox-label { display: flex; align-items: center; gap: 9px; color: var(--muted); font-weight: 500; }
.checkbox-label input { width: 16px; min-height: 16px; margin: 0; accent-color: var(--green); }
.medication-form { padding: 25px; }
.form-section + .form-section { margin-top: 27px; padding-top: 24px; border-top: 1px solid var(--line); }
.form-section h2 { margin-bottom: 5px; }
.field-help { margin-bottom: 14px; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.four-columns { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field-span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.detail-card { padding: 21px; }
.detail-card h2 { margin: 0; }
.detail-list { margin: 19px 0 0; }
.detail-list > div { display: flex; justify-content: space-between; gap: 14px; padding: 10px 0; border-top: 1px solid #edf1ee; }
.detail-list dt { color: var(--muted); font-size: 13px; }
.detail-list dd { margin: 0; text-align: right; font-size: 13px; font-weight: 650; }
.section-heading-spaced { margin: 32px 0 14px; }
.purchase-form { padding: 20px; }
.purchase-form .form-actions { margin-top: 16px; }
.purchase-history { margin-top: 14px; padding: 5px 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 9px; border-bottom: 1px solid #edf1ee; font-size: 13px; }
th { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.table-action { text-align: right; }
.danger-link { color: var(--red); }
.delete-form { margin-top: 24px; text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

@media (max-width: 760px) {
    .page { width: min(100% - 32px, 600px); padding-top: 32px; }
    .topbar { height: 60px; padding: 0 16px; }
    .account-name { display: none; }
    .page-heading { align-items: flex-start; }
    .page-heading > .button { flex: 0 0 auto; }
    .medication-grid, .detail-grid { grid-template-columns: 1fr; }
    .form-grid.four-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
    .page { width: min(100% - 24px, 600px); padding-top: 25px; }
    .page-heading { flex-direction: column; gap: 16px; }
    .page-heading > .button { width: 100%; }
    .summary-row { grid-template-columns: 1fr; gap: 9px; }
    .medication-card { padding: 16px; }
    .medication-card-top { flex-direction: column; }
    .status { align-self: flex-start; }
    .medication-form { padding: 18px; }
    .form-grid, .form-grid.four-columns { grid-template-columns: 1fr; }
    .field-span-2 { grid-column: auto; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
    .section-heading { align-items: center; }
    .footer { padding-right: 14px; padding-left: 14px; }
}
