/* ===============================================================
   SAHE SMS — Design System Enhancements
   Layered on top of design-system.css. This file ONLY adds and
   extends; it never renames or removes existing classes.

   Sections:
     1. Responsive 12-column grid (sm / md / lg + mobile stacking)
     2. Bootstrap-flavoured modal styling (paired with js/modal.js)
     3. Production polish (typography rhythm, shadows, micro-interactions)
     4. Accessibility (focus rings, darker muted/warning text)
     5. Comprehensive dark-mode overrides
   =============================================================== */

/* ===============================================================
   1. RESPONSIVE 12-COLUMN GRID
   The base file only defined a handful of fixed-width col-md-*.
   Generate the full 12-col set for every breakpoint templates use,
   and stack everything on small screens.
   =============================================================== */

/* Base (all widths) — full 1..12 set. These act as the "xs" defaults. */
.col-1  { width: 8.3333%; }
.col-2  { width: 16.6667%; }
.col-3  { width: 25%; }
.col-4  { width: 33.3333%; }
.col-5  { width: 41.6667%; }
.col-6  { width: 50%; }
.col-7  { width: 58.3333%; }
.col-8  { width: 66.6667%; }
.col-9  { width: 75%; }
.col-10 { width: 83.3333%; }
.col-11 { width: 91.6667%; }
.col-12 { width: 100%; }

/* >= 576px (sm) */
@media (min-width: 576px) {
    .col-sm-1  { width: 8.3333%; }
    .col-sm-2  { width: 16.6667%; }
    .col-sm-3  { width: 25%; }
    .col-sm-4  { width: 33.3333%; }
    .col-sm-5  { width: 41.6667%; }
    .col-sm-6  { width: 50%; }
    .col-sm-7  { width: 58.3333%; }
    .col-sm-8  { width: 66.6667%; }
    .col-sm-9  { width: 75%; }
    .col-sm-10 { width: 83.3333%; }
    .col-sm-11 { width: 91.6667%; }
    .col-sm-12 { width: 100%; }
}

/* >= 768px (md) — full set (base file only had 2,3,4,6) */
@media (min-width: 768px) {
    .col-md-1  { width: 8.3333%; }
    .col-md-2  { width: 16.6667%; }
    .col-md-3  { width: 25%; }
    .col-md-4  { width: 33.3333%; }
    .col-md-5  { width: 41.6667%; }
    .col-md-6  { width: 50%; }
    .col-md-7  { width: 58.3333%; }
    .col-md-8  { width: 66.6667%; }
    .col-md-9  { width: 75%; }
    .col-md-10 { width: 83.3333%; }
    .col-md-11 { width: 91.6667%; }
    .col-md-12 { width: 100%; }
}

/* >= 992px (lg) — full set (base file only had 4,6,8) */
@media (min-width: 992px) {
    .col-lg-1  { width: 8.3333%; }
    .col-lg-2  { width: 16.6667%; }
    .col-lg-3  { width: 25%; }
    .col-lg-4  { width: 33.3333%; }
    .col-lg-5  { width: 41.6667%; }
    .col-lg-6  { width: 50%; }
    .col-lg-7  { width: 58.3333%; }
    .col-lg-8  { width: 66.6667%; }
    .col-lg-9  { width: 75%; }
    .col-lg-10 { width: 83.3333%; }
    .col-lg-11 { width: 91.6667%; }
    .col-lg-12 { width: 100%; }
}

/* Mobile stacking — every column becomes full width below the md breakpoint.
   This fixes the original "fixed percent, no stacking" bug. */
@media (max-width: 767.98px) {
    [class*="col-"] {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* ===============================================================
   2. BOOTSTRAP-FLAVOURED MODALS  (paired with js/modal.js)
   Scoped to `.modal.fade` so it never clashes with the in-house
   `.modal.active` dialogs styled in design-system.css.
   =============================================================== */
.modal.fade {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    padding: var(--space-6) var(--space-4);
    /* reset the centred-transform the base .modal applies */
    top: auto;
    left: auto;
    transform: none;
    max-width: none;
    max-height: none;
    background: transparent;
    box-shadow: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base);
}

.modal.fade.show {
    display: block;
    opacity: 1;
    visibility: visible;
}

.modal.fade .modal-dialog {
    width: 100%;
    max-width: 520px;
    margin: 5vh auto;
    transform: translateY(-12px);
    transition: transform var(--transition-base);
}

.modal.fade.show .modal-dialog { transform: translateY(0); }

.modal.fade .modal-dialog.modal-lg { max-width: 800px; }
.modal.fade .modal-dialog.modal-sm { max-width: 360px; }

.modal.fade .modal-content {
    background: var(--white);
    border-radius: var(--radius-xl);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

/* The shared backdrop sits behind the dialog. */
.modal-backdrop.js-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: var(--z-modal-backdrop);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

body.modal-open { overflow: hidden; }

/* Bootstrap close-button glyph (no Bootstrap CSS present to draw it). */
.btn-close {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--gray-500);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0;
    line-height: 1;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.btn-close::before {
    content: "\00d7";          /* multiplication sign — a clean × */
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
}
.btn-close:hover { background: var(--gray-100); color: var(--gray-800); }
.btn-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.25);
}

