:root {
    --border: #d7dbe0;
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 14px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.site-footer {
    text-align: center;
    padding: 16px;
    color: var(--muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
}

.topbar nav {
    display: flex;
    align-items: center;
}

.topbar nav a {
    margin-right: 16px;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    line-height: 28px;
}

.topbar nav a:hover { color: var(--accent); }

.brand {
    display: inline-flex;
    align-items: center;
    margin-right: 12px;
}
.brand img {
    height: 28px;
    width: 28px;
    border-radius: 4px;
}

.topbar .whoami {
    display: flex;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
}

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 24px;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px 16px;
}

label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

/* Reserves two lines of height for every field label (not checkbox/
   dropzone labels, whose input is nested inside them rather than a
   following sibling) so a label that happens to wrap to two lines --
   e.g. "New Password (leave blank to keep current)" -- doesn't push its
   input down relative to shorter, single-line labels sharing the same
   .grid-form row. Using em (relative to the label's own 12px font-size)
   keeps the reserved height exact regardless of line-height inheritance. */
label:has(+ input),
label:has(+ select),
label:has(+ textarea),
label:has(+ .field-with-action) {
    min-height: 2.6em;
    line-height: 1.3;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 16px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

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

.patient-search-wrapper {
    position: relative;
}
.patient-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 20;
    margin-top: 2px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    max-height: 220px;
    overflow-y: auto;
}
.patient-search-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 6px 10px;
    border: none;
    background: none;
    cursor: pointer;
    font: inherit;
    color: var(--text);
}
.patient-search-item:hover,
.patient-search-item:focus {
    background: var(--bg);
}

.field-with-action {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.field-with-action input { flex: 1 1 auto; min-width: 0; }
.field-with-action button { flex: 0 0 auto; white-space: nowrap; }

.dropzone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 18px;
    text-align: center;
    cursor: pointer;
    background: #fafbfc;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover,
.dropzone.dropzone-active {
    border-color: var(--accent);
    background: #eff6ff;
}
.dropzone input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
}
.dropzone .dropzone-label {
    color: var(--muted);
    font-size: 13px;
}
.dropzone .dropzone-filename {
    margin-top: 6px;
    font-weight: 600;
    color: var(--text);
    font-size: 13.5px;
    word-break: break-all;
}

.subcard {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-top: 12px;
    background: #fafbfc;
}

.file-list-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}
.file-list-row:last-child {
    border-bottom: none;
}
.file-list-name {
    flex: 0 1 auto;
    font-size: 13.5px;
    word-break: break-all;
}
.file-list-row input[type="text"] {
    flex: 1 1 auto;
    min-width: 120px;
}

.actions-row {
    margin-top: 14px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

button, .btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: #f0f1f3; }

.btn-danger {
    background: #fff;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
}
.link-button:hover { color: var(--accent-hover); background: none; border: none; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

th, td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    vertical-align: middle;
}

th a { color: inherit; text-decoration: none; }
th a:hover { color: var(--accent); }

tbody tr:hover { background: #fafbfc; }

.token {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.table-actions { white-space: nowrap; }
.table-actions a, .table-actions form { display: inline-block; margin-right: 6px; }
.table-actions button { padding: 4px 8px; font-size: 12px; }

.empty-state {
    color: var(--muted);
    padding: 20px 0;
    text-align: center;
}

.flash {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

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

.new-token-banner {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.new-token-banner .token { font-size: 16px; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 12px;
    font-weight: 600;
}

/* flatpickr's calendar popup (vendored, see CLAUDE.md's "Date formatting"
   section) has a fixed ~308px width by default -- fine on desktop, but
   wider than the card/subcard column it opens from on a narrow phone
   (worst case: a retrieval-token row's expiry field, nested inside a
   .subcard's own padding), and wider than the viewport itself on the
   narrowest phones. flatpickr's own JS measures .dayContainer's *rendered*
   width and propagates it to .flatpickr-days/.flatpickr-calendar, so
   overriding this one rule is enough for all three to shrink together.
   `!important` is required because flatpickr.min.css is linked after this
   file (see includes/layout.php) and would otherwise win the cascade at
   equal specificity. min() leaves desktop/tablet at the original
   307.875px and only shrinks once the viewport is too narrow to fit that
   with margin either side. */
.flatpickr-calendar,
.flatpickr-calendar .flatpickr-days,
.flatpickr-calendar .dayContainer {
    width: min(307.875px, calc(100vw - 32px)) !important;
    min-width: 0 !important;
    max-width: min(307.875px, calc(100vw - 32px)) !important;
}

/* Mobile */
@media (max-width: 640px) {
    .container {
        padding: 16px 12px 48px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .topbar nav {
        display: flex;
        flex-wrap: wrap;
        gap: 4px 14px;
    }
    .topbar nav a {
        margin-right: 0;
    }
    .topbar .whoami {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
    }

    .card {
        padding: 16px;
    }

    .grid-form {
        grid-template-columns: 1fr;
    }

    .field-with-action {
        flex-wrap: wrap;
    }
    .field-with-action button {
        flex: 1 1 100%;
    }

    button, .btn {
        padding: 10px 16px;
    }

    .actions-row {
        flex-direction: column;
        align-items: stretch;
    }
    .actions-row button,
    .actions-row .btn {
        width: 100%;
        text-align: center;
    }

    table {
        font-size: 12.5px;
    }
    th, td {
        padding: 7px 8px;
    }

    .new-token-banner > div {
        width: 100%;
    }
}
