/* SGM Clinical CRM — compiled brand stylesheet.
   No build step required on production. Tokens mirror config/sgm.php. */

:root {
    --sgm-primary: #FEC679;
    --sgm-dark:    #E5A84E;
    --sgm-medium:  #FED59A;
    --sgm-light:   #FFF3DE;
    --sgm-pale:    #FFFAF0;
    --text:        #000000;
    --text-sub:    #333333;
    --text-meta:   #666666;
    --bg:          #FFFFFF;
    --bg-neutral:  #F5F5F5;
    --border:      #E0E0E0;

    --ok:      #2e7d32;
    --warn:    #b26a00;
    --danger:  #b3261e;
    --info:    #1565c0;

    --font-head: -apple-system, BlinkMacSystemFont, "SF Pro Display", Arial, Helvetica, sans-serif;
    --font-body: Georgia, "Times New Roman", serif;
    --font-ui:   -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Arial, sans-serif;

    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-body);
    color: var(--text);
    background: var(--bg-neutral);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .h { font-family: var(--font-head); font-weight: 600; color: var(--text); letter-spacing: -.01em; }
a { color: var(--sgm-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Auth layout ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
    width: 100%; max-width: 400px; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 32px;
}
.brand-mark {
    font-family: var(--font-head); font-weight: 700; font-size: 20px;
    display: flex; align-items: center; gap: 10px; margin-bottom: 4px;
}
.brand-logo {
    display: block; flex: 0 0 auto; width: 54px; height: 54px;
    object-fit: contain;
}
.sidebar .brand-logo { width: 42px; height: 42px; }
.brand-sub { color: var(--text-meta); font-size: 13px; margin-bottom: 24px; font-family: var(--font-ui); }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    background: var(--bg); border-right: 1px solid var(--border);
    padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand-mark { font-size: 17px; padding: 0 8px 16px; }
.nav-group-label {
    font-family: var(--font-ui); text-transform: uppercase; letter-spacing: .06em;
    font-size: 11px; color: var(--text-meta); margin: 16px 8px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
    font-family: var(--font-ui); font-size: 14px; color: var(--text-sub); margin-bottom: 2px;
}
.nav-item:hover { background: var(--sgm-pale); text-decoration: none; color: var(--text); }
.nav-item.active { background: var(--sgm-light); color: var(--text); font-weight: 600; }
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--sgm-dark); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 28px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar .page-title { font-family: var(--font-head); font-size: 18px; font-weight: 600; }
.user-chip { font-family: var(--font-ui); font-size: 13px; color: var(--text-sub);
    display: flex; align-items: center; gap: 12px; }
.role-badge {
    font-family: var(--font-ui); font-size: 11px; font-weight: 600; padding: 3px 9px;
    border-radius: 20px; background: var(--sgm-light); color: var(--sgm-dark);
    text-transform: uppercase; letter-spacing: .04em;
}
.content { width: 100%; max-width: none; padding: clamp(22px, 2.6vw, 42px); }

/* ---------- Cards / tiles ---------- */
.grid { display: grid; gap: clamp(20px, 2vw, 30px); width: 100%; }
.grid > * { min-width: 0; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
    background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--radius); padding: clamp(20px, 1.8vw, 28px); box-shadow: var(--shadow);
    min-width: 0; overflow-wrap: anywhere;
}
.card > *, .row-between > *, .mini-list li > *, .def-list > * { min-width: 0; max-width: 100%; }
.tile .label { font-family: var(--font-ui); font-size: 12px; color: var(--text-meta);
    text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-family: var(--font-head); font-size: 30px; font-weight: 700; margin-top: 6px; }
.tile .value small { font-size: 13px; color: var(--text-meta); font-weight: 400; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.muted { color: var(--text-meta); font-family: var(--font-ui); font-size: 13px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-family: var(--font-ui); font-size: 14px; }
table.data th {
    text-align: left; padding: 12px 16px; background: var(--bg-neutral);
    font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-meta);
    border-bottom: 1px solid var(--border);
}
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text-sub); }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--sgm-pale); }
table.data .btn, table.data .badge { white-space: nowrap; }

