/* ── Brand palette ──────────────────────────────────────── */
/*
  Active theme: Deep Slate
  --navbar-bg: #1e293b;
  --navbar-text: #f1f5f9;
  --navbar-hover: #94a3b8;

  Backup themes (swap the variables above to switch):

  Dark Teal (medical/healthcare feel)
  --navbar-bg: #134e4a;
  --navbar-text: #ccfbf1;
  --navbar-hover: #5eead4;

  Indigo (modern SaaS, Stripe-like)
  --navbar-bg: #312e81;
  --navbar-text: #e0e7ff;
  --navbar-hover: #a5b4fc;

  Charcoal (minimal, content-first)
  --navbar-bg: #1f2937;
  --navbar-text: #f9fafb;
  --navbar-hover: #9ca3af;
*/
:root {
    --navbar-bg:    #1e293b;
    --navbar-text:  #f1f5f9;
    --navbar-hover: #94a3b8;
}

/* ── Navbar ──────────────────────────────────────────────── */
.navbar.navbar-app {
    background-color: var(--navbar-bg) !important;
}
.navbar.navbar-app .navbar-brand,
.navbar.navbar-app .nav-link {
    color: var(--navbar-text) !important;
    opacity: 1;
}
.navbar.navbar-app .nav-link:hover,
.navbar.navbar-app .nav-link:focus {
    color: var(--navbar-hover) !important;
}
.navbar.navbar-app .nav-link.active {
    color: #ffffff !important;
    font-weight: 600;
}
.navbar.navbar-app .navbar-toggler {
    border-color: rgba(241,245,249,.3);
}

/* ── Sidebar layout ──────────────────────────────────────── */
:root {
    --sidebar-width:           220px;
    --sidebar-collapsed-width: 62px;
    --topbar-height:           52px;
}

body {
    background-color: #f1f5f9;
    font-size: 0.9rem;
    margin: 0;
}

/* Desktop: sidebar fixed, main content offset */
@media (min-width: 992px) {
    .app-main {
        margin-left: var(--sidebar-width);
        transition: margin-left .2s ease;
    }
    .sidebar-collapsed .app-main {
        margin-left: var(--sidebar-collapsed-width);
    }
}

/* Mobile: no offset, sidebar is off-canvas */
@media (max-width: 991.98px) {
    .app-main { margin-left: 0 !important; }
}

/* ── Sidebar shell ───────────────────────────────────────── */
.app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--navbar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 1040;
    transition: width .2s ease;
}

.sidebar-collapsed .app-sidebar {
    width: var(--sidebar-collapsed-width);
}

/* Off-canvas on mobile */
@media (max-width: 991.98px) {
    .app-sidebar {
        left: calc(-1 * var(--sidebar-width));
        width: var(--sidebar-width) !important;
        transition: left .25s ease;
    }
    body.sidebar-mobile-open .app-sidebar { left: 0; }
}

/* Overlay behind sidebar on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1039;
}
body.sidebar-mobile-open .sidebar-overlay { display: block; }

/* ── Sidebar header / brand ──────────────────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    padding: 10px 8px 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    overflow: hidden;
}

.sidebar-collapse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px; height: 28px;
    flex-shrink: 0;
    border-radius: 6px;
    background: rgba(255,255,255,.08);
    border: none;
    color: rgba(241,245,249,.7);
    cursor: pointer;
    transition: background .15s, color .15s;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.15); color: #f1f5f9; }

.sidebar-brand-icon {
    width: 36px; height: 36px;
    background: rgba(255,255,255,.15);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px; letter-spacing: .05em;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand-text {
    color: #f1f5f9;
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.sidebar-brand-subtitle {
    font-size: 11px;
    color: var(--navbar-hover);
    white-space: nowrap;
    display: block;
    margin-top: 2px;
}

/* ── Nav items ───────────────────────────────────────────── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

.sidebar-section-label {
    padding: 14px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--navbar-hover);
    white-space: nowrap;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    margin: 1px 8px;
    border-radius: 7px;
    color: rgba(241,245,249,.7);
    text-decoration: none;
    transition: background .15s, color .15s;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-item:hover  { background: rgba(255,255,255,.07); color: #f1f5f9; }
.sidebar-item.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }

.sidebar-item .si-icon {
    width: 18px; text-align: center;
    flex-shrink: 0; font-size: 15px;
}

.sidebar-item .si-label { font-size: 13.5px; }

/* ── Collapsed state: hide all text ─────────────────────── */
.sidebar-collapsed .sidebar-brand-text,
.sidebar-collapsed .sidebar-brand-subtitle,
.sidebar-collapsed .sidebar-section-label,
.sidebar-collapsed .si-label {
    opacity: 0; width: 0; overflow: hidden; display: inline-block;
}

