/* =========================================================================
   TEHRAN NOIR — Proxify Operator Console
   A dark, refined admin theme with saffron accents and monospace numerics.
   RTL-aware throughout via CSS logical properties.
   ========================================================================= */

/* Self-hosted Persian font (variable) — works without Google Fonts.
   Vazirmatn by Saber Rastikerdar, OFL licensed. */
@font-face {
  font-family: 'Vazirmatn';
  src: url('/static/fonts/Vazirmatn.woff2') format('woff2-variations'),
       url('/static/fonts/Vazirmatn.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* Latin fallbacks load from Google Fonts only if reachable; safe to fail. */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Manrope:wght@400;500;600;700&display=swap');

:root {
  /* Surfaces */
  --bg-base:   #0e1014;
  --bg-elev:   #15181f;
  --bg-elev-2: #1c2028;
  --bg-soft:   #0a0c10;
  --bg-soft-2: #060709;

  /* Ink */
  --ink:    #e8e6e0;
  --ink-2:  #a39e94;
  --ink-3:  #74716a;
  --ink-4:  #4d4a44;

  /* Rules */
  --rule:   #232730;
  --rule-2: #2c3140;
  --rule-3: #3a3f4c;

  /* Brand — saffron / muted gold */
  --accent:        #d4a456;
  --accent-glow:   #efc06d;
  --accent-deep:   #b8893a;
  --accent-soft:   rgba(212,164,86,.12);
  --accent-soft-2: rgba(212,164,86,.22);

  /* Semantic */
  --ok:        #6fb587;
  --ok-soft:   rgba(111,181,135,.14);
  --bad:       #d97070;
  --bad-soft:  rgba(217,112,112,.14);
  --info:      #7aa3c8;
  --info-soft: rgba(122,163,200,.14);
  --warn:      #d4a456;
  --warn-soft: rgba(212,164,86,.16);
  --plum:      #c89bd5;
  --plum-soft: rgba(200,155,213,.14);

  /* Layout */
  --radius:     10px;
  --radius-sm:  6px;
  --radius-lg:  16px;
  --header-h:   56px;
  --side-w:     264px;

  /* Typography */
  --font-sans: 'Vazirmatn', 'Manrope', 'IRANSans', Tahoma, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'Menlo', monospace;

  /* Shadows */
  --shadow-sm: 0 1px 0 rgba(255,255,255,.02), 0 1px 2px rgba(0,0,0,.4);
  --shadow:    0 10px 28px rgba(0,0,0,.45), 0 1px 0 rgba(255,255,255,.03) inset;
  --shadow-lg: 0 30px 60px rgba(0,0,0,.7);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: dark; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  font-feature-settings: 'ss01', 'cv11';
  min-height: 100vh;
  background-image:
    radial-gradient(60% 40% at 88% -10%, rgba(212,164,86,.08), transparent 60%),
    radial-gradient(50% 50% at -10% 110%, rgba(122,163,200,.05), transparent 60%);
  background-attachment: fixed;
}

/* faint film-grain overlay for depth — pure CSS, no extra requests */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .35;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* IMPORTANT: don't set z-index on .app — that would create a stacking context
   that traps the .sidebar (z-999) below the .scrim (z-998), since stacking-
   context children can never escape their parent context. .app uses
   position:relative (without z-index) so it stays above body::before noise
   without forming a new stacking context. */
.app, .login-shell { position: relative; }
.topbar { z-index: 40; }   /* sticky topbar */

a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-glow); }

::selection { background: var(--accent-soft-2); color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-soft); }
::-webkit-scrollbar-thumb {
  background: var(--rule-2);
  border-radius: 5px;
  border: 2px solid var(--bg-soft);
}
::-webkit-scrollbar-thumb:hover { background: var(--accent-deep); }

/* =========================================================================
   TYPOGRAPHY
   ========================================================================= */

