/* ============================================================
 * cellio.css — shared design system for the IMS web UI.
 * ------------------------------------------------------------
 * 🌙 DARK THEME (v2). Surfaces, text, and borders are tuned for
 * long sessions in dim shop environments. The sidebar and content
 * area share a deep navy palette; the accent (purple-blue) stays
 * the brand colour but slightly brighter to read well on dark.
 *
 * Printable pages (sale-summary, print_label) are forced back to
 * a white-on-black scheme via @media print at the bottom.
 *
 * Sections:
 *   1.  CSS variables (tokens)         → colour palette + shape
 *   2.  Reset + base
 *   3.  Layout primitives (app shell, sidebar, content)
 *   4.  Typography
 *   5.  Buttons
 *   6.  Cards + KPIs + Tiles
 *   7.  Forms + inputs
 *   8.  Tables
 *   9.  Pills / badges
 *   10. Empty state
 *   11. Utilities
 *   12. Login (full-screen)
 *   13. Responsive
 *   14. Print overrides
 * ============================================================ */

/* ---- 1. Tokens -------------------------------------------- */
:root {
  /* Brand */
  --c-accent:        #6d7eff;
  --c-accent-hover:  #8090ff;
  --c-accent-soft:   rgba(109, 126, 255, 0.18);
  --c-accent-text:   #ffffff;

  /* Neutrals (dark theme) */
  --c-bg:            #0b1020;   /* Page background — deep navy */
  --c-surface:       #141c33;   /* Cards / panels */
  --c-surface-alt:   #1c243c;   /* Table heads, hover, subdued blocks */
  --c-surface-deep:  #0e1428;   /* Inputs (slightly darker than cards) */
  --c-border:        #28324f;   /* Default border — visible but subtle */
  --c-border-strong: #3d4a73;   /* Hover / strong border */
  --c-text:          #e8eef7;   /* Body text */
  --c-text-muted:    #98a2bd;   /* Secondary text */
  --c-text-dim:      #6c7591;   /* Tertiary / placeholder */

  /* Sidebar — slightly darker than the content surface so it
     reads as the navigation chrome rather than as a peer card. */
  --c-side-bg:       #060a17;
  --c-side-bg-hover: #11182d;
  --c-side-text:     #d8def0;
  --c-side-text-dim: #7a8299;
  --c-side-active:   #6d7eff;
  --c-side-divider:  #1a2238;

  /* Status — bright fills on transparent backgrounds. The "soft"
     variant is what cards/pills use as their background. */
  --c-success:       #34d399;
  --c-success-soft:  rgba(52, 211, 153, 0.16);
  --c-success-text:  #6ee7b7;     /* light green for text on dark */
  --c-warn:          #fbbf24;
  --c-warn-soft:     rgba(251, 191, 36, 0.16);
  --c-warn-text:     #fde68a;
  --c-error:         #f87171;
  --c-error-soft:    rgba(248, 113, 113, 0.16);
  --c-error-text:    #fca5a5;
  --c-info:          #60a5fa;
  --c-info-soft:     rgba(96, 165, 250, 0.16);
  --c-info-text:     #93c5fd;

  /* Shape */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* Elevation — softer on dark. */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h:  60px;

  /* Type scale */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 28px;
  --fs-3xl: 36px;
}

/* ---- 2. Reset + base -------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--c-accent-hover); }

code, pre, .mono {
  font-family: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}
code {
  background: var(--c-surface-alt);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--c-info-text);
}

::selection { background: var(--c-accent); color: #fff; }

/* Default scrollbars on dark */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--c-bg); }
::-webkit-scrollbar-thumb {
  background: var(--c-border);
  border-radius: 8px;
  border: 2px solid var(--c-bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--c-border-strong); }