/* ===============================================================
   3. PRODUCTION POLISH
   =============================================================== */

/* Smoother page-content entrance. */
.main-content > .container { animation: saheFadeUp .32s ease both; }
@keyframes saheFadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .main-content > .container,
    .modal.fade,
    .modal.fade .modal-dialog { animation: none !important; transition: none !important; }
}

/* Cards: a touch more lift on hover for interactive feel, consistent radius. */
.card,
.content-card,
.panel {
    transition: box-shadow var(--transition-base), border-color var(--transition-base), transform var(--transition-base);
}

/* Section title used on the dashboard and elsewhere. */
.section-title {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
    margin: 0 0 var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Subtle gradient sheen on primary buttons for a premium feel. */
.btn-primary {
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.04));
}

/* Tables: zebra-free but with crisper hover and rounded container. */
.table-container,
.table-wrapper,
.table-responsive {
    border: 1px solid var(--gray-200);
    background: var(--white);
}

/* Status / badge pills get a hairline for definition on white. */
.badge { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.02); }

/* Metric tile accent strip — a discreet brand cue. */
.metric-card::before {
    content: "";
    position: absolute;
    left: 0; top: 12px; bottom: 12px;
    width: 3px;
    border-radius: var(--radius-full);
    background: transparent;
    transition: background var(--transition-fast);
}
.metric-card:hover::before { background: var(--primary); }

/* Inputs: slightly softer rest state, clear focus already defined upstream. */
input, select, textarea, .form-control {
    box-shadow: var(--shadow-xs);
}

/* Empty-state icon gets the brand tint instead of flat grey. */
.empty-icon {
    background: var(--primary-50);
    color: var(--primary);
}

/* ===============================================================
   4. ACCESSIBILITY
   =============================================================== */

/* Always-visible keyboard focus ring across interactive elements. */
a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible,
.action-btn:focus-visible,
.dropdown-item:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Darken muted + warning text for AA contrast on white. */
.text-muted,
.page-subtitle,
.card-subtitle,
.metric-label,
.stat-label { color: var(--gray-600) !important; }

.text-warning { color: var(--warning-dark) !important; }

/* Skip-to-content affordance (progressive — used if a template adds it). */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 10000;
    background: var(--primary);
    color: #fff;
    padding: var(--space-2) var(--space-4);
    border-radius: 0 0 var(--radius-md) 0;
}
.skip-link:focus { left: 0; }

/* ===============================================================
   5. COMPREHENSIVE DARK MODE
   The base file flips the gray-* ramp and a few surfaces. Here we
   complete the picture: buttons, badges, alerts, panels, cards,
   tables, dropdowns, modals, form controls, status chips, etc.
   Most components already consume var(--*) tokens, so we mostly
   re-point the status *-light tints to dark-friendly translucents.
   =============================================================== */
html[data-theme="dark"] {
    --primary-50: #1c2c45;
    --primary-100: #24375a;
    --white: #1e293b;
    --surface: #1e293b;
    --bg: #1e293b;

    --success-light: rgba(34, 197, 94, 0.16);
    --warning-light: rgba(234, 179, 8, 0.16);
    --danger-light:  rgba(248, 113, 113, 0.16);
    --info-light:    rgba(96, 165, 250, 0.16);

    --success: #4ade80;
    --success-dark: #86efac;
    --warning: #facc15;
    --warning-dark: #fde047;
    --danger: #f87171;
    --danger-dark: #fca5a5;
    --info: #60a5fa;
    --info-dark: #93c5fd;
}

