:root {
    --bg: #f3f4f5;
    --card: #ffffff;
    --text: #1b1b1f;
    --muted: #6e6f78;
    --line: #e8d8b0;
    --primary: #1f1712;
    --primary-dark: #0f0c0a;
    --gold: #c89a4b;
    --gold-soft: #f1dfb1;
    --danger: #a12828;
    --success: #1a7f4b;
    --shadow: 0 14px 40px rgba(16, 12, 9, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background:
        radial-gradient(circle at top, rgba(200, 154, 75, 0.12), transparent 30%),
        linear-gradient(180deg, #f8f8f8 0%, var(--bg) 100%);
    color: var(--text);
}

body.modal-open {
    overflow: hidden;
}

a { color: var(--primary); }

img { max-width: 100%; display: block; }

.page-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(244, 244, 245, 0.94);
    backdrop-filter: blur(6px);
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.page-loader.is-hidden {
    opacity: 0;
    visibility: hidden;
}

.page-loader-card {
    background: #fff;
    border: 1px solid rgba(200, 154, 75, 0.24);
    border-radius: 28px;
    box-shadow: var(--shadow);
    padding: 26px 28px;
    width: min(92vw, 360px);
    display: grid;
    justify-items: center;
    gap: 14px;
    text-align: center;
}

.page-loader-logo {
    width: 180px;
    height: auto;
}

.page-loader-spinner {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 4px solid #eadfca;
    border-top-color: var(--gold);
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(22, 17, 13, 0.92);
    color: white;
    padding: 18px 28px;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: space-between;
    align-items: center;
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-logo {
    width: 74px;
    min-width: 74px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    padding: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.topbar h1 { margin: 0; font-size: 1.7rem; letter-spacing: 0.02em; }
.topbar p { margin: 6px 0 0; opacity: 0.86; }

.topnav { display: flex; gap: 12px; flex-wrap: wrap; }

.topnav a,
.button-secondary,
button,
input,
select,
textarea {
    border-radius: 14px;
}

.topnav a,
.button-secondary {
    color: white;
    text-decoration: none;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 24px 90px;
}

.grid.two-columns {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
}

.card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.96));
    border: 1px solid rgba(200, 154, 75, 0.22);
    box-shadow: var(--shadow);
    border-radius: 24px;
    padding: 22px;
    margin-bottom: 20px;
}

.card-head { margin-bottom: 18px; }

.card-head.between,
.actions-row,
.search-form,
.patient-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
    align-items: center;
}

.auth-card {
    max-width: 540px;
    margin: 46px auto;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

.form-grid label,
label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 600;
    color: var(--text);
}

.full-width { grid-column: 1 / -1; }

input,
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #d8d5ce;
    font-size: 0.97rem;
    background: #fcfcfc;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(200, 154, 75, 0.12);
}

textarea { resize: vertical; }

button,
.button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    text-decoration: none;
    cursor: pointer;
    font-weight: 700;
}

button:hover,
.button-secondary:hover,
.topnav a:hover { opacity: 0.94; }

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid #eee7d8;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.9rem;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.danger-link { color: var(--danger) !important; }

.alert {
    padding: 14px 16px;
    border-radius: 16px;
    margin-bottom: 16px;
    font-weight: 700;
}

.alert-success {
    background: #e8f7ef;
    color: var(--success);
    border: 1px solid #b9e4ca;
}

.alert-error {
    background: #fff0f0;
    color: var(--danger);
    border: 1px solid #efc7c7;
}

.hint-box {
    background: #fbf7ef;
    border: 1px dashed #d4b36d;
    border-radius: 18px;
    padding: 16px;
    margin-top: 18px;
}

.success-box {
    background: #eefaf3;
    border-color: #9ed1b3;
}

.inline-check {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.inline-check input { width: auto; }

.record-list {
    display: grid;
    gap: 16px;
}

.record-item {
    border: 1px solid rgba(200, 154, 75, 0.22);
    border-radius: 18px;
    padding: 18px;
    background: linear-gradient(180deg, #fff, #fcfaf6);
}

.record-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    color: var(--muted);
}

.footer {
    text-align: center;
    padding: 24px;
    color: var(--muted);
}

.floating-app-btn {
    position: fixed;
    right: 22px;
    bottom: 24px;
    z-index: 300;
    min-width: 72px;
    border-radius: 999px;
    padding: 13px 18px;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.18);
    background: linear-gradient(135deg, #1d1712 0%, #c89a4b 100%);
    color: #fff;
}

.app-modal {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.52);
    padding: 20px;
}

.app-modal.is-visible {
    display: flex;
}

.app-modal-card {
    width: min(92vw, 430px);
    background: #fff;
    border-radius: 28px;
    padding: 28px 24px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.2);
    position: relative;
    text-align: center;
    border: 1px solid rgba(200, 154, 75, 0.25);
}

.app-modal-logo {
    width: 180px;
    margin: 0 auto 18px;
}

.app-modal-card h2 {
    margin: 0 0 10px;
}

.app-modal-card p {
    margin: 0 0 10px;
    font-size: 1.08rem;
    font-weight: 700;
    color: var(--primary);
}

.app-modal-card small {
    color: var(--muted);
    line-height: 1.5;
}

.app-modal-close {
    position: absolute;
    right: 12px;
    top: 12px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    padding: 0;
}

.patient-access-box {
    display: grid;
    gap: 8px;
}

.badge-gold {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(200, 154, 75, 0.12);
    color: #8a6326;
    font-weight: 700;
    font-size: 0.9rem;
}

@media (max-width: 960px) {
    .grid.two-columns,
    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .topbar {
        padding: 16px 18px;
    }

    .brand-wrap {
        width: 100%;
        align-items: flex-start;
    }

    .brand-logo {
        width: 60px;
        min-width: 60px;
    }

    .topbar h1 {
        font-size: 1.35rem;
    }

    .container {
        padding: 20px 16px 90px;
    }

    .card {
        border-radius: 20px;
        padding: 18px;
    }

    .floating-app-btn {
        right: 16px;
        bottom: 18px;
    }
}