/* ---- 3. App shell ----------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--c-side-bg);
  color: var(--c-side-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--c-side-divider);
}

.sidebar-brand {
  padding: 18px 18px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--c-side-divider);
  color: #fff;
}

.sidebar-brand .brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--c-accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
}

.sidebar-section { padding: 14px 0 6px; }
.sidebar-section-title {
  padding: 0 18px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-side-text-dim);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  color: var(--c-side-text);
  font-size: var(--fs-md);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.sidebar-link:hover {
  background: var(--c-side-bg-hover);
  text-decoration: none;
  color: #fff;
}
.sidebar-link.active {
  background: var(--c-side-bg-hover);
  border-left-color: var(--c-side-active);
  color: #fff;
  font-weight: 600;
}
.sidebar-link .icon {
  width: 18px;
  text-align: center;
  font-size: 15px;
  opacity: 0.85;
}

.sidebar-foot {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--c-side-divider);
  font-size: var(--fs-sm);
  color: var(--c-side-text-dim);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-user { display: flex; align-items: center; gap: 8px; }
.sidebar-user .avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--c-accent);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px; text-transform: uppercase;
}
.sidebar-user .name {
  color: var(--c-side-text);
  font-weight: 500;
  font-size: var(--fs-md);
}
.sidebar-foot a {
  color: var(--c-side-text-dim);
  font-size: var(--fs-sm);
}
.sidebar-foot a:hover { color: #fff; }

/* Main content */
.content {
  padding: 28px 32px 60px;
  max-width: 1400px;
  width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--c-text);
}
.page-subtitle {
  color: var(--c-text-muted);
  font-size: var(--fs-md);
  margin-top: 4px;
}

/* ---- 4. Typography ---------------------------------------- */
h1, h2, h3, h4 { color: var(--c-text); font-weight: 700; letter-spacing: -0.01em; }

/* ---- 5. Buttons ------------------------------------------- */
.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  font-weight: 500;
  font-family: inherit;
  border: 1px solid transparent;
  background: var(--c-surface-alt);
  color: var(--c-text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.06s;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover {
  background: var(--c-border);
  text-decoration: none;
  color: var(--c-text);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--c-accent);
  color: #fff;
  border-color: var(--c-accent);
}
.btn-primary:hover {
  background: var(--c-accent-hover);
  border-color: var(--c-accent-hover);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--c-border);
  color: var(--c-text);
}
.btn-ghost:hover {
  background: var(--c-surface-alt);
  border-color: var(--c-border-strong);
  color: var(--c-text);
}

.btn-danger {
  background: var(--c-error);
  color: #fff;
  border-color: var(--c-error);
}
.btn-danger:hover {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.btn-sm { padding: 5px 11px; font-size: var(--fs-sm); }
.btn-lg { padding: 12px 22px; font-size: var(--fs-lg); }
.btn-block { width: 100%; }

/* ---- 6. Cards + KPIs + Tiles ------------------------------ */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.card-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--c-text);
}
.card-link {
  font-size: var(--fs-sm);
  color: var(--c-accent);
  text-decoration: none;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.12s, transform 0.12s;
  box-shadow: var(--shadow-sm);
}
.kpi:hover { border-color: var(--c-border-strong); }
.kpi-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--c-text);
}
.kpi-sub { font-size: var(--fs-sm); color: var(--c-text-muted); }
.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-sm);
  font-weight: 500;
}
.kpi-trend.up   { color: var(--c-success); }
.kpi-trend.down { color: var(--c-error); }
.kpi-trend.flat { color: var(--c-text-dim); }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.tile {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: var(--c-text);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
  box-shadow: var(--shadow-sm);
}
.tile:hover {
  border-color: var(--c-accent);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  color: var(--c-text);
  transform: translateY(-1px);
}
.tile-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--c-accent-soft);
  color: var(--c-accent);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: 18px;
}
.tile-title { font-weight: 600; font-size: var(--fs-md); }
.tile-desc {
  font-size: var(--fs-sm);
  color: var(--c-text-muted);
  line-height: 1.4;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 26px 0 12px;
}
.section-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--c-text);
}

/* ---- 7. Forms --------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.form-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--c-text);
}
.form-help {
  font-size: var(--fs-xs);
  color: var(--c-text-muted);
}
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface-deep);
  color: var(--c-text);
  font-size: var(--fs-md);
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px var(--c-accent-soft);
  background: var(--c-surface);
}
.input::placeholder, .textarea::placeholder { color: var(--c-text-dim); }
.textarea { resize: vertical; min-height: 80px; }

/* Native select arrow tinting (Firefox/WebKit) */
.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2398a2bd' d='M6 8L0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.select option { background: var(--c-surface); color: var(--c-text); }

/* Native checkbox / radio: accent the modern way (browser-tinted). */
input[type="checkbox"], input[type="radio"] { accent-color: var(--c-accent); }

/* ---- 8. Tables -------------------------------------------- */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  font-size: var(--fs-md);
}
.table th, .table td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
}
.table th {
  background: var(--c-surface-alt);
  font-weight: 600;
  color: var(--c-text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--c-surface-alt); }
.table a { color: var(--c-info); }
.table a:hover { color: var(--c-info-text); }