h1, h2, h3, h4 { color: var(--ink); margin: 0 0 .8em; letter-spacing: -0.01em; }
h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  display: flex;
  align-items: center;
  gap: 14px;
}
h1::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to var(--end-side, right), var(--rule), transparent);
  max-width: 120px;
}
h2 {
  font-size: 17px;
  font-weight: 600;
  margin-top: 32px;
  color: var(--ink);
}
h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-2);
  margin-bottom: 14px;
}

p { margin: 0 0 8px; color: var(--ink-2); }
.muted { color: var(--ink-3); font-size: 13px; }
strong { color: var(--ink); font-weight: 600; }

code {
  font-family: var(--font-mono);
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  padding: 2px 7px;
  font-size: 12px;
  border-radius: 4px;
  color: var(--accent-glow);
  font-feature-settings: 'tnum';
}

small { font-size: 12px; color: var(--ink-3); }

/* =========================================================================
   APP SHELL — sidebar + content + responsive drawer
   ========================================================================= */

.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────── */

.sidebar {
  background: var(--bg-soft);
  border-inline-end: 1px solid var(--rule);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 22px 18px 18px;
  z-index: 5;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 6px 22px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 14px;
}
.sb-logo {
  width: 42px; height: 42px;
  border-radius: 11px;
  background: linear-gradient(180deg, var(--accent-glow), var(--accent-deep));
  color: #1a1206;
  font-weight: 800;
  font-size: 22px;
  line-height: 1;
  display: grid;
  place-items: center;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.35),
    inset 0 -1px 0 rgba(0,0,0,.2),
    0 6px 18px rgba(212,164,86,.25);
  flex-shrink: 0;
}
.sb-titles { line-height: 1.2; min-width: 0; }
.sb-title { color: var(--ink); font-weight: 700; font-size: 14px; }
.sb-sub {
  color: var(--ink-3);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  margin-top: 3px;
  font-family: var(--font-mono);
}

.sb-section-label {
  font-size: 9.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink-4);
  padding: 16px 12px 8px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.sb-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
}
.sb-nav a {
  position: relative;
  color: var(--ink-2);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 11px;
  transition: color .15s, background .15s;
}
.sb-nav a > span:first-child {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  filter: saturate(.85);
}
.sb-nav a:hover {
  color: var(--ink);
  background: var(--bg-elev);
}
.sb-nav a.active {
  color: var(--ink);
  background: var(--accent-soft);
}
.sb-nav a.active::before {
  content: "";
  position: absolute;
  inset-inline-start: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 12px var(--accent-soft-2);
}
.sb-nav a.active > span:first-child { filter: none; }

.sb-foot {
  margin-top: 14px;
  padding: 14px;
  background: var(--bg-soft-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.sb-user {
  display: flex; gap: 10px; align-items: center; margin-bottom: 12px;
}
.sb-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--accent-deep);
  color: var(--accent-glow);
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.sb-user > div { min-width: 0; line-height: 1.2; }
.sb-username {
  font-size: 13px; color: var(--ink); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-role {
  font-size: 9.5px; color: var(--ink-3);
  letter-spacing: .14em; text-transform: uppercase;
  font-family: var(--font-mono);
  margin-top: 2px;
}
.sb-logout {
  display: flex;
  align-items: center; justify-content: center; gap: 6px;
  padding: 9px;
  font-size: 12px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm);
  width: 100%;
  transition: all .15s;
}
.sb-logout:hover {
  color: var(--bad);
  border-color: rgba(217,112,112,.4);
  background: var(--bad-soft);
}

/* ─── Mobile topbar + drawer ──────────────────────────────────────────── */

.topbar {
  display: none;
  position: sticky; top: 0;
  z-index: 40;
  background: rgba(14,16,20,.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--rule);
  padding: 0 16px;
  height: var(--header-h);
  align-items: center;
  gap: 12px;
}
.tb-brand-mini {
  display: flex; align-items: center; gap: 10px;
}
.tb-logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--accent-glow), var(--accent-deep));
  color: #1a1206;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
}
.tb-title {
  font-weight: 700; font-size: 13px; color: var(--ink);
  letter-spacing: .04em;
}
.tb-spacer { flex: 1; }

