/* ================================================================
   PRIME SMS — RESET, TYPOGRAPHY, APP SHELL
================================================================ */

/* ── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    color: var(--tx-2);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Numbers-heavy product: digits must never shift width between
       renders, so tabular figures are the global default rather than
       an opt-in class on a handful of table cells. */
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'cv11', 'ss01';
}

a { text-decoration: none; color: inherit; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Every interactive element gets the same ring — never remove it
   without replacing it. */
:focus-visible { outline: none; box-shadow: var(--ring); }

/* ── TYPOGRAPHY ─────────────────────────────────────────────
   Headings run on the display face at heavy weights. The jump from
   400 body to 700/800 headings is what makes the hierarchy read at a
   glance — a uniform 600 everywhere is what made this look generic. */
h1, h2, h3, h4 {
    font-family: var(--font-display);
    color: var(--tx-1);
    line-height: var(--lh-tight);
    font-weight: var(--fw-bold);
}
h1 { font-size: var(--fs-h1); font-weight: var(--fw-black); letter-spacing: var(--ls-h1); }
h2 { font-size: var(--fs-h2); letter-spacing: var(--ls-h2); }
h3 { font-size: var(--fs-h3); }

/* Small uppercase label — section dividers, stat captions. */
.label-caps {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--tx-3);
    text-transform: uppercase;
    letter-spacing: var(--ls-caps);
}

.text-muted { color: var(--tx-3); }
.text-mono  { font-family: var(--font-mono); font-size: var(--fs-sm); }
.num        { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ================================================================
   APP LAYOUT
================================================================ */
.app { display: flex; min-height: 100vh; }

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: var(--z-sidebar);
    transition: transform var(--dur) var(--ease);
}

/* Brand */
.sb-logo {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-4);
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}
.sb-logo-icon {
    width: 34px; height: 34px;
    background: var(--primary);
    border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; color: #fff;
    flex-shrink: 0;
}
.sb-logo-text {
    font-family: var(--font-display);
    font-size: 1.0625rem;
    font-weight: var(--fw-black);
    color: var(--tx-1);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.sb-logo-sub {
    font-size: 0.6875rem;
    font-weight: var(--fw-bold);
    color: var(--tx-3);
    letter-spacing: var(--ls-caps);
    text-transform: uppercase;
}

/* Nav */
.sb-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3) var(--sp-2) var(--sp-4);
    scrollbar-width: thin;
}
.sb-nav::-webkit-scrollbar { width: 4px; }
.sb-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-full); }

.sb-section {
    padding: var(--sp-5) var(--sp-3) var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--tx-3);
    text-transform: uppercase;
    letter-spacing: var(--ls-caps);
    user-select: none;
}
.sb-nav > .sb-section:first-child { padding-top: var(--sp-2); }

/* Shared shape for every clickable row in the sidebar. */
.sb-item, .sb-group-toggle, .sb-subitem {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    height: 36px;
    padding: 0 var(--sp-3);
    margin-bottom: 1px;
    border-radius: var(--r-md);
    font-size: var(--fs-body);
    font-weight: var(--fw-medium);
    color: var(--tx-2);
    cursor: pointer;
    user-select: none;
    transition: background var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease);
}
.sb-item:hover, .sb-group-toggle:hover, .sb-subitem:hover {
    background: var(--surface-hover);
    color: var(--tx-1);
}
.sb-item i, .sb-group-toggle .sb-lead, .sb-subitem i {
    width: 18px;
    text-align: center;
    font-size: 14px;
    color: var(--tx-2);
    flex-shrink: 0;
    transition: color var(--dur-fast) var(--ease);
}
.sb-item:hover i, .sb-group-toggle:hover .sb-lead { color: var(--tx-2); }

/* Selected state — solid brand fill. A tint alone was too quiet to
   locate at a glance in a sidebar this dense. */
