/* ================================================================
   SQRbits Dashboard — Layout & Custom Components
   static/dashboard/layout.css

   Loaded AFTER bootstrap.min.css + theme.css.
   Contains ONLY layout structure & non-Bootstrap custom components.
   Bootstrap owns: .btn, .card, .table, .alert, .badge, forms.
   ================================================================ */


/* ── A) Design Tokens ─────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg:           #f4f5f7;
  --panel:        #ffffff;
  --border:       #e2e4e9;
  --border-light: #f0f1f3;

  /* Text */
  --text:         #111827;
  --text-secondary: #4b5563;
  --muted:        #8b929e;

  /* Semantic */
  --primary:      #18181b;
  --primary-600:  #27272a;
  --primary-ring: rgba(24,24,27,.18);

  --success:         #059669;
  --success-bg:      #ecfdf5;
  --success-border:  #a7f3d0;
  --success-text:    #065f46;

  --danger:          #dc2626;
  --danger-bg:       #fef2f2;
  --danger-border:   #fecaca;
  --danger-text:     #991b1b;

  --warning:         #d97706;
  --warning-bg:      #fffbeb;
  --warning-border:  #fde68a;
  --warning-text:    #92400e;

  --info:            #2563eb;
  --info-bg:         #eff6ff;
  --info-border:     #bfdbfe;
  --info-text:       #1e40af;

  /* Radius */
  --radius:       8px;
  --radius-lg:    12px;
  --radius-full:  9999px;

  /* Shadows */
  --shadow:       0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
  --shadow-md:    0 4px 16px rgba(0,0,0,.07);
  --shadow-lg:    0 10px 32px rgba(0,0,0,.10);

  /* Typography */
  --font:      'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --text-xs:   .6875rem;   /* 11px */
  --text-sm:   .8125rem;   /* 13px */
  --text-base: .875rem;    /* 14px */
  --text-md:   .9375rem;   /* 15px */
  --text-lg:   1.0625rem;  /* 17px */
  --text-xl:   1.25rem;    /* 20px */
  --text-2xl:  1.5rem;     /* 24px */
  --text-3xl:  1.875rem;   /* 30px */
  --leading:   1.6;

  /* Layout */
  --sidebar-w: 260px;
  --topbar-h:  56px;
  --content-max: 1200px;

  /* Transitions */
  --ease: cubic-bezier(.4,0,.2,1);
}


/* ── Reset ────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: var(--leading);
  color: var(--text);
  /* background is set by theme.css */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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


/* ================================================================
   B) LAYOUT
   ================================================================ */
.layout { display: flex; min-height: 100vh; }


/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: #d4d4d8;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 22px 24px 18px;
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: -.5px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-brand span { color: var(--brand); }

.sidebar-company {
  padding: 14px 24px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-company-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: #e4e4e7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.sidebar-company-role {
  font-size: var(--text-xs);
  color: #71717a;
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-top: 2px;
}

/* Nav */
.sidebar-nav { flex: 1; padding: 10px 0; }

.sidebar-section-label {
  padding: 22px 24px 6px;
  font-size: .625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #52525b;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: #a1a1aa;
  border-left: 3px solid transparent;
  transition: all .15s var(--ease);
}
.sidebar-nav a:hover {
  background: rgba(255,255,255,.05);
  color: #f4f4f5;
}
.sidebar-nav a.active {
  background: rgba(255,255,255,.08);
  color: var(--brand);
  font-weight: 600;
  border-left-color: var(--brand);
}

.nav-icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  font-size: 14px;
  opacity: .55;
}
.sidebar-nav a:hover .nav-icon,
.sidebar-nav a.active .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 14px 24px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-footer form { display: inline; }
.sidebar-footer button {
  background: none;
  border: none;
  color: #71717a;
  font-size: var(--text-sm);
  cursor: pointer;
  padding: 6px 0;
  transition: color .15s;
}
.sidebar-footer button:hover { color: #fca5a5; }


/* ── Main ─────────────────────────────────────────────────────── */
.layout > .main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}