.menu-btn {
  background: transparent;
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm);
  width: 36px; height: 36px;
  color: var(--ink);
  display: grid; place-items: center;
  cursor: pointer;
  transition: all .15s;
}
.menu-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.scrim {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 998;
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0;
    inset-inline-start: 0;     /* RTL: anchored to right edge */
    width: 280px;
    transform: translateX(100%);   /* hidden off-screen to the right */
    transition: transform .32s cubic-bezier(.2,.85,.25,1);
    box-shadow: -20px 0 50px rgba(0,0,0,.5);
    z-index: 999;
  }
  body.sidebar-open { overflow: hidden; }   /* prevent body scroll behind drawer */
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .scrim { display: block; }
  .content { padding: 22px 18px 80px !important; }
}

/* ─── Content ─────────────────────────────────────────────────────────── */

.content {
  position: relative;
  padding: 36px 40px 80px;
  min-width: 0;
}
.content > * {
  animation: fade-up .5s cubic-bezier(.2,.7,.2,1) both;
}
.content > *:nth-child(1) { animation-delay: .04s; }
.content > *:nth-child(2) { animation-delay: .10s; }
.content > *:nth-child(3) { animation-delay: .16s; }
.content > *:nth-child(4) { animation-delay: .22s; }
.content > *:nth-child(5) { animation-delay: .28s; }
.content > *:nth-child(6) { animation-delay: .34s; }
.content > *:nth-child(n+7) { animation-delay: .38s; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================================================================
   GRID & STAT CARDS
   ========================================================================= */

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  position: relative;
}
.card h3 {
  border-bottom: 1px dashed var(--rule);
  padding-bottom: 12px;
  margin-bottom: 16px;
  margin-top: 0;
}
.card-flat {
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color .2s, transform .2s;
}
.stat:hover {
  border-color: var(--rule-3);
  transform: translateY(-1px);
}
.stat::before {
  content: "";
  position: absolute;
  inset-inline-start: 0; top: 0;
  width: 38px; height: 2px;
  background: var(--ink-4);
}
.stat::after {
  content: "";
  position: absolute;
  inset-inline-end: 16px;
  top: 18px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-4);
  box-shadow: 0 0 8px currentColor;
  opacity: .6;
}
.stat .label {
  color: var(--ink-3);
  font-size: 10.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 14px;
  font-family: var(--font-mono);
}
.stat .value {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  font-size: 30px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
  letter-spacing: -.01em;
}
.stat.accent::before, .stat.warn::before  { background: var(--accent); }
.stat.success::before                     { background: var(--ok); }
.stat.info::before                        { background: var(--info); }
.stat.accent::after, .stat.warn::after    { background: var(--accent); }
.stat.success::after                      { background: var(--ok); }
.stat.info::after                         { background: var(--info); }

/* =========================================================================
   TABLES
   ========================================================================= */

.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;            /* clip rounded corners */
  margin-bottom: 16px;
}
/* horizontal scroll for very wide tables on mobile */
.table-wrap > table {
  min-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 14px 16px;
  text-align: start;
  vertical-align: middle;
  font-size: 13px;
  border-bottom: 1px solid var(--rule);
}
tr:last-child td { border-bottom: none; }
th {
  background: var(--bg-soft);
  color: var(--ink-3);
  font-weight: 700;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-family: var(--font-mono);
  white-space: nowrap;
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(212,164,86,.04); }
td code {
  background: var(--bg-soft);
  border-color: var(--rule);
  font-size: 11.5px;
}
td strong { color: var(--ink); }

/* responsive: enable horizontal scroll on cramped viewports */
@media (max-width: 800px) {
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap > table { min-width: 720px; }
  th, td { padding: 12px 12px; }
}

/* =========================================================================
   FORMS
   ========================================================================= */