.sb-item.active, .sb-subitem.active {
    background: var(--primary);
    color: #fff;
    font-weight: var(--fw-semibold);
}
.sb-item.active i, .sb-subitem.active i { color: #fff; }
.sb-item.active:hover, .sb-subitem.active:hover {
    background: var(--primary-hover);
    color: #fff;
}

.sb-item-arrow, .sb-group-caret {
    margin-left: auto;
    font-size: 10px;
    color: var(--tx-4);
}
.sb-item i.sb-item-arrow { width: auto; }

/* Collapsible group */
.sb-group { margin-bottom: 2px; }
.sb-group.has-active > .sb-group-toggle { color: var(--tx-1); font-weight: var(--fw-semibold); }
.sb-group.has-active > .sb-group-toggle .sb-lead { color: var(--primary); }
.sb-group-caret { transition: transform var(--dur) var(--ease); }
.sb-group.open .sb-group-caret { transform: rotate(90deg); }

.sb-submenu {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows var(--dur-slow) var(--ease);
}
.sb-submenu > div { overflow: hidden; }
.sb-group.open .sb-submenu { grid-template-rows: 1fr; }

.sb-subitem {
    padding-left: calc(var(--sp-3) + 18px + var(--sp-3));
    font-size: var(--fs-sm);
}
.sb-subitem i { font-size: 12px; }

/* Footer */
.sb-footer {
    flex-shrink: 0;
    padding: var(--sp-3);
    border-top: 1px solid var(--border-subtle);
}
.sb-user {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2);
    border-radius: var(--r-md);
}
.sb-user-name {
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
    color: var(--tx-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.sb-user-role { font-size: var(--fs-xs); color: var(--tx-3); }

/* ── AVATAR ─────────────────────────────────────────────────── */
.avatar {
    width: 34px; height: 34px;
    border-radius: var(--r-full);
    background: var(--brand-100);
    color: var(--primary-text);
    display: flex; align-items: center; justify-content: center;
    font-size: var(--fs-sm);
    font-weight: var(--fw-bold);
    flex-shrink: 0;
    text-transform: uppercase;
}
.avatar-sm { width: 30px; height: 30px; font-size: var(--fs-xs); }

/* ── MAIN ───────────────────────────────────────────────────── */
.main-wrap {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* ── TOPBAR ─────────────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    padding: 0 var(--sp-8);
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    flex-shrink: 0;
}
.topbar-left  { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-4); }

.topbar-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: var(--fw-bold);
    letter-spacing: -0.01em;
    color: var(--tx-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hamburger {
    display: none;
    align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: transparent;
    cursor: pointer;
    color: var(--tx-2);
    font-size: 14px;
    transition: background var(--dur-fast) var(--ease);
}
.hamburger:hover { background: var(--surface-hover); }

/* Credit pill — the one number a customer checks constantly, so it
   reads as a unit rather than a stacked label. */
.credit-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-1) var(--sp-3);
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: var(--r-full);
    white-space: nowrap;
}
.credit-pill i { font-size: 11px; color: var(--success); }
.credit-pill .credits-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--success-text);
    opacity: 0.8;
}
.credit-pill .credits-value {
    font-size: var(--fs-body);
    font-weight: var(--fw-bold);
    color: var(--success-text);
}

.topbar-role {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    color: var(--tx-2);
    padding: var(--sp-1) var(--sp-3);
    background: var(--slate-100);
    border-radius: var(--r-full);
    white-space: nowrap;
}
.topbar-role i { font-size: 11px; color: var(--tx-3); }

.topbar-divider { width: 1px; height: 26px; background: var(--border); }

.topbar-signout {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    background: transparent;
    color: var(--tx-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: var(--fs-sm);
    font-weight: var(--fw-medium);
    cursor: pointer;
    transition: background var(--dur-fast) var(--ease),
                color var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease);
}
.topbar-signout:hover {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: var(--danger-border);
}

/* ── CONTENT ────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    padding: var(--sp-6);
    max-width: var(--content-max);
    width: 100%;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
    flex-wrap: wrap;
}
.page-header h1 { margin-bottom: 2px; }
.page-header p  { font-size: var(--fs-sm); color: var(--tx-3); max-width: 70ch; }

.section-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--tx-3);
    text-transform: uppercase;
    letter-spacing: var(--ls-caps);
    margin-bottom: var(--sp-3);
}

/* ── MOBILE OVERLAY ─────────────────────────────────────────── */
.sb-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: var(--z-overlay);
}
.sb-overlay.show { display: block; }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .main-content { padding: var(--sp-6); }
    .topbar { padding: 0 var(--sp-6); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--sh-xl); }
    .main-wrap { margin-left: 0; }
    .hamburger { display: flex; }
    .main-content { padding: var(--sp-4); }
    .topbar { padding: 0 var(--sp-4); gap: var(--sp-2); }
    .topbar-right { gap: var(--sp-2); }
    .topbar-divider, .topbar-role { display: none; }
    .page-header { flex-direction: column; align-items: stretch; }
}
@media (max-width: 520px) {
    .credit-pill .credits-label { display: none; }
    .topbar-signout span { display: none; }
    .topbar-signout { padding: var(--sp-2); }
}