/* ── Topbar ───────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.topbar-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-user {
  font-size: var(--text-sm);
  color: var(--muted);
}
.topbar-user strong { color: var(--text-secondary); font-weight: 600; }

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: .625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.role-badge-owner {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #92400e;
}
.role-badge-staff {
  background: #f4f4f5;
  color: #52525b;
}


/* ── Content ──────────────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 28px 32px 40px;
  max-width: var(--content-max);
  width: 100%;
}


/* ================================================================
   PAGE HEADER SYSTEM (Global Standard)
   ================================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

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

.page-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.page-header-lg {
  margin-bottom: 28px;
}


/* ================================================================
   ADDED UTILITIES (backward compat for templates)
   ================================================================ */

/* Table wrapper (fallback if a page still uses .table-wrap) */
.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--panel);
}


/* ================================================================
   POINTS (customer detail — colours not in theme.css)
   ================================================================ */
.pts-balance        { background: var(--info-bg); }
.pts-balance .pts-label { color: #3b82f6; }
.pts-earned         { background: var(--success-bg); }
.pts-earned .pts-label  { color: #10b981; }
.pts-redeemed       { background: var(--danger-bg); }
.pts-redeemed .pts-label { color: #ef4444; }


/* ================================================================
   MODAL
   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: modalOverlayIn .2s ease;
}
.modal-overlay[hidden] { display: none; }

.modal-container {
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  position: relative;
  animation: modalIn .2s ease;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  font-size: 20px;
  color: var(--muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: all .15s var(--ease);
  z-index: 1;
}
.modal-close:hover {
  background: rgba(0,0,0,.06);
  color: var(--text-secondary);
}

.modal-header { padding: 22px 22px 0; }
.modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
}
.modal-subtitle {
  font-size: var(--text-sm);
  color: var(--muted);
  margin-top: 3px;
}
.modal-body { padding: 18px 22px 22px; }

@keyframes modalOverlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}


/* ================================================================
   BRANCH MAP
   ================================================================ */
.branch-map {
  height: 360px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  z-index: 0;
}
.branch-map-modal {
  height: 260px;
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Fix Leaflet z-index inside modals */
.modal-body .leaflet-pane { z-index: 1; }
.modal-body .leaflet-top,
.modal-body .leaflet-bottom { z-index: 2; }


/* ================================================================
   TOAST
   ================================================================ */
#toast-container {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 400px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.45;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  border: 1px solid transparent;
  animation: toastIn .3s ease-out;
  transition: opacity .25s, transform .25s;
}
.toast.removing { opacity: 0; transform: translateX(30px); }
.toast-icon  { flex-shrink: 0; font-size: 16px; line-height: 1.3; }
.toast-body  { flex: 1; }
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: inherit;
  opacity: .4;
  padding: 0 0 0 6px;
  line-height: 1;
}
.toast-close:hover { opacity: .8; }

.toast-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.toast-error   { background: var(--danger-bg);  border-color: var(--danger-border);  color: var(--danger-text); }
.toast-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.toast-info    { background: var(--info-bg);    border-color: var(--info-border);    color: var(--info-text); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}


/* ================================================================
   HTMX INDICATOR
   ================================================================ */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-indicator.htmx-request { display: inline-block; }
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }


/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 768px) {
  .sidebar {
    display: flex;
    transform: translateX(-110%);
    transition: transform .2s ease;
    width: min(86vw, 320px);
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .layout > .main { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .page-header { flex-direction: column; gap: 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* Backdrop */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 90;
}
body.sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Show hamburger only on mobile */
.mobile-only { display: none; }
@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
}


/* ================================================================
   QUICK ACTION CARDS (dashboard home)
   ================================================================ */
.quick-action-card {
  transition: transform .12s var(--ease), box-shadow .12s var(--ease);
  border: 1px solid var(--border);
  cursor: pointer;
}
.quick-action-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}
.quick-action-icon {
  font-size: 28px;
  line-height: 1;
}