/* ---- 9. Pills / badges ------------------------------------ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--c-surface-alt);
  color: var(--c-text);
}
.pill-success { background: var(--c-success-soft); color: var(--c-success-text); }
.pill-warn    { background: var(--c-warn-soft);    color: var(--c-warn-text); }
.pill-error   { background: var(--c-error-soft);   color: var(--c-error-text); }
.pill-info    { background: var(--c-info-soft);    color: var(--c-info-text); }
.pill-accent  { background: var(--c-accent-soft);  color: var(--c-accent); }

/* ---- 10. Empty state -------------------------------------- */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--c-text-muted);
  font-size: var(--fs-md);
  background: var(--c-surface);
  border: 1px dashed var(--c-border);
  border-radius: var(--r-md);
}
.empty-icon { font-size: 32px; margin-bottom: 8px; opacity: 0.6; }

/* ---- 11. Utilities ---------------------------------------- */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.text-muted   { color: var(--c-text-muted); }
.text-dim     { color: var(--c-text-dim); }
.text-success { color: var(--c-success-text); }
.text-error   { color: var(--c-error-text); }
.text-warn    { color: var(--c-warn-text); }
.text-info    { color: var(--c-info-text); }
.fs-sm { font-size: var(--fs-sm); }
.fs-xs { font-size: var(--fs-xs); }
.fw-600 { font-weight: 600; }
.mt-2 { margin-top: 8px; }   .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }

/* ---- 12. Login (full-screen) ------------------------------ */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--c-bg);
}
.login-side {
  background:
    radial-gradient(1100px 540px at -10% -20%, rgba(109, 126, 255, 0.35), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(168, 85, 247, 0.30), transparent 55%),
    linear-gradient(135deg, #0d1226 0%, #1a2447 130%);
  color: #fff;
  padding: 50px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
}
.login-brand .brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(255,255,255,0.18);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.login-pitch h2 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
  color: #fff;
}
.login-pitch p {
  font-size: 15px;
  opacity: 0.85;
  line-height: 1.6;
  max-width: 420px;
}
.login-pitch ul {
  list-style: none;
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-pitch li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  opacity: 0.9;
}
.login-pitch li::before { content: "✓"; opacity: 0.9; }
.login-foot { font-size: 12px; opacity: 0.7; }

.login-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 50px;
  background: var(--c-bg);
}
.login-card { width: 100%; max-width: 380px; }
.login-card h1 {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  color: var(--c-text);
}
.login-card .subtitle {
  color: var(--c-text-muted);
  margin-bottom: 26px;
}
.login-error {
  background: var(--c-error-soft);
  color: var(--c-error-text);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: var(--fs-sm);
  margin-bottom: 14px;
  border: 1px solid var(--c-error);
}

/* ---- 13. Responsive --------------------------------------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--c-side-divider);
  }
  .sidebar-brand { border-bottom: none; padding: 14px; flex-shrink: 0; }
  .sidebar-section { display: none; }
  .sidebar-foot { display: none; }
  .content { padding: 18px; }
  .login-shell { grid-template-columns: 1fr; }
  .login-side { padding: 30px; }
  .login-form-wrap { padding: 30px; }
}

/* ---- 14. Print overrides ---------------------------------- *
 * Receipts (worker/sale-summary.php) and labels
 * (worker/print_label.php) need black-ink-on-white-paper. We
 * force the light scheme + hide the sidebar in print media.
 */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
    padding: 0 !important;
  }
  .app-shell, .sidebar, .legacy-sidebar { display: none !important; }
  .content { padding: 0 !important; max-width: 100% !important; }
  .card, .kpi {
    background: #fff !important;
    border-color: #e0e0e0 !important;
    box-shadow: none !important;
  }
  .table {
    background: #fff !important;
    border-color: #e0e0e0 !important;
  }
  .table th { background: #f5f5f5 !important; color: #555 !important; }
  .table td, .table th { color: #000 !important; border-color: #e0e0e0 !important; }
  .input, .select, .textarea {
    background: #fff !important;
    border-color: #ccc !important;
    color: #000 !important;
  }
  a { color: #0066cc !important; }
  /* Pills get printed as plain text on light pastel — readable
     when photocopied. */
  .pill { background: #f0f0f0 !important; color: #333 !important; }
  .pill-success { background: #d1fae5 !important; color: #065f46 !important; }
  .pill-warn    { background: #fef3c7 !important; color: #78350f !important; }
  .pill-error   { background: #fee2e2 !important; color: #7f1d1d !important; }
  .pill-info    { background: #dbeafe !important; color: #1e3a8a !important; }
}