input[type=text], input[type=number], input[type=password], input[type=email],
input[type=search], textarea, select {
  width: auto;
  padding: 10px 13px;
  font-family: inherit;
  font-size: 13px;
  background: var(--bg-soft);
  color: var(--ink);
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input::placeholder, textarea::placeholder { color: var(--ink-4); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-elev);
}
input[type=number] {
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
}
textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  line-height: 1.6;
}
select {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  /* chevron */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
    linear-gradient(-45deg, transparent 50%, var(--ink-2) 50%);
  background-position:
    calc(0% + 14px) center,
    calc(0% + 19px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-start: 32px;
}

.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  margin-bottom: 6px;
  font-size: 10.5px;
  color: var(--ink-3);
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 700;
  font-family: var(--font-mono);
}
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
}
.form-row small {
  display: block;
  margin-top: 6px;
  color: var(--ink-3);
  font-size: 11px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* =========================================================================
   BUTTONS
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-2);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  text-decoration: none;
  line-height: 1;
  white-space: nowrap;
}
.btn:hover {
  border-color: var(--ink-3);
  background: var(--bg-elev-2);
  color: var(--ink);
}
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  color: #1a1206;
  border-color: var(--accent);
  font-weight: 700;
}
.btn.primary:hover {
  background: var(--accent-glow);
  border-color: var(--accent-glow);
  color: #1a1206;
  box-shadow: 0 6px 22px rgba(212,164,86,.25);
}
.btn.success {
  color: var(--ok);
  border-color: rgba(111,181,135,.35);
  background: var(--ok-soft);
}
.btn.success:hover {
  background: rgba(111,181,135,.22);
  border-color: var(--ok);
  color: var(--ok);
}
.btn.danger {
  color: var(--bad);
  border-color: rgba(217,112,112,.35);
  background: var(--bad-soft);
}
.btn.danger:hover {
  background: rgba(217,112,112,.22);
  border-color: var(--bad);
  color: var(--bad);
}
.btn.muted { color: var(--ink-3); }
.btn.sm { padding: 6px 11px; font-size: 12px; gap: 6px; }
.btn.block {
  display: flex;
  width: 100%;
  padding: 12px;
  font-weight: 700;
  letter-spacing: .04em;
}

form.inline { display: inline-block; margin: 0; }

/* =========================================================================
   BADGES
   ========================================================================= */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 10.5px;
  letter-spacing: .1em;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--bg-elev-2);
  color: var(--ink-2);
  border: 1px solid var(--rule-2);
  font-family: var(--font-mono);
  white-space: nowrap;
}
.badge::before {
  content: "";
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 6px currentColor;
}
.badge.pending  { color: var(--warn); background: var(--warn-soft); border-color: rgba(212,164,86,.30); }
.badge.approved { color: var(--ok);   background: var(--ok-soft);   border-color: rgba(111,181,135,.30); }
.badge.rejected,
.badge.banned   { color: var(--bad);  background: var(--bad-soft);  border-color: rgba(217,112,112,.30); }
.badge.active,
.badge.open     { color: var(--info); background: var(--info-soft); border-color: rgba(122,163,200,.30); }
.badge.inactive,
.badge.closed   { color: var(--ink-3); background: var(--bg-elev-2); border-color: var(--rule-2); }
.badge.purpose-order        { color: var(--accent-glow); background: var(--accent-soft); border-color: rgba(212,164,86,.28); }
.badge.purpose-wallet_topup { color: var(--plum);        background: var(--plum-soft);   border-color: rgba(200,155,213,.28); }

/* =========================================================================
   TOOLBAR / FLASH
   ========================================================================= */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  padding: 12px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.toolbar form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0;
}
.toolbar label {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .12em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.spacer { flex: 1; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.flash, .error {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 13px;
  border: 1px solid;
  display: flex;
  align-items: center;
  gap: 10px;
}
.flash {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: rgba(111,181,135,.3);
}
.flash::before { content: "✓"; font-weight: 700; }
.error {
  background: var(--bad-soft);
  color: var(--bad);
  border-color: rgba(217,112,112,.3);
}
.error::before { content: "!"; font-weight: 700; font-family: var(--font-mono); }

/* =========================================================================
   CHAT THREAD (support_user.html)
   ========================================================================= */

.chat {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 8px 4px;
  margin: 18px 0;
}
.msg {
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  padding: 14px 16px;
  border-radius: 14px;
  max-width: 76%;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.msg-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 11px;
}
.msg-from {
  font-weight: 800;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.msg-meta .muted { font-size: 11px; }
.msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  color: var(--ink);
}
.msg-user {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(122,163,200,.10), rgba(122,163,200,.02));
  border-color: rgba(122,163,200,.28);
  border-end-end-radius: 4px;
}
.msg-user .msg-from { color: var(--info); }
.msg-admin {
  align-self: flex-start;
  background: linear-gradient(180deg, rgba(212,164,86,.10), rgba(212,164,86,.02));
  border-color: rgba(212,164,86,.28);
  border-end-start-radius: 4px;
}
.msg-admin .msg-from { color: var(--accent); }
.msg-pending {
  align-self: flex-start;
  max-width: 60%;
  background: transparent;
  border: 1px dashed var(--rule-2);
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-3);
  font-size: 12px;
  letter-spacing: .04em;
}