html[data-theme="dark"] body { background: #0f172a; color: #e2e8f0; }

/* App shell */
html[data-theme="dark"] .app-layout { background: #0f172a; }
html[data-theme="dark"] .main-content { background: #0f172a; }
html[data-theme="dark"] .mobile-header { background: #1e293b; border-color: #334155; }

/* Surfaces */
html[data-theme="dark"] .card,
html[data-theme="dark"] .content-card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .metric-card,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .filter-bar,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .modal.fade .modal-content,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .topbar-dropdown-menu {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #e2e8f0;
}

html[data-theme="dark"] .card-header,
html[data-theme="dark"] .content-card-header,
html[data-theme="dark"] .panel-header,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer,
html[data-theme="dark"] .card-footer,
html[data-theme="dark"] .panel-footer {
    background: #1e293b;
    border-color: #334155;
}
html[data-theme="dark"] .card-footer,
html[data-theme="dark"] .panel-footer { background: #172033; }

/* Tables */
html[data-theme="dark"] .table th,
html[data-theme="dark"] .data-table th {
    background: #172033;
    color: #cbd5e1;
    border-color: #334155;
}
html[data-theme="dark"] .table td,
html[data-theme="dark"] .data-table td {
    color: #e2e8f0;
    border-color: #283449;
}
html[data-theme="dark"] .table tbody tr:hover,
html[data-theme="dark"] .data-table tbody tr:hover { background: #24304a; }
html[data-theme="dark"] .data-table tfoot td { background: #172033; color: #f1f5f9; }

/* Form controls */
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .search-input,
html[data-theme="dark"] .topbar-search input {
    background: #0f172a !important;
    color: #f1f5f9;
    border-color: #334155;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #64748b; }
html[data-theme="dark"] select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
}

/* Buttons */
html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .btn-outline,
html[data-theme="dark"] .btn-outline-secondary {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #475569;
}
html[data-theme="dark"] .btn-secondary:hover,
html[data-theme="dark"] .btn-outline:hover,
html[data-theme="dark"] .btn-outline-secondary:hover {
    background: #24304a;
    color: #f1f5f9;
}
html[data-theme="dark"] .btn-ghost { color: #cbd5e1; }
html[data-theme="dark"] .btn-ghost:hover { background: #24304a; color: #f1f5f9; }

/* Badges, chips, alerts already consume the re-pointed tints above.
   Just ensure neutral variants read well. */
html[data-theme="dark"] .badge-secondary,
html[data-theme="dark"] .badge.bg-secondary,
html[data-theme="dark"] .status-chip,
html[data-theme="dark"] .badge.bg-light,
html[data-theme="dark"] .status-inactive,
html[data-theme="dark"] .status-badge.inactive {
    background: #334155 !important;
    color: #cbd5e1 !important;
}
html[data-theme="dark"] .code-badge { background: #334155; color: #e2e8f0; }

html[data-theme="dark"] .alert-info { background: var(--info-light); color: var(--info-dark); border-color: rgba(96,165,250,0.3); }
html[data-theme="dark"] .alert-success { background: var(--success-light); color: var(--success-dark); border-color: rgba(74,222,128,0.3); }
html[data-theme="dark"] .alert-warning { background: var(--warning-light); color: var(--warning-dark); border-color: rgba(250,204,21,0.3); }
html[data-theme="dark"] .alert-danger { background: var(--danger-light); color: var(--danger-dark); border-color: rgba(248,113,113,0.3); }

/* Dropdown items */
html[data-theme="dark"] .dropdown-item,
html[data-theme="dark"] .topbar-dropdown-item { color: #e2e8f0; }
html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .topbar-dropdown-item:hover { background: #24304a; }
html[data-theme="dark"] .topbar-dropdown-header,
html[data-theme="dark"] .topbar-dropdown-divider,
html[data-theme="dark"] .dropdown-divider { border-color: #334155; background: transparent; }

/* Progress track */
html[data-theme="dark"] .progress { background: #334155; }

/* Pagination */
html[data-theme="dark"] .pagination a,
html[data-theme="dark"] .pagination span,
html[data-theme="dark"] .page-link {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}
html[data-theme="dark"] .pagination a:hover,
html[data-theme="dark"] .page-link:hover { background: #24304a; }

/* Quick-links / attention / list rows */
html[data-theme="dark"] .quick-link { color: #cbd5e1; border-color: #283449; }
html[data-theme="dark"] .quick-link:hover { background: #24304a; color: #f1f5f9; }
html[data-theme="dark"] .attention-item { border-color: #283449; }
html[data-theme="dark"] .attention-item:hover { background: #24304a; }
html[data-theme="dark"] .list-group-item { border-color: #283449; }

/* Empty state tweak for dark */
html[data-theme="dark"] .empty-icon { background: #24304a; color: #93c5fd; }

/* Modal backdrop already dark; nudge opacity. */
html[data-theme="dark"] .modal-backdrop.js-modal-backdrop { background: rgba(0, 0, 0, 0.6); }

/* Muted text override re-points to a readable slate in dark. */
html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .page-subtitle,
html[data-theme="dark"] .card-subtitle,
html[data-theme="dark"] .metric-label,
html[data-theme="dark"] .stat-label { color: #94a3b8 !important; }

/* =====================================================================
   FOUNDATION ADD-ONS (Session 3) — fill remaining utility/component gaps
   so no page renders unstyled, and standardise tables/cards/charts.
   ===================================================================== */

/* --- Missing button variants/aliases used across templates --- */
.btn-xs { padding: 2px 8px; font-size: 0.72rem; line-height: 1.4; border-radius: 6px; }
.btn-save  { background: var(--primary); color:#fff; border:1px solid var(--primary); }
.btn-save:hover { background: var(--primary-dark, #16314f); }
.btn-submit { background: var(--primary); color:#fff; }
.btn-cancel, .btn-back { background:#fff; color: var(--gray-700,#374151); border:1px solid var(--gray-300,#d1d5db); }
.btn-cancel:hover, .btn-back:hover { background: var(--gray-50,#f8f9fb); }
.btn-delete { background: var(--danger,#dc2626); color:#fff; border:1px solid var(--danger,#dc2626); }
.btn-delete:hover { filter: brightness(0.93); }

/* --- Table polish: hover + responsive scroll + zebra option --- */
.table-hover tbody tr:hover,
.data-table.table-hover tbody tr:hover { background: var(--primary-50, #eef2f7); }
.table-responsive { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.data-table.striped tbody tr:nth-child(even),
.table.striped tbody tr:nth-child(even) { background: var(--gray-50, #fafbfc); }

/* Row action buttons cluster (consistent across all list pages) */
.row-actions { display:inline-flex; gap:6px; align-items:center; white-space:nowrap; }
.row-actions .btn { padding:4px 9px; font-size:0.78rem; }

/* --- Float/spacing utilities still referenced by templates --- */
.float-end { float:right !important; }
.float-start { float:left !important; }
.ms-auto { margin-left:auto !important; }
.me-auto { margin-right:auto !important; }
.w-100 { width:100% !important; }

/* --- Chart container: one consistent wrapper for all graphs --- */
.chart-card { background:#fff; border:1px solid var(--gray-200,#e5e7eb); border-radius:14px; padding:20px 22px; box-shadow:0 1px 3px rgba(16,24,40,.06); }
.chart-card .chart-title { font-size:0.95rem; font-weight:700; color:var(--gray-800,#1f2937); margin:0 0 14px; display:flex; align-items:center; gap:8px; }
.chart-wrap { position:relative; width:100%; height:300px; }
.chart-wrap.sm { height:220px; }
.chart-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(340px,1fr)); gap:20px; }

/* --- Empty state (standardised) --- */
.empty-state { text-align:center; padding:48px 24px; color:var(--gray-500,#6b7280); }
.empty-state i { font-size:42px; color:var(--gray-300,#d1d5db); margin-bottom:14px; display:block; }
.empty-state h3 { color:var(--gray-600,#4b5563); margin:0 0 6px; font-size:1.05rem; }

/* Dark-mode for the new bits */
html[data-theme="dark"] .chart-card,
html[data-theme="dark"] .btn-cancel,
html[data-theme="dark"] .btn-back { background:#1e293b; color:#e2e8f0; border-color:#334155; }
html[data-theme="dark"] .table-hover tbody tr:hover { background:#243049; }
html[data-theme="dark"] .data-table.striped tbody tr:nth-child(even),
html[data-theme="dark"] .table.striped tbody tr:nth-child(even) { background:#1c2638; }

/* =====================================================================
   FORM LAYOUT STANDARD (Session 3) — one polished, consistent form
   system. Fixes sprawling grids, floating checkboxes, and width so every
   create/edit form reads cleanly regardless of how fields are rendered.
   ===================================================================== */

/* Keep forms to a comfortable reading width even inside full-width panels. */
.form-container { max-width: 920px; margin: 0 auto; }
.panel > .panel-body > form .form-grid,
.form-card .form-grid,
.panel-body > form .form-grid { max-width: 100%; }

/* Canonical 2-column grid with sensible stacking; never auto-fill into 4+. */
.form-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 18px 22px !important;
    align-items: start;
}
.form-grid .full-width,
.form-grid .form-group.full-width { grid-column: 1 / -1; }
/* A textarea field should always span the full row. */
.form-grid .form-group:has(textarea) { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 0; }
.form-group > label,
.form-group > .form-label { font-size: .72rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .4px; color: var(--gray-500, #6b7280); margin: 0; }

/* --- Checkboxes / radios: render as a clean inline toggle row --- */
.form-group input[type="checkbox"],
.form-group input[type="radio"],
input[type="checkbox"], input[type="radio"] {
    width: 18px !important; height: 18px !important; min-height: 0 !important;
    padding: 0 !important; margin: 0; flex: 0 0 auto;
    accent-color: var(--primary, #1e3a5f); cursor: pointer; vertical-align: middle;
    border-radius: 5px; appearance: auto;
}
/* When a form-group is just a checkbox/radio, lay it out as a tidy row card. */
.form-grid .form-group:has(> input[type="checkbox"]:only-of-type),
.form-grid .form-group:has(> label > input[type="checkbox"]) {
    flex-direction: row-reverse; align-items: center; justify-content: flex-end;
    gap: 10px; background: var(--gray-50, #f8f9fb); border: 1px solid var(--gray-200,#e5e7eb);
    border-radius: 10px; padding: 11px 14px; align-self: stretch;
}
.form-grid .form-group:has(> input[type="checkbox"]) > label,
.form-grid .form-group:has(> input[type="checkbox"]) > .form-label {
    text-transform: none; letter-spacing: 0; font-size: .85rem; font-weight: 500;
    color: var(--gray-700,#374151); margin: 0; flex: 1;
}

/* Standard form footer/actions row. */
.form-actions, .form-footer {
    display: flex; gap: 12px; justify-content: flex-end; align-items: center;
    padding: 18px 0 0; margin-top: 22px; border-top: 1px solid var(--gray-200,#e5e7eb);
}
.form-card .form-actions, .form-card .form-footer { padding: 16px 24px; margin-top: 0;
    background: var(--gray-50,#f8f9fb); }

/* Responsive: single column on phones. */
@media (max-width: 640px){ .form-grid { grid-template-columns: 1fr !important; } }

/* Dark mode */
html[data-theme="dark"] .form-grid .form-group:has(> input[type="checkbox"]) {
    background:#1c2638; border-color:#334155; }
html[data-theme="dark"] .form-actions, html[data-theme="dark"] .form-footer { border-color:#334155; }
html[data-theme="dark"] .form-card .form-actions, html[data-theme="dark"] .form-card .form-footer { background:#1e293b; }

/* =====================================================================
   Document-template module — shared bits that replace the old per-page
   inline <style> blocks (modal preview, rendered output, document editor).
   Centralised here so the markup uses shared classes only.
   ===================================================================== */

/* Wide variant of the standard .modal for rendered-document previews. */
.modal.modal-lg { max-width: 820px; }
.modal .rendered-content { border:1px solid var(--gray-200,#e5e7eb); border-radius:8px;
    padding:24px; line-height:1.7; font-size:.9rem; max-height:60vh; overflow-y:auto; }

/* Rendered preview surface (preview page). */
.rendered-doc { background:#fff; border:1px solid var(--gray-200,#e5e7eb); border-radius:8px;
    padding:28px; line-height:1.7; color:var(--gray-800,#1e293b); }
.preview-subject { background:var(--gray-50,#f8f9fb); border:1px solid var(--gray-200,#e5e7eb);
    border-radius:6px; padding:10px 14px; margin-bottom:16px; }
.preview-subject strong { color:var(--primary,#1e3a5f); margin-right:6px; }

/* Document-template editor: code editor + variable sidebar (no shared eq). */
.tpl-editor { display:grid; grid-template-columns:1fr 380px; gap:24px; align-items:start; }
.tpl-editor__side { position:sticky; top:16px; }
.tpl-code { border:1px solid var(--gray-300,#d1d5db); border-radius:8px; overflow:hidden; background:#fff; }
.tpl-code__toolbar { display:flex; align-items:center; gap:2px; padding:6px 10px;
    background:var(--gray-50,#f8f9fb); border-bottom:1px solid var(--gray-200,#e5e7eb); flex-wrap:wrap; }
.tpl-code__toolbar .sep { width:1px; height:20px; background:var(--gray-300,#d1d5db); margin:0 6px; }
.tpl-tbtn { display:inline-flex; align-items:center; gap:5px; padding:5px 10px; border:none;
    background:transparent; border-radius:4px; font-size:.76rem; color:var(--gray-600,#4b5563);
    cursor:pointer; transition:all .15s; font-family:inherit; }
.tpl-tbtn:hover { background:var(--primary,#1e3a5f); color:#fff; }
.tpl-code textarea { width:100%; min-height:320px; padding:16px; border:none; outline:none;
    font-family:'Cascadia Code','Fira Code','Consolas',monospace; font-size:.82rem; line-height:1.7;
    resize:vertical; background:#fafbfc; color:#1e293b; border-radius:0; }
.tpl-mono { font-family:'Cascadia Code','Consolas',monospace !important; font-size:.82rem !important; }
.tpl-tabs { display:flex; border-bottom:1px solid var(--gray-200,#e5e7eb); }
.tpl-tab { flex:1; padding:11px 0; text-align:center; font-size:.78rem; font-weight:600;
    color:var(--gray-500,#6b7280); background:transparent; border:none; cursor:pointer;
    border-bottom:2px solid transparent; transition:all .15s; }
.tpl-tab.active { color:var(--primary,#1e3a5f); border-bottom-color:var(--primary,#1e3a5f);
    background:var(--gray-50,#f8f9fb); }
.tpl-pane { display:none; }
.tpl-pane.active { display:block; }
.tpl-var-search input { width:100%; }
.tpl-var-group-head { display:flex; align-items:center; justify-content:space-between; padding:6px 10px;
    font-size:.72rem; font-weight:700; color:var(--primary,#1e3a5f); text-transform:uppercase;
    letter-spacing:.04em; cursor:pointer; border-radius:4px; }
.tpl-var-group-head:hover { background:#f0f4f8; }
.tpl-var-chips { padding:2px 4px 10px; display:flex; flex-wrap:wrap; gap:4px; }
.tpl-chip { display:inline-block; padding:3px 8px; background:#f0f4f8; border:1px solid var(--gray-200,#e5e7eb);
    border-radius:4px; font-size:.72rem; font-family:'Cascadia Code','Consolas',monospace;
    color:var(--primary,#1e3a5f); cursor:pointer; transition:all .12s; white-space:nowrap; }
.tpl-chip:hover { background:var(--primary,#1e3a5f); color:#fff; border-color:var(--primary,#1e3a5f); }
.tpl-preview-doc { background:#fff; border:1px solid var(--gray-200,#e5e7eb); border-radius:6px;
    padding:24px; font-size:.85rem; line-height:1.7; color:#1e293b; min-height:200px; }
@media(max-width:1024px){ .tpl-editor{ grid-template-columns:1fr; } .tpl-editor__side{ position:static; } }

/* Global form error + text-transform utilities (used by standard forms). */
.form-error { font-size:.75rem; color:var(--danger,#dc2626); display:flex; align-items:center; gap:.3rem; margin-top:2px; }
.form-error i { font-size:.7rem; }
.text-uppercase { text-transform:uppercase !important; }

/* =====================================================================
   POLISH PASS (Session 4) — input comfort + graceful placeholder
   truncation + premium visual refinements toward a 10/10 finish.
   ===================================================================== */

/* --- Inputs: never clip a placeholder; degrade long text to an ellipsis. --- */
.form-control, input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="date"], input[type="time"],
input[type="datetime-local"], input[type="url"], input[type="search"], select {
    min-height: 42px; height: 42px; line-height: 1.4;
    text-overflow: ellipsis;            /* long placeholder/value -> "…" not a hard cut */
}
input::placeholder, textarea::placeholder { text-overflow: ellipsis; opacity: 1; color: var(--gray-400,#9ca3af); }
textarea { min-height: 96px; height: auto; line-height: 1.5; }
/* Tame native number spinners so the value/placeholder isn't crowded. */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { margin-left: 4px; }
/* Selects: keep room for the chevron so long options don't sit under it. */
select { padding-right: 2.6rem !important; }
/* Slightly stronger, calmer focus ring. */
.form-control:focus, input:focus, select:focus, textarea:focus {
    box-shadow: 0 0 0 3px rgba(30,58,95,.12); border-color: var(--primary,#1e3a5f);
}

/* --- Premium card / table / header refinements --- */
.metric-card { transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease; }
.metric-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(16,24,40,.10); }
.panel, .card, .chart-card { box-shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06); }
.panel-header, .card-header { letter-spacing: .1px; }
.data-table thead th, .table thead th {
    text-transform: uppercase; font-size: .68rem; letter-spacing: .5px;
    color: var(--gray-500,#6b7280); background: var(--gray-50,#f8fafc);
    border-bottom: 1px solid var(--gray-200,#e5e7eb); white-space: nowrap;
}
.data-table tbody td, .table tbody td { vertical-align: middle; }
.page-header { padding-bottom: 14px; border-bottom: 1px solid var(--gray-200,#eef0f3); margin-bottom: 22px; }
.btn { transition: transform .12s ease, box-shadow .12s ease, background .15s ease, filter .15s ease; }
.btn:active { transform: translateY(1px); }
.badge { font-weight: 600; letter-spacing: .2px; }

/* Dark-mode parity for the refinements. */
html[data-theme="dark"] .data-table thead th, html[data-theme="dark"] .table thead th {
    background: #243049; color: #94a3b8; border-color: #334155; }
html[data-theme="dark"] .page-header { border-color: #334155; }
html[data-theme="dark"] input::placeholder, html[data-theme="dark"] textarea::placeholder { color: #64748b; }

/* Apply-form document uploads + country doc rule inputs */
.doc-upload-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; }
.doc-upload-grid .doc-req { display:flex; flex-direction:column; gap:6px; }
.doc-req label { font-size:.78rem; font-weight:600; color:var(--gray-600,#4b5563); }
.doc-req input[type="file"] { font-size:.85rem; padding:8px 10px; border:1px dashed var(--gray-300,#d1d5db);
    border-radius:10px; background:var(--gray-50,#f8fafc); width:100%; }
.doc-req input[type="file"]:hover { border-color:var(--primary,#1e3a5f); }
@media (max-width:640px){ .doc-upload-grid { grid-template-columns:1fr; } }

/* =====================================================================
   Custom dialogs (saheConfirm / saheAlert) — replaces native confirm/alert
   ===================================================================== */
.sahe-dialog-overlay {
    position: fixed; inset: 0; z-index: 4000; display: none;
    align-items: center; justify-content: center;
    background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px);
    padding: 20px; animation: saheFade .15s ease;
}
.sahe-dialog-overlay.open { display: flex; }
@keyframes saheFade { from { opacity: 0; } to { opacity: 1; } }
.sahe-dialog {
    background: #fff; border-radius: 16px; width: 100%; max-width: 420px;
    padding: 28px 26px 22px; text-align: center;
    box-shadow: 0 24px 60px rgba(16, 24, 40, .28); animation: sahePop .18s ease;
}
@keyframes sahePop { from { transform: translateY(8px) scale(.98); opacity: .6; } to { transform: none; opacity: 1; } }
.sahe-dialog-icon {
    width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 14px;
    display: flex; align-items: center; justify-content: center; font-size: 24px;
    background: var(--primary-50, #eef2f7); color: var(--primary, #1e3a5f);
}
.sahe-dialog-icon.danger  { background: #fee2e2; color: #dc2626; }
.sahe-dialog-icon.warning { background: #fef3c7; color: #b45309; }
.sahe-dialog-icon.success { background: #dcfce7; color: #16a34a; }
.sahe-dialog-icon.info    { background: #e0f2fe; color: #0369a1; }
.sahe-dialog-title { font-size: 1.15rem; font-weight: 700; color: var(--gray-900, #111827); margin: 0 0 6px; }
.sahe-dialog-msg { font-size: .92rem; color: var(--gray-600, #4b5563); margin: 0 0 22px; line-height: 1.5; }
.sahe-dialog-actions { display: flex; gap: 10px; justify-content: center; }
.sahe-dialog-actions .btn { min-width: 110px; justify-content: center; }
html[data-theme="dark"] .sahe-dialog { background: #1e293b; }
html[data-theme="dark"] .sahe-dialog-title { color: #f1f5f9; }
html[data-theme="dark"] .sahe-dialog-msg { color: #cbd5e1; }