/* Tables used throughout clinical, finance, care and administration views. */
table.table {
    width: 100%; min-width: 100%; border-collapse: collapse; border-spacing: 0;
    table-layout: auto; font-family: var(--font-ui); font-size: 13px;
}
table.table th {
    text-align: left; padding: 11px 13px; background: var(--bg-neutral);
    color: var(--text-meta); font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .035em; line-height: 1.35;
    border-bottom: 1px solid var(--border); vertical-align: bottom;
}
table.table td {
    padding: 11px 13px; color: var(--text-sub); line-height: 1.45;
    border-bottom: 1px solid var(--border); vertical-align: top;
    overflow-wrap: anywhere;
}
table.table tbody tr:last-child td { border-bottom: none; }
table.table tbody tr:hover td { background: var(--sgm-pale); }
table.table .btn, table.table .badge { white-space: nowrap; }

/* ---------- Badges ---------- */
.badge { font-family: var(--font-ui); font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.badge.active   { background: #e8f5e9; color: var(--ok); }
.badge.inactive { background: #f0f0f0; color: var(--text-meta); }
.badge.suspended{ background: #fdecea; color: var(--danger); }

/* ---------- Forms ---------- */
form .field { margin-bottom: 16px; }
label { display: block; font-family: var(--font-ui); font-size: 13px; color: var(--text-sub); margin-bottom: 6px; font-weight: 500; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=date], input[type=number],
input[type=tel], input[type=time], input[type=datetime-local], input[type=search], select, textarea {
    width: 100%; font-family: var(--font-ui); font-size: 14px; color: var(--text);
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--sgm-dark); box-shadow: 0 0 0 3px var(--sgm-light);
}
textarea { min-height: 110px; resize: vertical; line-height: 1.55; }
textarea[data-autogrow] { min-height: 116px; overflow-y: hidden; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-family: var(--font-ui); font-size: 14px; }
.checkbox-row input { width: auto; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-ui);
    font-size: 14px; font-weight: 600; padding: 10px 18px; border-radius: 8px;
    border: 1px solid transparent; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--sgm-primary); color: var(--text); }
.btn-primary:hover { background: var(--sgm-dark); text-decoration: none; }
.btn-ghost { background: var(--bg); color: var(--text-sub); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-neutral); text-decoration: none; }
.btn-danger { background: var(--bg); color: var(--danger); border-color: #f2c4c0; }
.btn-danger:hover { background: #fdecea; text-decoration: none; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ---------- Alerts ---------- */
.alert { font-family: var(--font-ui); font-size: 14px; padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; }
.alert-success { background: #e8f5e9; color: var(--ok); }
.alert-error   { background: #fdecea; color: var(--danger); }
.alert-info    { background: var(--sgm-light); color: var(--sgm-dark); }
.field-error { color: var(--danger); font-family: var(--font-ui); font-size: 12px; margin-top: 5px; }

/* ---------- Layout helpers ---------- */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.pagination-wrap { margin-top: 18px; }
.pagination {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    width: 100%; flex-wrap: wrap; font-family: var(--font-ui); font-size: 13px;
}
.pagination-summary { color: var(--text-meta); }
.pagination-controls { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.pagination-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: auto; min-width: 34px; height: 34px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: 7px;
    background: var(--bg); color: var(--text-sub); line-height: 1;
}
a.pagination-link:hover { background: var(--sgm-pale); color: var(--text); text-decoration: none; }
.pagination-arrow { width: 34px; padding: 0; font-size: 20px; font-weight: 600; }
.pagination-current { background: var(--sgm-light); border-color: var(--sgm-primary); font-weight: 700; }
.pagination-disabled { color: var(--text-meta); background: var(--bg-neutral); opacity: .55; cursor: not-allowed; }
.pagination-ellipsis { min-width: 24px; padding: 0 4px; border-color: transparent; background: transparent; }
.mt-4 { margin-top: 24px; } .mb-4 { margin-bottom: 24px; }
.notice-box { background: var(--sgm-pale); border: 1px dashed var(--sgm-dark); border-radius: 8px; padding: 14px 16px; font-family: var(--font-ui); font-size: 13px; color: var(--text-sub); }

/* ---------- Responsive: tablet ---------- */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 1024px) { .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px)  {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
    .grid-4, .grid-5, .grid-2 { grid-template-columns: 1fr; }
    .card:has(table.table) { overflow-x: auto; }
    table.table, table.data { min-width: 680px; }
    table.table th, table.table td, table.data th, table.data td { white-space: nowrap; }
    .pagination { align-items: flex-start; }
    .pagination-summary { flex-basis: 100%; }
}

/* ===== Phase 2 additions ===== */
.badge.info    { background: #e7f1fb; color: #1b5e9b; }
.badge.danger  { background: #fdecea; color: var(--danger); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1024px) { .grid-3 { grid-template-columns: 1fr; } }

.alert-warning { background: #fff6e6; border: 1px solid var(--sgm-dark); color: #8a5a00; }

.dup-box { border: 1px solid var(--sgm-dark); background: var(--sgm-pale); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; font-family: var(--font-ui); font-size: 13px; }
.dup-box a { color: var(--sgm-dark); font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); font-family: var(--font-ui); font-size: 13px; }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--sgm-primary); border: 2px solid #fff; }
.timeline .t-meta { color: var(--text-meta); font-size: 12px; }

.patient-card { border: 1px solid var(--border); border-radius: 10px; padding: 16px; background: #fff; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.patient-card .time { font-family: var(--font-head); font-size: 22px; font-weight: 700; color: var(--sgm-dark); min-width: 66px; }
.patient-card .who { font-family: var(--font-ui); }
.patient-card .who .name { font-weight: 600; font-size: 15px; }
.patient-card .who .meta { color: var(--text-meta); font-size: 13px; margin-top: 2px; }
.redflag-banner { background: #fdecea; border: 1px solid var(--danger); color: var(--danger); border-radius: 8px; padding: 12px 14px; font-family: var(--font-ui); font-size: 13px; font-weight: 600; margin-bottom: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; font-family: var(--font-ui); font-size: 13px; color: var(--text-meta); border-bottom: 2px solid transparent; cursor: pointer; }
.tabs a.active { color: var(--sgm-dark); border-bottom-color: var(--sgm-primary); font-weight: 600; }

.def-list { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-family: var(--font-ui); font-size: 14px; }
.def-list dt { color: var(--text-meta); }
.def-list dd { margin: 0; color: var(--text-sub); white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.readonly-field { min-height: 44px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--sgm-pale); overflow-wrap: anywhere; }
.readonly-field > div + div { margin-top: 6px; }
.finance-cancel-order-form { display: grid; gap: 6px; min-width: 190px; }
.searchable-select { position: relative; width: 100%; min-width: 0; }
.searchable-select-input { width: 100%; padding-right: 34px; background-image: linear-gradient(45deg, transparent 50%, var(--text-sub) 50%), linear-gradient(135deg, var(--text-sub) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.searchable-native-select { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; opacity: 0 !important; pointer-events: none !important; }
.searchable-select-menu { position: absolute; z-index: 80; top: calc(100% + 4px); left: 0; right: 0; max-height: 280px; overflow-y: auto; padding: 5px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); box-shadow: 0 14px 36px rgba(23, 33, 43, .16); }
.searchable-select-option { display: block; width: 100%; padding: 9px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--text); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.searchable-select-option:hover, .searchable-select-option.active { background: var(--sgm-pale); color: var(--sgm-dark); }
.searchable-select-empty { padding: 10px; color: var(--text-sub); font-size: 12px; }
.section-label { font-family: var(--font-ui); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-meta); margin: 4px 0 10px; }
[x-cloak] { display: none !important; }

/* ===== Phase 3: encounter editor ===== */
.encounter-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr) 190px; gap: clamp(20px, 1.7vw, 28px); align-items: start; }
.enc-summary { position: sticky; top: 16px; }
.enc-summary h4 { font-family: var(--font-ui); font-size: 12px; text-transform: uppercase; letter-spacing:.04em; color: var(--text-meta); margin: 14px 0 6px; }
.enc-summary .pill { display:inline-block; background: var(--sgm-pale); border:1px solid var(--border); border-radius:14px; padding:2px 9px; font-family:var(--font-ui); font-size:12px; margin:2px 3px 0 0; }
.enc-actions { position: sticky; top: 16px; display:flex; flex-direction:column; gap:8px; }
.enc-actions .btn { width:100%; justify-content:center; }
.mini-list { list-style:none; margin:0; padding:0; font-family:var(--font-ui); font-size:13px; }
.mini-list li { padding:8px 0; border-bottom:1px solid var(--border); display:flex; justify-content:space-between; gap:8px; overflow-wrap:anywhere; }
.mini-list li:last-child { border-bottom:none; }
.history-line, .history-medicine, .timeline-summary-item, details, summary, pre, code {
    min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word;
}
pre { white-space: pre-wrap; overflow-x: auto; }
.score-grid { display:grid; grid-template-columns: 1fr auto; gap:8px 14px; align-items:center; font-family:var(--font-ui); font-size:14px; }
.sign-warn { background:#fff6e6; border:1px solid var(--sgm-dark); color:#8a5a00; border-radius:8px; padding:10px 12px; font-family:var(--font-ui); font-size:12px; }
@media (max-width: 1240px) { .encounter-grid { grid-template-columns: 1fr; } .enc-summary, .enc-actions { position: static; } }

/* ---- Phase 4: prescription / medication / discharge ---- */
.page-head { display:flex; justify-content:space-between; align-items:flex-end; gap:16px; flex-wrap:wrap; }
.page-kicker { font-size:12px; color:#666; }
.page-head-search {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 8px; flex-wrap: wrap; min-width: min(100%, 320px);
}
.page-head-search input { flex: 1 1 220px; min-width: 0; }
.page-head-search .btn { flex: 0 0 auto; width: auto; align-self: center; }
.finance-formula {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
}
.finance-case-overview {
    grid-template-columns: minmax(300px, .72fr) minmax(560px, 1.28fr);
    align-items: start;
}
.grid-wide-left {
    grid-template-columns: minmax(560px, 1.28fr) minmax(300px, .72fr);
    align-items: start;
}
.grid-wide-right {
    grid-template-columns: minmax(300px, .72fr) minmax(560px, 1.28fr);
    align-items: start;
}
.finance-allocation-card table.table th:last-child,
.finance-allocation-card table.table td:last-child {
    width: 1%; white-space: nowrap; overflow-wrap: normal; text-align: right;
}
.allocation-rules-table th:nth-child(2),
.allocation-rules-table td:nth-child(2) { white-space: nowrap; }
.finance-formula > div {
    display: grid; gap: 5px; padding: 14px 16px; border: 1px solid var(--border);
    border-radius: 9px; background: var(--bg); font-family: var(--font-ui);
}
.finance-formula strong { font-size: 13px; }
.finance-formula span { color: var(--text-meta); font-size: 12px; line-height: 1.5; }
.finance-rule-note { margin-top: 10px; line-height: 1.65; }
.allocation-switch {
    display: inline-flex; gap: 4px; margin: 6px 0 12px; padding: 4px;
    border-radius: 9px; background: var(--bg-neutral); font-family: var(--font-ui);
}
.allocation-switch-button {
    min-height: 32px; padding: 5px 10px; border: 0; border-radius: 7px;
    background: transparent; color: var(--text-meta); cursor: pointer; font: 600 12px/1.3 var(--font-ui);
}
.allocation-switch-button.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.allocation-full-table tbody tr:has(td:first-child:not(:empty)) td { border-top: 2px solid var(--border); }
.case-line-form, .payment-form {
    margin-top: 12px; display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap;
}
.line-total-preview {
    display: grid; gap: 2px; min-width: 130px; padding: 6px 10px;
    border-radius: 7px; background: var(--sgm-pale); font-family: var(--font-ui);
}
.line-total-preview span { color: var(--text-meta); font-size: 10px; text-transform: uppercase; }
.line-total-preview strong { color: var(--sgm-dark); font-size: 15px; }
.finance-total-row td { background: var(--sgm-pale); }
.payment-balance {
    display: grid; gap: 3px; margin-bottom: 12px; padding: 12px 14px;
    border: 1px solid var(--sgm-primary); border-radius: 9px; background: var(--sgm-pale);
    font-family: var(--font-ui);
}
.payment-balance span { color: var(--text-meta); font-size: 12px; }
.payment-balance strong { color: var(--sgm-dark); font-size: 22px; }
.payment-balance small, .field-help { color: var(--text-meta); font: 12px/1.5 var(--font-ui); }
.payment-history-table th:nth-child(2),
.payment-history-table td:nth-child(2),
.payment-history-table th:nth-child(3),
.payment-history-table td:nth-child(3) { white-space: nowrap; overflow-wrap: normal; }
.payout-statement-table th:first-child,
.payout-statement-table td:first-child,
.payout-statement-table th:nth-last-child(-n+3),
.payout-statement-table td:nth-last-child(-n+3) { white-space: nowrap; overflow-wrap: normal; }
.finance-adjustment-fields {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px; align-items: end;
}
.financial-dictionary { display: grid; gap: 16px; margin-top: 16px; }
.definition-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.definition-item { padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-neutral); }
.research-variable-row { display:grid; grid-template-columns:minmax(180px,1.2fr) minmax(130px,.75fr) minmax(110px,.55fr) minmax(180px,1fr) auto; gap:10px; align-items:end; }
.research-variable-row .field { margin-bottom:0; }
@media (max-width: 1024px) { .research-variable-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.definition-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-family: var(--font-ui); }
.definition-heading code { color: var(--text-meta); font-size: 10px; overflow-wrap: anywhere; }
.definition-item p { margin: 6px 0 0; color: var(--text-sub); font: 13px/1.55 var(--font-ui); }
.definition-formula { margin-top: 7px; color: var(--sgm-dark); font: 600 12px/1.45 var(--font-ui); }
.table-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.service-edit-grid {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px;
    align-items: end; margin-top: 14px;
}
.service-edit-grid .field { margin: 0; }
.service-edit-note { grid-column: span 3; }
.badge-warning { background:#FFF3DE; color:#E5A84E; border:1px solid #FED59A; }
.input-sm { padding:4px 6px; font-size:12px; border:1px solid #E0E0E0; border-radius:4px; }
.ac-item:hover { background:#FFFAF0; }
.alert-warning { background:#FFF3DE; border:1px solid #FED59A; color:#8a5a00; padding:10px 12px; border-radius:6px; }

@media (max-width: 1240px) {
    .finance-case-overview, .grid-wide-left, .grid-wide-right { grid-template-columns: 1fr; }
}

/* ===== Clinical reading and data-entry improvements ===== */
.protocol-sections { display: grid; gap: 14px; margin-top: 14px; }
.protocol-section {
    border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
    background: var(--bg);
}
.protocol-section-heading {
    display: flex; align-items: center; gap: 10px; padding: 12px 16px;
    background: var(--sgm-pale); border-bottom: 1px solid var(--border);
}
.protocol-section-heading h4 { margin: 0; font-size: 15px; }
.protocol-section-key {
    flex: 0 0 auto; border-radius: 6px; padding: 3px 8px; background: var(--sgm-light);
    color: var(--sgm-dark); font: 700 11px/1.4 var(--font-ui);
}
.protocol-section-body {
    padding: 16px; color: var(--text-sub); font-family: var(--font-ui);
    font-size: 14px; line-height: 1.75; white-space: normal;
}
.protocol-raw { margin-top: 12px; border: 1px solid var(--border); border-radius: 10px; }

.timeline-detail, .history-encounter {
    margin-top: 9px; border: 1px solid var(--border); border-radius: 9px; background: var(--bg);
}
.timeline-detail summary, .history-encounter summary {
    cursor: pointer; padding: 10px 12px; color: var(--text-sub); font-family: var(--font-ui);
    font-size: 13px; font-weight: 600;
}
.timeline-summary-grid {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px; margin: 3px 0 8px;
}
.timeline-summary-item {
    display: grid; align-content: start; gap: 3px; min-width: 0;
    padding: 9px 10px; border-radius: 7px; background: var(--bg-neutral);
}
.timeline-summary-item > strong {
    color: var(--text-meta); font-size: 10px; letter-spacing: .045em; text-transform: uppercase;
}
.timeline-summary-item > span { color: var(--text-sub); font-size: 12px; font-weight: 500; line-height: 1.45; }
.timeline-summary-action { color: var(--sgm-dark); font-size: 12px; }
.timeline-detail[open] summary, .history-encounter[open] summary {
    border-bottom: 1px solid var(--border); background: var(--sgm-pale);
}
.timeline-detail-content, .history-encounter-body { padding: 14px; display: grid; gap: 12px; }
.history-meta { color: var(--text-meta); font-family: var(--font-ui); font-size: 12px; }
.history-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.history-columns-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.history-line { margin-top: 6px; font-family: var(--font-ui); font-size: 13px; }
.history-prescription + .history-prescription { margin-top: 10px; }
.history-medicine {
    margin-top: 6px; padding: 8px 10px; border-left: 3px solid var(--sgm-primary);
    background: var(--bg-neutral); border-radius: 0 7px 7px 0; font-family: var(--font-ui); font-size: 13px;
}
.patient-history-panel { margin-bottom: 18px; }
.history-encounters { display: grid; gap: 9px; margin-top: 14px; }
.history-encounter summary { display: grid; grid-template-columns: minmax(150px, .7fr) minmax(0, 2fr); gap: 16px; }

.dose-calculator { padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--sgm-pale); margin-bottom: 16px; }
.dose-total {
    display: flex; align-items: baseline; flex-wrap: wrap; gap: 7px; padding: 10px 12px;
    border-radius: 8px; background: var(--bg); font-family: var(--font-ui); font-size: 13px;
}
.dose-total strong { font-size: 21px; color: var(--sgm-dark); }

.draft-autosave-status {
    min-height: 22px; padding: 3px 2px 7px; color: var(--text-meta);
    font-family: var(--font-ui); font-size: 12px;
}
.text-danger { color: var(--danger); }

@media (max-width: 900px) {
    .history-columns, .history-encounter summary, .timeline-summary-grid, .finance-formula { grid-template-columns: 1fr; }
    .definition-list { grid-template-columns: 1fr; }
    .allocation-switch { display: flex; }
    .allocation-switch-button { flex: 1 1 0; }
    .service-edit-grid { grid-template-columns: 1fr; }
    .service-edit-note { grid-column: auto; }
}
.service-category-manager > summary {
    align-items: center;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    list-style: none;
}

.service-category-manager > summary::-webkit-details-marker { display: none; }
.service-category-manager > summary small { color: var(--muted); display: block; font-size: 11px; margin-top: 3px; }
.service-category-create { align-items: end; display: grid; gap: 10px; grid-template-columns: minmax(220px, 1.5fr) minmax(180px, 1fr) 100px auto; margin-top: 12px; }
.service-category-create .field { margin: 0; }
.service-category-list { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 4px; }
.service-category-row { align-items: center; border-bottom: 1px solid var(--border); display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr) auto; padding: 10px 0; }
.service-category-row.is-inactive { opacity: .68; }
.service-category-update { align-items: center; display: grid; gap: 8px; grid-template-columns: 120px minmax(180px, 1.4fr) minmax(160px, 1fr) 80px 100px auto; }
.service-category-code small { color: var(--muted); display: block; font-size: 10px; margin-top: 2px; }
.service-category-active { font-size: 12px; white-space: nowrap; }

@media (max-width: 980px) {
    .service-category-create, .service-category-update { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .service-category-row { align-items: end; }
}

@media (max-width: 640px) {
    .service-category-create, .service-category-update { grid-template-columns: 1fr; }
}

/* ===== Role-scoped monthly dashboards ===== */
.dashboard-shell { display: grid; gap: clamp(28px, 3vw, 44px); }
.dashboard-head {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; flex-wrap: wrap;
    padding: clamp(22px, 2.4vw, 34px); border-radius: 16px;
    background: linear-gradient(125deg, #fff 0%, var(--sgm-pale) 65%, var(--sgm-light) 100%);
    border: 1px solid var(--sgm-medium); box-shadow: var(--shadow);
}
.dashboard-head h1 { margin: 4px 0 6px; font-size: clamp(25px, 2.4vw, 38px); }
.dashboard-head p { margin: 0; color: var(--text-meta); font: 13px/1.5 var(--font-ui); }
.dashboard-month-filter { min-width: min(100%, 330px); }
.dashboard-month-filter > div { display: flex; gap: 8px; }
.dashboard-month-filter input { min-width: 170px; }
.dashboard-section { display: grid; gap: 16px; min-width: 0; }
.dashboard-section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.dashboard-section-head h2 { margin: 2px 0 0; font-size: clamp(19px, 1.7vw, 25px); }
.section-eyebrow { color: var(--sgm-dark); font: 700 11px/1.3 var(--font-ui); letter-spacing: .08em; text-transform: uppercase; }
.section-note { color: var(--text-meta); font: 12px/1.4 var(--font-ui); }
.dashboard-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(12px, 1.5vw, 20px); }
.metric-card {
    min-width: 0; padding: clamp(17px, 1.7vw, 24px); border: 1px solid var(--border); border-radius: 13px;
    background: var(--bg); box-shadow: var(--shadow); font-family: var(--font-ui);
}
.metric-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--text-meta); font-size: 12px; }
.metric-card > strong { display: block; margin: 9px 0 4px; font: 700 clamp(25px, 2vw, 34px)/1.05 var(--font-head); overflow-wrap: anywhere; }
.metric-card > small { display: block; color: var(--text-meta); font-size: 11px; }
.metric-delta { flex: 0 0 auto; padding: 2px 7px; border-radius: 20px; font-size: 10px; font-weight: 700; }
.metric-delta.up { color: var(--ok); background: #e8f5e9; }
.metric-delta.down { color: var(--danger); background: #fdecea; }
.metric-delta.neutral { color: var(--text-meta); background: var(--bg-neutral); }
.money-card > strong { font-size: clamp(21px, 1.65vw, 29px); }
.dashboard-grid { display: grid; gap: clamp(14px, 1.7vw, 24px); min-width: 0; }
.dashboard-grid-wide { grid-template-columns: minmax(520px, 1.35fr) minmax(300px, .65fr); }
.dashboard-grid-equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dashboard-grid-quad { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.dashboard-panel {
    min-width: 0; padding: clamp(18px, 1.8vw, 26px); border: 1px solid var(--border); border-radius: 13px;
    background: var(--bg); box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.dashboard-panel h3 { margin: 0; font-size: 15px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.panel-head p { margin: 3px 0 0; color: var(--text-meta); font: 11px/1.45 var(--font-ui); }
.panel-number { color: var(--sgm-dark); font: 700 25px/1 var(--font-head); white-space: nowrap; }
.chart-legend { display: flex; gap: 12px; color: var(--text-meta); font: 10px/1.3 var(--font-ui); }
.chart-legend span::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 2px; }
.legend-booked::before { background: var(--sgm-medium); }
.legend-completed::before { background: var(--sgm-dark); }
.column-chart { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end; gap: clamp(8px, 1.4vw, 18px); height: 230px; padding-top: 26px; }
.column-chart-group { display: grid; grid-template-rows: 1fr auto auto; align-items: end; gap: 4px; height: 100%; text-align: center; font-family: var(--font-ui); }
.column-chart-bars { display: flex; align-items: end; justify-content: center; gap: 4px; height: 100%; border-bottom: 1px solid var(--border); }
.chart-bar { width: min(18px, 35%); min-height: 4px; border-radius: 5px 5px 0 0; }
.chart-bar.booked { background: var(--sgm-medium); }
.chart-bar.completed { background: var(--sgm-dark); }
.column-chart-group > strong { font-size: 11px; }
.column-chart-group > small { color: var(--text-meta); font-size: 9px; }
.funnel-row { display: grid; gap: 6px; margin-top: 18px; }
.funnel-row > div:first-child { display: flex; justify-content: space-between; gap: 12px; font: 12px/1.4 var(--font-ui); }
.progress-track { height: 7px; border-radius: 20px; background: var(--bg-neutral); overflow: hidden; }
.progress-track span { display: block; height: 100%; min-width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--sgm-primary), var(--sgm-dark)); }
.progress-track.large { height: 11px; margin-top: 16px; }
.procedure-numbers { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 20px; }
.procedure-numbers > div { padding: 14px; border-radius: 9px; background: var(--bg-neutral); }
.procedure-numbers small { display: block; color: var(--text-meta); font: 11px/1.3 var(--font-ui); }
.procedure-numbers strong { display: block; margin-top: 5px; font: 700 25px/1 var(--font-head); }
.compact-panel h3 { margin-bottom: 14px; }
.compact-stat { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font: 12px/1.4 var(--font-ui); }
.compact-stat:last-child { border-bottom: 0; }
.compact-stat strong { font-size: 15px; }
.compact-stat.warning strong { color: var(--warn); }
.hero-stat { color: var(--sgm-dark); font: 700 46px/1 var(--font-head); }
.status-stack { display: grid; gap: 7px; margin-top: 14px; color: var(--text-meta); font: 11px/1.4 var(--font-ui); }
.status-stack span { display: flex; justify-content: space-between; gap: 8px; }
.catalog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.catalog-grid > div { display: grid; gap: 3px; padding: 11px; border-radius: 8px; background: var(--bg-neutral); font-family: var(--font-ui); }
.catalog-grid span { color: var(--text-meta); font-size: 10px; }
.catalog-grid strong { font-size: 21px; }
.panel-footnote { margin: 13px 0 0; color: var(--text-meta); font: 11px/1.5 var(--font-ui); }
.table-panel { padding: 0; overflow: hidden; }
.table-panel > h3 { padding: 18px 20px 4px; }
.dashboard-table-wrap { border: 0; border-radius: 0; }
.dashboard-table { min-width: 720px; }
.capacity-cell { min-width: 190px; }
.capacity-cell > div:first-child { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font: 11px/1.3 var(--font-ui); }
.capacity-cell span { color: var(--text-meta); }
.finance-dashboard-section { padding: clamp(20px, 2vw, 30px); margin-inline: calc(clamp(8px, 1vw, 14px) * -1); border-radius: 18px; background: #fffaf0; border: 1px solid var(--sgm-medium); }
.revenue-chart { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); align-items: end; gap: 14px; height: 230px; padding-top: 24px; }
.revenue-chart > div { display: grid; grid-template-rows: 1fr auto auto; gap: 4px; height: 100%; align-items: end; text-align: center; font-family: var(--font-ui); }
.revenue-bar { display: block; width: min(42px, 65%); min-height: 4px; margin: 0 auto; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--sgm-dark), var(--sgm-primary)); }
.revenue-chart strong { font-size: 11px; }
.revenue-chart small { color: var(--text-meta); font-size: 9px; }
.finance-composition { display: grid; justify-items: center; }
.finance-composition .panel-head { width: 100%; }
.finance-ring { display: grid; place-items: center; width: 170px; height: 170px; margin: 18px auto; border-radius: 50%; background: conic-gradient(var(--sgm-dark) 0 var(--partner), var(--sgm-medium) var(--partner) calc(var(--partner) + var(--cost)), #e8f5e9 calc(var(--partner) + var(--cost)) 100%); position: relative; }
.finance-ring::after { content: ''; position: absolute; inset: 28px; border-radius: 50%; background: var(--bg); }
.finance-ring > span { position: relative; z-index: 1; display: grid; text-align: center; }
.finance-ring strong { font: 700 25px/1 var(--font-head); }
.finance-ring small { margin-top: 5px; color: var(--text-meta); font: 10px/1.2 var(--font-ui); }
.finance-legend { display: grid; gap: 7px; width: 100%; font: 11px/1.4 var(--font-ui); }
.finance-legend span { display: flex; justify-content: space-between; gap: 10px; }
.finance-legend span::before { content: ''; width: 8px; height: 8px; margin-top: 3px; border-radius: 2px; }
.finance-legend .partner::before { background: var(--sgm-dark); }
.finance-legend .direct::before { background: var(--sgm-medium); }
.finance-legend .sgm::before { background: #a5d6a7; }
.finance-legend strong { margin-left: auto; }
.empty-dashboard { text-align: center; padding: 50px; }
.doctor-schedule-editor { padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-neutral); }
.doctor-schedule-row { display: grid; grid-template-columns: minmax(210px,1.4fr) minmax(130px,.8fr) 120px 120px auto; gap: 10px; align-items: end; padding: 11px 0; border-top: 1px solid var(--border); }
.doctor-schedule-row label { font-size: 11px; }

@media (max-width: 1280px) {
    .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid-wide { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
    .dashboard-grid-equal { grid-template-columns: 1fr; }
    .dashboard-head { align-items: stretch; }
    .dashboard-month-filter { width: 100%; }
    .dashboard-table-wrap { overflow-x: auto; }
    .doctor-schedule-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .dashboard-kpis { grid-template-columns: 1fr; }
    .dashboard-month-filter > div { flex-direction: column; }
    .column-chart, .revenue-chart { gap: 5px; height: 190px; }
    .chart-legend { display: none; }
    .dashboard-head, .dashboard-panel, .metric-card { border-radius: 10px; }
    .finance-dashboard-section { padding: 14px; }
    .doctor-schedule-row { grid-template-columns: 1fr; }
}