@media (max-width: 720px) {
  .msg { max-width: 92%; }
  .msg-pending { max-width: 80%; }
}

/* =========================================================================
   RECEIPT THUMBNAIL
   ========================================================================= */

.receipt-thumb {
  display: inline-block;
  width: 56px; height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--rule-2);
  background: var(--bg-soft);
  transition: border-color .15s, transform .15s, box-shadow .15s;
  flex-shrink: 0;
}
.receipt-thumb:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.receipt-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  cursor: zoom-in;
}

/* =========================================================================
   MODAL DIALOG
   ========================================================================= */

dialog.modal {
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 0;
  width: 480px;
  max-width: calc(100vw - 24px);
  background: var(--bg-elev);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  margin: auto;
  /* subtle glow */
  outline: 1px solid rgba(212,164,86,.06);
  outline-offset: -1px;
}
dialog.modal::backdrop {
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
dialog.modal[open] {
  animation: pop .25s cubic-bezier(.2,.85,.25,1) both;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
dialog.modal .modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--rule);
}
dialog.modal .modal-head h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--accent);
  border: none;
  padding: 0;
}
dialog.modal .modal-body { padding: 22px; }
dialog.modal .modal-body .card-flat,
dialog.modal .modal-body p { color: var(--ink-2); }
dialog.modal .modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--rule);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: var(--bg-soft);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
dialog.modal .modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--ink-3);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}
dialog.modal .modal-close:hover {
  color: var(--bad);
  background: var(--bad-soft);
}

/* =========================================================================
   LOGIN — full-screen cinematic
   ========================================================================= */

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-base);
  position: relative;
  overflow: hidden;
}
.login-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(70% 50% at 75% 25%, rgba(212,164,86,.22), transparent 65%),
    radial-gradient(80% 60% at -10% 95%, rgba(122,163,200,.10), transparent 70%);
  pointer-events: none;
  z-index: 1;
}
.login-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(90deg, transparent 0 119px, rgba(255,255,255,.025) 120px),
    repeating-linear-gradient(0deg,  transparent 0 119px, rgba(255,255,255,.018) 120px);
  pointer-events: none;
  z-index: 1;
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
          mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

.login-card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 420px;
  background: rgba(20,23,30,.82);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 44px 38px 32px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  animation: rise .8s cubic-bezier(.2,.9,.3,1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(24px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.login-logo {
  width: 64px; height: 64px;
  margin: 0 auto 20px;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--accent-glow), var(--accent-deep));
  color: #1a1206;
  display: grid; place-items: center;
  font-weight: 800; font-size: 28px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.4),
    inset 0 -1px 0 rgba(0,0,0,.2),
    0 14px 38px rgba(212,164,86,.32);
}
.login-card h1 {
  text-align: center;
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: -.01em;
  display: block;
}
.login-card h1::after { display: none; }
.login-card .muted {
  text-align: center;
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 28px;
  font-family: var(--font-mono);
}
.login-card form { text-align: start; }
.login-card label {
  display: block;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 700;
  margin-bottom: 14px;
  font-family: var(--font-mono);
}
.login-card label input {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 12px 14px;
  font-size: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--rule-2);
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  letter-spacing: 0;
  text-transform: none;
  font-weight: 500;
}
.login-card label input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-soft-2);
}
.login-card .btn.block {
  margin-top: 6px;
}
.login-foot {
  display: block;
  text-align: center;
  margin-top: 26px;
  font-size: 10px;
  color: var(--ink-4);
  letter-spacing: .18em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.login-foot::before {
  content: "";
  display: block;
  width: 28px; height: 1px;
  background: var(--rule-2);
  margin: 0 auto 14px;
}

/* =========================================================================
   TABS (settings page)
   ========================================================================= */

.tabs {
  display: flex;
  gap: 4px;
  padding: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 9px 14px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-3);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab:hover {
  color: var(--ink);
  background: var(--bg-elev-2);
}
.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: rgba(212,164,86,.25);
  font-weight: 600;
}

