:root {
    --bg: #f4f7f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-muted: #475569;
    --primary: #0f766e;
    --primary-hover: #0d5e58;
    --primary-soft: #ccfbf1;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Tahoma", "Noto Sans Arabic", "Cairo", sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

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

a:hover {
    text-decoration: underline;
}

.ltr {
    direction: ltr;
    unicode-bidi: isolate;
    display: inline-block;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

/* App Shell */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 16px;
}

.brand-badge {
    background: var(--primary);
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 700;
}

.topbar-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 14px;
    color: var(--text-muted);
}

.user-pill {
    background: var(--surface-muted);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 999px;
    color: var(--text);
    font-weight: 500;
}

.workspace {
    display: flex;
    flex: 1;
}

.sidebar {
    width: 230px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 20px 14px;
    flex-shrink: 0;
}

.nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--text);
    font-weight: 500;
    transition: background 0.15s ease;
}

.nav-link:hover {
    background: var(--surface-muted);
    text-decoration: none;
}

.nav-link.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

.nav-link.disabled {
    color: #94a3b8;
    cursor: not-allowed;
    pointer-events: none;
}

.soon-badge {
    font-size: 11px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: #64748b;
    padding: 1px 7px;
    border-radius: 999px;
}

.content {
    flex: 1;
    padding: 24px 28px;
    max-width: 1280px;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
}

.page-subtitle {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
}

.kpi-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}

.kpi-value.warn {
    color: var(--warn);
}

.kpi-value.primary {
    color: var(--primary);
}

/* Cards & Tables */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-muted);
}

.card-title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.card-body {
    padding: 18px;
}

.two-col {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
    gap: 18px;
}

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

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

th, td {
    text-align: right;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #f8fafc;
}

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    color: var(--text);
}

.badge-primary {
    background: var(--primary-soft);
    border-color: #99f6e4;
    color: var(--primary);
}

.badge-info {
    background: var(--info-soft);
    border-color: #bae6fd;
    color: var(--info);
}

.badge-warn {
    background: var(--warn-soft);
    border-color: #fde68a;
    color: var(--warn);
}

.badge-danger {
    background: var(--danger-soft);
    border-color: #fecaca;
    color: var(--danger);
}

/* Search Bar & Forms (Auth + Search only) */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.input {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    padding: 9px 13px;
    font-size: 14px;
    font-family: inherit;
    min-width: 280px;
    flex: 1;
}

.input:focus {
    outline: 2px solid var(--primary-soft);
    border-color: var(--primary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    background: var(--primary);
    color: #ffffff;
}

.btn:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.btn-outline {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

.btn-outline:hover {
    background: var(--surface-muted);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 13px;
}

/* Patient Detail Meta Grid */
.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.meta-item-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.meta-item-value {
    font-size: 15px;
    font-weight: 600;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-danger {
    background: var(--danger-soft);
    border: 1px solid #fecaca;
    color: var(--danger);
}

.alert-success {
    background: var(--primary-soft);
    border: 1px solid #99f6e4;
    color: var(--primary);
}

.alert-warn {
    background: var(--warn-soft);
    border: 1px solid #fde68a;
    color: var(--warn);
}

/* Pagination */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
    flex-wrap: wrap;
    gap: 10px;
    font-size: 13px;
}

.pagination-links {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.page-link {
    padding: 5px 11px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.page-link.active {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.page-link.disabled {
    color: #94a3b8;
    background: var(--surface-muted);
}

/* Auth Center Shell */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
    padding: 28px;
}

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
}

.form-group .input {
    width: 100%;
    min-width: 0;
}

.tenant-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.tenant-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    background: var(--surface-muted);
}

.tenant-option:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    text-decoration: none;
}

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

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
}

.chip:hover {
    background: var(--surface-muted);
    text-decoration: none;
}

.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.tabs {
    display: flex;
    gap: 8px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 18px;
}

.tab-link {
    padding: 10px 18px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-link:hover {
    color: var(--text);
    text-decoration: none;
}

.tab-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
    align-items: flex-end;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 150px;
}

.filter-field label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.select, .input-sm {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
}

@media (max-width: 900px) {
    .workspace {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        border-left: none;
        border-bottom: 1px solid var(--border);
    }

    .two-col {
        grid-template-columns: 1fr;
    }
}