.sidebar-collapsed .sf-label {
    display: none;
}

.sidebar-collapsed .sidebar-item {
    justify-content: center;
    gap: 0;
    margin: 1px 4px;
}

.sidebar-collapsed .sidebar-header { justify-content: center; gap: 0; }
.sidebar-collapsed .sidebar-brand-link { flex: 0; min-width: 0; }
.sidebar-collapsed .sidebar-collapse-btn { margin: 0; }

/* ── Sidebar footer ──────────────────────────────────────── */
.sidebar-footer {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}

.sf-user-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 7px;
    color: rgba(241,245,249,.75);
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    transition: background .15s;
}

.sf-user-btn:hover { background: rgba(255,255,255,.07); color: #f1f5f9; }

.sidebar-collapsed .sf-user-btn { justify-content: center; }

.sf-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff;
    flex-shrink: 0;
}

.sf-name  { font-size: 13px; font-weight: 600; color: #f1f5f9; line-height: 1.3; }
.sf-email { font-size: 11px; color: var(--navbar-hover); }

.sf-toggle-icon { transition: transform .2s; flex-shrink: 0; font-size: 12px; }
.sidebar-collapsed .sf-toggle-icon { transform: rotate(180deg); }

/* ── Mobile top bar ──────────────────────────────────────── */
.app-topbar-mobile {
    position: sticky;
    top: 0;
    z-index: 1038;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: var(--topbar-height);
    background: var(--navbar-bg);
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.topbar-hamburger {
    background: none;
    border: none;
    color: #f1f5f9;
    font-size: 18px;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1;
}
.topbar-hamburger:hover { background: rgba(255,255,255,.1); }

.topbar-brand {
    color: #f1f5f9;
    font-weight: 700;
    font-size: 16px;
    flex: 1;
    text-decoration: none;
}

/* Impersonation banner */
.impersonation-banner {
    background: #fef3c7;
    border-bottom: 2px solid #f59e0b;
    padding: 7px 24px;
    font-size: 13px;
    color: #92400e;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Main content area ───────────────────────────────────── */
.app-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-content {
    padding: 24px;
    flex: 1;
}

@media (max-width: 767.98px) {
    .app-content { padding: 16px; }
}

/* ── Flash alerts (floating bottom-left) ────────────────── */
.floating-alert {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    z-index: 9999;
    width: 320px;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
    border-radius: 0.5rem;
}

/* ── Tables ─────────────────────────────────────────────── */
.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
}

/* ── Patient detail tabs ─────────────────────────────────── */
.patient-tab-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 240px;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 2rem;
}

/* ── Custom grid calendar ────────────────────────────────── */
.cal-wrapper {
    overflow-x: auto;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #fff;
}

/* Both header and body rows share the same grid columns */
.cal-grid-row {
    display: grid;
    grid-template-columns: 52px repeat(var(--cal-cols, 1), minmax(130px, 1fr));
}

/* Sticky header */
.cal-header-row {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #fff;
    border-bottom: 2px solid #dee2e6;
}
.cal-time-cell {
    border-right: 1px solid #dee2e6;
}
.cal-header-cell {
    padding: 8px 6px 6px;
    font-weight: 600;
    font-size: .82rem;
    text-align: center;
    border-left: 1px solid #dee2e6;
}

/* Time label column */
.cal-time-col {
    border-right: 1px solid #dee2e6;
}
/* Each label div = 1 slot = 18px (15 min) */
.cal-slot-label {
    height: 18px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding-right: 6px;
}
/* :00 — full "H:00" label, lifted slightly above the line */
.cal-lbl-hour {
    font-size: .68rem;
    font-weight: 600;
    color: #6c757d;
    position: relative;
    top: -7px;
    white-space: nowrap;
}
/* :30 — half-hour, a bit subtler */
.cal-lbl-half {
    font-size: .62rem;
    color: #9ca3af;
    position: relative;
    top: -7px;
}
/* :15 / :45 — quarter, smallest */
.cal-lbl-quarter {
    font-size: .58rem;
    color: #c5cdd6;
    position: relative;
    top: -7px;
}

/* Cabinet columns */
.cal-cabinet-col {
    position: relative;
    border-left: 1px solid #dee2e6;
    cursor: crosshair;
}
.cal-cabinet-col--over {
    background: rgba(55, 136, 216, .07);
}

/* Background slot grid lines — 15-min slots at 18px each */
.cal-slot {
    height: 18px;
    border-bottom: 1px solid #e9ecef;   /* :00 line (solid) */
    box-sizing: border-box;
}
.cal-slot-half {
    border-bottom: 1px solid #f0f2f5;   /* :30 line (lighter solid) */
}
.cal-slot-quarter {
    border-bottom: 1px dashed #f5f5f5;  /* :15 / :45 (dashed, barely visible) */
}

/* Appointment blocks */
.cal-event {
    position: absolute;
    box-sizing: border-box;
    border-radius: 4px;
    padding: 3px 5px;
    font-size: .72rem;
    line-height: 1.25;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,.15);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,.35);
    z-index: 5;
    transition: filter .1s, box-shadow .1s;
    user-select: none;
}
.cal-event:hover {
    filter: brightness(.88);
    z-index: 6;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.cal-event--dragging {
    opacity: .45;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.cal-ev-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cal-ev-sub,
.cal-ev-time {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: .88;
    font-size: .65rem;
}

/* Resize handles (top / bottom edge of appointment) */
.cal-ev-resize-handle-top,
.cal-ev-resize-handle-bot {
    position: absolute;
    left: 0;
    right: 0;
    height: 6px;
    cursor: ns-resize;
    z-index: 10;
    border-radius: 4px;
}
.cal-ev-resize-handle-top { top: 0; }
.cal-ev-resize-handle-bot { bottom: 0; }
.cal-ev-resize-handle-top:hover,
.cal-ev-resize-handle-bot:hover {
    background: rgba(255,255,255,.3);
}
.cal-event--resizing {
    opacity: .75;
    z-index: 10;
    cursor: ns-resize !important;
}

/* ── Mobile calendar: single-column view ─────────────────── */
@media (max-width: 767.98px) {
    /* Override the N-column grid to time + 1 visible column */
    .cal-grid-row {
        grid-template-columns: 40px 1fr !important;
    }
    /* Hide all data columns; JS adds .cal-col-active to the selected one */
    .cal-header-cell,
    .cal-cabinet-col {
        display: none;
    }
    .cal-header-cell.cal-col-active,
    .cal-cabinet-col.cal-col-active {
        display: block;
    }
    /* Shrink time label column slightly */
    .cal-slot-label {
        padding-right: 4px;
    }
    .cal-lbl-hour   { font-size: .6rem; }
    .cal-lbl-half   { font-size: .56rem; }
    .cal-lbl-quarter { font-size: .52rem; }
    /* View-toggle labels: icon-only on small screens */
    .cal-view-label { display: none; }
}

/* Current-time red line */
.cal-now-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: #ef4444;
    pointer-events: none;
    z-index: 8;
}
.cal-now-line::before {
    content: '';
    position: absolute;
    left: -1px;
    top: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ef4444;
}

/* ── Odontogram chart ────────────────────────────────────── */
.odo-chart { overflow-x: auto; padding-bottom: 4px; }

.odo-row {
    display: flex;
    align-items: flex-end;
    min-width: 640px;
    margin-bottom: 1px;
}
.odo-row--dec { align-items: flex-end; }

.odo-half { display: flex; flex: 1; gap: 2px; }
.odo-half--right { justify-content: flex-end; }
.odo-half--left  { justify-content: flex-start; }

.odo-midline {
    width: 10px;
    flex-shrink: 0;
    background: repeating-linear-gradient(to bottom,#adb5bd 0,#adb5bd 4px,transparent 4px,transparent 8px);
    margin: 0 2px;
    border-radius: 2px;
    align-self: stretch;
}
.odo-midline--dec { opacity: .5; }

.odo-jaw-sep {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    margin: 3px 0;
    border-top: 2px solid #dee2e6;
    border-bottom: 2px solid #dee2e6;
    min-width: 640px;
}
.odo-jaw-label {
    font-size: .62rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: #adb5bd;
    padding: 0 4px;
}

/* ── Tooth button ── */
.odo-tooth {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    width: 40px;
    padding: 2px 1px;
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: transform .12s, filter .12s;
}
.odo-tooth:hover  { transform: scale(1.12); filter: drop-shadow(0 2px 4px rgba(0,0,0,.25)); z-index: 2; }
.odo-tooth--active { transform: scale(1.14); filter: drop-shadow(0 0 4px #0d6efd) drop-shadow(0 2px 6px rgba(13,110,253,.4)); z-index: 3; }
.odo-tooth--lower { flex-direction: column-reverse; }
.odo-tooth--dec   { width: 30px; }

/* Tooth number label */
.odo-tooth__num {
    font-size: .58rem;
    font-weight: 700;
    color: #6c757d;
    line-height: 1;
}
.odo-tooth--active .odo-tooth__num { color: #0d6efd; }

/* SVG tooth graphic */
.odo-svg {
    width: 36px;
    height: 68px;
    display: block;
    flex-shrink: 0;
}
.odo-tooth--dec .odo-svg { width: 26px; height: 50px; }

/* Endodontic dot */
.odo-tooth__endo {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.endo-none              { background: transparent; }
.endo-treated           { background: #198754; }
.endo-needs_treatment   { background: #fd7e14; }
.endo-periapical_lesion { background: #dc3545; }
.odo-tooth--dec .odo-tooth__endo { width: 5px; height: 5px; }

/* Crown fill per status (CSS var inherited into SVG shadow tree) */
.odo-tooth                                      { --crown-fill: #f2f0ec; }
.odo-tooth[data-status="caries"]               { --crown-fill: #e07070; }
.odo-tooth[data-status="filled"]               { --crown-fill: #7aabdf; }
.odo-tooth[data-status="crown"]                { --crown-fill: #e8c84a; }
.odo-tooth[data-status="missing"]              { --crown-fill: transparent; opacity: .4; }
.odo-tooth[data-status="implant"]              { --crown-fill: #6ecfe8; }
.odo-tooth[data-status="bridge_abutment"]      { --crown-fill: #e8a84a; }
.odo-tooth[data-status="extraction_indicated"] { --crown-fill: #b07de0; }
.odo-tooth[data-status="veneer"]               { --crown-fill: #e87ac8; }
.odo-tooth[data-status="fracture"]             { --crown-fill: #e89060; }

/* Deciduous spacer */
.odo-dec-spacer {
    width: calc(3 * 40px + 3 * 2px);
    flex-shrink: 0;
}

/* Legend */
.odo-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.odo-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .7rem;
    color: #495057;
}
.odo-legend-item::before {
    content: '';
    width: 11px;
    height: 14px;
    border-radius: 2px 2px 4px 4px;
    flex-shrink: 0;
}
.odo-legend-item[data-status="healthy"]::before              { background:#f2f0ec; border:1px solid #ced4da; }
.odo-legend-item[data-status="caries"]::before               { background:#e07070; }
.odo-legend-item[data-status="filled"]::before               { background:#7aabdf; }
.odo-legend-item[data-status="crown"]::before                { background:#e8c84a; }
.odo-legend-item[data-status="missing"]::before              { background:#dee2e6; border:1px dashed #adb5bd; }
.odo-legend-item[data-status="implant"]::before              { background:#6ecfe8; }
.odo-legend-item[data-status="bridge_abutment"]::before      { background:#e8a84a; }
.odo-legend-item[data-status="extraction_indicated"]::before { background:#b07de0; }
.odo-legend-item[data-status="veneer"]::before               { background:#e87ac8; }
.odo-legend-item[data-status="fracture"]::before             { background:#e89060; }

/* ── Periodontal chart ─────────────────────────────────────── */
.perio-scroll-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.perio-arch-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #6c757d;
    margin-bottom: 4px;
}

.perio-arch-sep {
    height: 12px;
}

.perio-table {
    border-collapse: collapse;
    font-size: .72rem;
    white-space: nowrap;
    min-width: 100%;
}

.perio-col-label { width: 72px; min-width: 72px; }
.perio-col-mid   { width: 10px; background: #e9ecef; }

.perio-label {
    font-size: .65rem;
    color: #6c757d;
    padding: 2px 4px;
    text-align: right;
    vertical-align: middle;
    line-height: 1.2;
    border-right: 1px solid #dee2e6;
    min-width: 72px;
}

.perio-cell {
    border: 1px solid #e9ecef;
    text-align: center;
    vertical-align: middle;
    padding: 0;
    min-width: 16px;
    height: 20px;
    cursor: default;
}

.perio-cell--toggle {
    cursor: pointer;
    background: #f8f9fa;
    user-select: none;
}
.perio-cell--toggle:hover { background: #e9ecef; }

.perio-on--bleed  { background: #e07070 !important; }
.perio-on--plaque { background: #7aabdf !important; }

.perio-cell--num   { padding: 0; }
.perio-cell--single { cursor: pointer; }
.perio-cell--implant { cursor: pointer; font-size: .85rem; line-height: 1; }

.perio-input {
    width: 100%;
    border: 0;
    text-align: center;
    background: transparent;
    font-size: .72rem;
    color: inherit;
    padding: 0;
    height: 20px;
    outline: none;
    -moz-appearance: textfield;
}
.perio-input::-webkit-outer-spin-button,
.perio-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.perio-input:focus { background: #fff3cd; }

.perio-pd--deep { color: #c0392b; font-weight: 600; }

.perio-row--teeth td { background: #e9ecef; }
.perio-tooth-num {
    font-size: .68rem;
    font-weight: 600;
    text-align: center;
    padding: 2px 0;
    border: 1px solid #dee2e6;
}

.perio-row--pd .perio-cell--num { background: #fafafa; }

.perio-mid { background: #e9ecef; width: 10px; }

/* group separation between teeth — every 3rd col inside a half */
.perio-table col:nth-child(3n+2) { border-right: 1px solid #adb5bd; }

.perio-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 2px;
    vertical-align: middle;
}
.perio-dot--bleed  { background: #e07070; }
.perio-dot--plaque { background: #7aabdf; }

.perio-save-status {
    position: fixed;
    bottom: 16px;
    right: 16px;
    font-size: .75rem;
    padding: 4px 10px;
    border-radius: 4px;
    pointer-events: none;
    transition: opacity .3s;
}
.perio-save-status--saving { background: #fff3cd; color: #856404; }
.perio-save-status--saved  { background: #d1e7dd; color: #0f5132; }
.perio-save-status--error  { background: #f8d7da; color: #842029; }

/* Visualization rows — image + canvas overlay */
.perio-row--viz-img td { padding: 0 !important; }
.perio-viz-img-cell    { padding: 0 !important; }
.pvz-label             { font-size: .6rem !important; color: #94a3b8 !important; vertical-align: middle !important; }
.perio-viz-imgwrap {
    position: relative;
    width: 100%;
    height: 120px;
    overflow: hidden;
    background: #fff;
}
.perio-viz-img {
    display: block;
    width: 100%;
    height: 120px;
    /* stretch image to fill — preserves tooth column alignment with table */
}
.perio-viz-img--flip { transform: scaleY(-1); }
.perio-viz-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 120px;
    pointer-events: none;
}