.tab-panel { display: none; }
.tab-panel.active {
  display: block;
  animation: fade-up .35s ease both;
}

.settings-foot {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background:
    linear-gradient(0deg, var(--bg-base) 70%, transparent);
  padding: 18px 0 8px;
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}
.settings-foot .save-hint {
  color: var(--ink-3);
  font-size: 11.5px;
  letter-spacing: .08em;
  font-family: var(--font-mono);
}

/* =========================================================================
   SETTINGS NOTE — informational callout box used inside settings cards
   ========================================================================= */

.note {
  display: flex;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 12.5px;
  margin-bottom: 16px;
  align-items: flex-start;
}
.note .note-icon {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 6px;
  display: grid; place-items: center;
  font-weight: 700;
  font-family: var(--font-mono);
}
.note.warn {
  background: var(--warn-soft);
  border-color: rgba(212,164,86,.28);
  color: var(--accent-glow);
}
.note.warn .note-icon {
  background: rgba(212,164,86,.2);
  color: var(--accent-glow);
}
.note.info {
  background: var(--info-soft);
  border-color: rgba(122,163,200,.28);
  color: var(--info);
}
.note.info .note-icon {
  background: rgba(122,163,200,.2);
  color: var(--info);
}
.note code {
  background: rgba(0,0,0,.25);
  border-color: rgba(255,255,255,.1);
  color: inherit;
  font-size: 11.5px;
}

/* =========================================================================
   FIELDSET — multi-config slots in approve modal
   ========================================================================= */

fieldset.cfg-slot {
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 14px 16px 6px;
  margin: 0 0 14px;
  background: var(--bg-soft);
  position: relative;
}
fieldset.cfg-slot legend {
  padding: 2px 10px;
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--bg-elev);
  border: 1px solid var(--rule);
  border-radius: 999px;
}
fieldset.cfg-slot.sent {
  background: var(--bg-soft-2);
  opacity: .7;
  border-style: dashed;
}
fieldset.cfg-slot.sent legend {
  color: var(--ok);
}
fieldset.cfg-slot textarea[disabled],
fieldset.cfg-slot input[disabled] {
  background: var(--bg-soft-2);
  color: var(--ink-4);
  cursor: not-allowed;
}

/* =========================================================================
   UTILITIES & SMALL-VIEWPORT REFINEMENTS
   ========================================================================= */

.inline { display: inline-block; }
hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 22px 0;
}

details > summary { cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }

@media (max-width: 720px) {
  .toolbar { padding: 10px 12px; }
  .stat .value { font-size: 24px; }
  .stat { padding: 18px; }
  .card { padding: 18px; }
  h1 { font-size: 19px; }
  h2 { font-size: 15px; }
  dialog.modal { width: calc(100vw - 24px); }
  dialog.modal .modal-body,
  dialog.modal .modal-foot,
  dialog.modal .modal-head { padding-inline: 18px; }
}

@media (max-width: 480px) {
  .content { padding: 18px 14px 60px !important; }
  .row-actions { width: 100%; }
  .row-actions .btn { flex: 1; min-width: 0; }
}

/* Hide pure-decorative ::after of stat cards on tiny widths to reduce visual noise */
@media (max-width: 380px) {
  .stat::after { display: none; }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
