:root {
    --bg: #eef3f1;
    --bg-accent: #d9e7e2;
    --surface: #ffffff;
    --ink: #1c2b28;
    --muted: #5b6f6a;
    --line: #c9d6d1;
    --teal: #1f6f63;
    --teal-dark: #155249;
    --teal-soft: #e4f3ef;
    --amber: #b7791f;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --shadow: 0 10px 30px rgba(28, 43, 40, 0.08);
    --radius: 16px;
    --font: "Segoe UI", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(31, 111, 99, 0.12), transparent 40%),
        linear-gradient(180deg, var(--bg), var(--bg-accent));
    min-height: 100%;
}

body { min-height: 100vh; }

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(8px);
    background: rgba(238, 243, 241, 0.92);
    border-bottom: 1px solid var(--line);
}

.topbar-inner {
    max-width: 820px;
    margin: 0 auto;
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.topbar-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    flex: 1;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.02em;
}

.brand-center {
    width: 100%;
    text-align: center;
    font-size: 1.15rem;
}

.caregiver-chip {
    font-size: 0.85rem;
    color: var(--muted);
}

.page {
    max-width: 820px;
    margin: 0 auto;
    padding: 1.25rem 1rem 3rem;
}

h1 {
    margin: 0 0 0.35rem;
    font-size: 1.65rem;
    line-height: 1.2;
}

h2 {
    margin: 0 0 0.75rem;
    font-size: 1.25rem;
}

.lede {
    margin: 0 0 1.25rem;
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.stack { display: grid; gap: 0.85rem; }

.list {
    display: grid;
    gap: 0.75rem;
}

.list-item {
    display: block;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    color: inherit;
    box-shadow: var(--shadow);
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.list-item:hover,
.list-item:focus-visible {
    transform: translateY(-1px);
    border-color: var(--teal);
    outline: none;
}

.list-item.inactive {
    opacity: 0.72;
    background: #f7f8f8;
}

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

.list-item-meta {
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.92rem;
}

.badge {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #eceff1;
    color: var(--muted);
}

.badge-inactive {
    background: #eceff1;
    color: #667;
}

.badge-rx {
    background: #e8f1ff;
    color: #1d4f91;
}

.badge-otc {
    background: #fff4df;
    color: #8a5a00;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: none;
    border-radius: 12px;
    padding: 0.85rem 1.1rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    color: #fff;
    background: var(--teal);
}

.btn:hover { background: var(--teal-dark); }

.btn-block { width: 100%; }

.btn-home,
.btn-secondary {
    background: var(--teal-soft);
    color: var(--teal-dark);
}

.btn-home:hover,
.btn-secondary:hover {
    background: #d3ebe4;
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
}

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

.btn-danger:hover {
    background: #912018;
}

.btn-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-row .btn { flex: 1; min-width: 120px; }

.alert {
    padding: 0.85rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    font-weight: 600;
}

.alert-success {
    background: var(--teal-soft);
    color: var(--teal-dark);
}

.alert-error {
    background: var(--danger-soft);
    color: var(--danger);
}

.form-grid {
    display: grid;
    gap: 0.9rem;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="tel"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.8rem 0.9rem;
    font: inherit;
    background: #fff;
    color: var(--ink);
}

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

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 600;
}

.checkbox-row input { width: auto; }

.menu-grid {
    display: grid;
    gap: 0.85rem;
}

.menu-link {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1.15rem;
    border-radius: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
}

.menu-link:hover {
    border-color: var(--teal);
    background: var(--teal-soft);
}

.menu-link .menu-icon {
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    max-width: 18px;
    max-height: 18px;
    flex: 0 0 18px;
    color: var(--teal-dark);
    display: block;
}

.menu-link:hover .menu-icon {
    color: var(--teal);
}

.pin-wrap {
    max-width: 360px;
    margin: 2rem auto 0;
    text-align: center;
}

.pin-display {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin: 1.25rem 0 1.5rem;
}

.pin-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--teal);
    background: transparent;
}

.pin-dot.filled { background: var(--teal); }

.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.pin-key {
    aspect-ratio: 1.35;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fff;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow);
}

.pin-key:active { transform: scale(0.98); }

.pin-key.action {
    font-size: 1rem;
    color: var(--muted);
}

.detail-block {
    display: grid;
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

.detail-row {
    display: grid;
    gap: 0.15rem;
    padding-bottom: 0.65rem;
    border-bottom: 1px solid var(--line);
}

.detail-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 700;
}

.detail-value {
    font-size: 1.05rem;
    white-space: pre-wrap;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(18, 28, 26, 0.55);
    z-index: 50;
}

.modal.open { display: flex; }

.modal-card {
    width: min(480px, 100%);
    background: #fff;
    border-radius: 18px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.modal-card h2 { margin-bottom: 0.5rem; }

.signature-wrap {
    border: 1px dashed var(--line);
    border-radius: 14px;
    background: #fafafa;
    overflow: hidden;
}

#signature-canvas {
    display: block;
    width: 100%;
    height: 180px;
    touch-action: none;
    cursor: crosshair;
}

.footer-actions {
    margin-top: 1.5rem;
    display: grid;
    gap: 0.75rem;
}

.empty {
    padding: 1.25rem;
    text-align: center;
    color: var(--muted);
    background: rgba(255,255,255,0.6);
    border-radius: 14px;
    border: 1px dashed var(--line);
}

.section-label {
    margin: 1.5rem 0 0.65rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 700;
}

@media (max-width: 480px) {
    h1 { font-size: 1.4rem; }
    .pin-key { aspect-ratio: 1.2; }
}
