/* styles.css — Main stylesheet for Tether Dashboard */
/* Supports Light/Dark mode, RTL, Responsive */

/* ── CSS Variables ── */
:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --surface-3: #e8e5de;
  --border: #d9d6cf;
  --text: #241f19;
  --muted: #736f68;
  --primary: #0d6d73;
  --primary-2: #ececec;
  --primary-dark: #095358;
  --success: #3d7a2a;
  --success-bg: #e8f5e2;
  --danger: #a13d55;
  --danger-bg: #fde8ed;
  --warning: #a06717;
  --warning-bg: #fef3e2;
  --shadow: 0 8px 24px rgba(25,20,10,.08);
  --shadow-lg: 0 16px 40px rgba(25,20,10,.14);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --sidebar-width: 380px;
  --header-h: 60px;
  --transition: 0.2s ease;
  --bid-color: #1a6b3c;
  --bid-bg: #e6f4ec;
  --ask-color: #a13d55;
  --ask-bg: #fde8ed;
  --ob-bar-bid: rgba(26,107,60,.18);
  --ob-bar-ask: rgba(161,61,85,.18);
  --text-muted: #888;
  --ring: rgba(13,109,115,.28);
  --primary-soft: rgba(13,109,115,.10);
  --maxw: 1440px;
  --bottomnav-h: 62px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111418;
  --surface: #1a1f26;
  --surface-2: #222831;
  --surface-3: #2c3340;
  --border: #353c47;
  --text: #e8e6e1;
  --muted: #8a8f98;
  --primary: #19a1a9;
  --primary-2: #2a2e36;
  --primary-dark: #22bcc5;
  --success: #4caf6a;
  --success-bg: #0d2b18;
  --danger: #e05577;
  --danger-bg: #2b0f18;
  --warning: #e0973a;
  --warning-bg: #2b1e08;
  --shadow: 0 8px 24px rgba(0,0,0,.3);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.4);
  --bid-color: #4caf6a;
  --bid-bg: #0d2b18;
  --ask-color: #e05577;
  --ask-bg: #2b0f18;
  --ob-bar-bid: rgba(76,175,106,.2);
  --ob-bar-ask: rgba(224,85,119,.2);
  --text-muted: #8a8f98;
  --ring: rgba(34,188,197,.34);
  --primary-soft: rgba(34,188,197,.14);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Vazirmatn', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
}
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; }
input, select, textarea, button {
  font-family: inherit;
  font-size: .94rem;
  color: var(--text);
}

/* ── App Layout ── */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.app-topbar-logo {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
}
.app-topbar-spacer { flex: 1; }
.app-topbar-actions { display: flex; gap: 10px; align-items: center; }

.app-body {
  display: flex;
  flex: 1;
  gap: 0;
  position: relative;
}

/* ── Sidebar (Order Book) ── */
.ob-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
}
.ob-sidebar.collapsed {
  width: 48px;
  min-width: 48px;
}
.ob-sidebar.collapsed .ob-content { display: none; }

.ob-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  gap: 10px;
  min-height: 54px;
}
.ob-sidebar-title {
  font-size: .95rem;
  font-weight: 700;
  white-space: nowrap;
}
.ob-sidebar-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ob-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  min-width: 0;
}

/* ── Topbar Navigation Tabs ── */
.nav-tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.nav-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: var(--radius-xs);
  font-size: .9rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition);
}
.nav-tab:hover { background: var(--surface-2); color: var(--text); }
.nav-tab.active {
  background: var(--surface-3);
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
}

/* ── Page Sections ── */
.page-section { display: none; }
.page-section.active { display: block; }

/* ── Original Dashboard Styles (preserved) ── */
.wrap {
  width: 100%;
  margin: 0 auto 32px;
}
.header {
  display: grid;
  grid-template-columns: 1.2fr .8fr;
  gap: 16px;
  align-items: stretch;
  margin-bottom: 16px;
}
.hero, .panel, .table-card, .form-card, .note {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero {
  padding: 22px;
  background: var(--surface);
}
.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(1.4rem, 2vw, 2rem);
  color: var(--text);
}
.hero p { margin: 0; color: var(--muted); }
.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.mini {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.mini b { display:block; font-size: .84rem; color: var(--muted); margin-bottom: 4px; }
.mini span { font-size: 1rem; font-weight: 700; }
.panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.status-box { display: grid; gap: 10px; }
.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 12px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.status-item span { color: var(--muted); font-size: .9rem; }
.status-item strong { font-size: 1rem; }
.grid-main {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 16px;
  align-items: start;
}
.stack { display: grid; gap: 16px; }
.form-card, .table-card, .note { padding: 16px; }
h2, h3 { margin: 0 0 12px; font-size: 1.05rem; }
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.tab-btn, .btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: .92rem;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tab-btn:hover, .btn:hover { background: var(--surface-3); }
.tab-btn.active, .btn.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn.ghost { background: transparent; }
.btn.danger-btn { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.tab-content { display: none; }
.tab-content.active { display: block; }
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.field { display: grid; gap: 6px; }
.field.full { grid-column: 1 / -1; }
label { font-size: .85rem; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
option {
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border);
  box-shadow: 0 0 0 2px rgba(0,0,0,.08);
}
textarea { min-height: 84px; resize: vertical; }
.helper {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
}
.table-head {
  display:flex; justify-content:space-between; align-items:center; gap:10px; margin-bottom:10px;
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: top;
}
th { color: var(--muted); font-weight: 700; background: var(--surface-2); }
.table-card tr:hover td { background: var(--surface-2); }
.rpt-result tr:hover td { background: var(--surface-2); }
.scroll { overflow:auto; }
.split { display:grid; grid-template-columns: 1fr 1fr; gap:16px; }
.empty {
  padding: 20px; text-align:center; color:var(--muted);
  background: var(--surface-2); border:1px dashed var(--border); border-radius:14px;
}

/* ── Order Book Card ── */
.ob-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.ob-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.ob-exchange-name {
  font-weight: 700;
  font-size: .9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ob-status {
  font-size: .76rem;
  color: var(--muted);
  white-space: nowrap;
}
.ob-spread-info {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
  font-size: .78rem;
  flex-wrap: wrap;
}
.ob-spread-item { display: flex; gap: 4px; }
.ob-spread-item span { color: var(--muted); }
.ob-tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.ob-table-section { padding: 8px; }
.ob-table-section:first-child {
  border-left: 1px solid var(--border);
}
.ob-table-label {
  font-size: .76rem;
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 6px;
}
.ob-table-label.bids { color: var(--bid-color); background: var(--bid-bg); }
.ob-table-label.asks { color: var(--ask-color); background: var(--ask-bg); }
.ob-error { padding: 16px; text-align: center; color: var(--danger); font-size: .82rem; }
.ob-loading { padding: 16px; text-align: center; color: var(--muted); font-size: .82rem; }
.ob-refresh-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: .76rem;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition);
}
.ob-refresh-btn:hover { background: var(--surface-2); color: var(--primary); }

/* Sidebar toggle button */
.sidebar-toggle-btn {
  background: none;
  border: none;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.sidebar-toggle-btn:hover { background: var(--surface-2); color: var(--primary); }

/* Refresh interval select */
.ob-interval-select {
  font-size: .78rem;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* ── Export Modal ── */
.export-field-checkboxes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
}
.export-field-cb {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface-2);
  font-size: .85rem;
}
.export-field-cb input[type=checkbox] { width: auto; }

/* ── Reports Section ── */
.reports-container { display: flex; flex-direction: column; gap: 16px; }
.reports-filters-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.reports-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.report-filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 140px;
  flex: 1;
}
.report-filter-group label { font-size: .8rem; color: var(--muted); }
.rpt-summary-cards {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.rpt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}
.rpt-card span { font-size: .8rem; color: var(--muted); }
.rpt-card strong { font-size: 1rem; font-weight: 700; }
.rpt-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.rpt-arb-banner {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.rpt-arb-item { display: flex; flex-direction: column; gap: 4px; }
.rpt-arb-item span { font-size: .8rem; color: var(--muted); }
.rpt-arb-item strong { font-size: 1.1rem; }
.loading-spinner {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  animation: pulse 1.5s infinite;
}

/* ── DB Panel ── */
.db-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.db-health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.db-health-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.db-health-item .dh-label { font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.db-health-item .dh-value { font-size: 1.1rem; font-weight: 700; }

/* ── Dark Mode Toggle ── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  font-size: .84rem;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* ── Utility ── */
.text-sm { font-size: .85rem; }
.text-xs { font-size: .78rem; }

/* ── Responsive ── */
@media (max-width: 1300px) {
  :root { --sidebar-width: 320px; }
}
@media (max-width: 1100px) {
  .ob-sidebar { position: fixed; right: 0; top: var(--header-h); bottom: 0; z-index: 50; transform: translateX(100%); }
  .ob-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .header, .grid-main, .split, .kpis { grid-template-columns: 1fr 1fr; }
  .grid-main { grid-template-columns: 1fr; }
  .ob-tables { grid-template-columns: 1fr; }
  .ob-table-section:first-child { border-left: none; border-bottom: 1px solid var(--border); }
}
@media (max-width: 700px) {
  .header, .kpis, .hero-grid, .field-grid, .split { grid-template-columns: 1fr; }
  .main-content { padding: 12px; }
  .reports-filter-row { flex-direction: column; }
  .nav-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .export-field-checkboxes { grid-template-columns: 1fr; }
}


/* ══════════════════════════════════════════════════════════════
   NEW MODULAR STYLES (v2)
══════════════════════════════════════════════════════════════ */

/* ── Page sections (tabs) ── */
.page-section { display: none; padding: 24px; }
.page-section.active { display: block; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 20px; }
.card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.card-header h2 { margin: 0; font-size: 1.1rem; }
.card-wide { grid-column: 1 / -1; }

/* ── Dashboard grid ── */
.dash-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* ── Trade input ── */
.field-group { display: flex; flex-direction: column; gap: 12px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.select-full { flex: 1; }
.icon-btn { padding: 8px 12px; font-size: 1.1rem; font-weight: 700; }
.trade-id-preview { background: var(--surface-2); border: 1px dashed var(--border); border-radius: var(--radius-xs); padding: 10px 14px; font-size: .85rem; color: var(--muted); text-align: center; margin: 8px 0; }
.trade-id-badge { color: var(--primary); font-size: .9rem; }

/* ── Open trades list ── */
.open-trades-list { display: flex; flex-direction: column; gap: 8px; max-height: 68vh; overflow-y: auto; }
.trade-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-xs); cursor: pointer; transition: background .15s; }
.trade-row:hover { background: var(--surface-3); }
.trade-id { font-family: monospace; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.trade-info { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.trade-cp { font-weight: 600; }
.trade-date { font-size: .8rem; }
.trade-desc { font-size: .8rem; }
.trade-actions { display: flex; gap: 6px; flex-shrink: 0; }
.badge-count { background: var(--primary); color: #fff; border-radius: 99px; padding: 2px 8px; font-size: .8rem; }

/* ── Badges ── */

/* ── Buttons ── */
.btn.sm    { padding: 4px 10px; font-size: .8rem; }
.btn.wide  { width: 100%; justify-content: center; }
.btn.danger  { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.btn.success:hover { background: var(--success); color: #fff; }

/* ── Modal overlay ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.modal-overlay.hidden { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: 96vw; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); padding: 24px; }
.modal-box.modal-lg { max-width: 860px; }
.modal-header { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; padding: 20px 20px 0; }
.modal-body { padding: 16px 20px; }
.modal-footer { padding: 16px 20px; display: flex; gap: 10px; border-top: 1px solid var(--border); }
.modal-close { background: transparent; border: none; font-size: 1.2rem; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: var(--surface-2); }

/* ── Trade modal ── */
.tm-trade-info { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.trade-id-lg { font-family: monospace; font-size: 1.1rem; font-weight: 700; color: var(--primary); }
.docs-section { margin-bottom: 16px; }
.docs-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.docs-header h3 { margin: 0; }

/* ── Document card ── */
.doc-card { border: 1px solid var(--border); border-radius: var(--radius-xs); margin-bottom: 8px; overflow: hidden; }
.doc-card-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--surface-2); }
.doc-seq { font-weight: 700; color: var(--primary); font-size: .9rem; display: flex; align-items: center; gap: 8px; }
.doc-details { padding: 12px 14px; }
.doc-detail-row { display: flex; gap: 8px; padding: 4px 0; font-size: .88rem; border-bottom: 1px solid var(--border); }
.doc-detail-row:last-child { border-bottom: none; }
.doc-detail-row > span:first-child { color: var(--muted); min-width: 130px; flex-shrink: 0; }
.doc-detail-row > span:last-child { color: var(--text); word-break: break-all; }
.mono-sm { font-family: monospace; font-size: .82rem; }
.badge-pay { background: #fff3cd; color: #856404; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.badge-rec { background: #d1e7dd; color: #0a3622; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
[data-theme="dark"] .badge-pay { background: #3d2f00; color: #ffc107; }
[data-theme="dark"] .badge-rec { background: #0a2e1c; color: #75c795; }
.doc-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.doc-col { }
.col-label { font-weight: 700; font-size: .85rem; color: var(--muted); margin-bottom: 8px; }
.pay-col .col-label { color: var(--danger); }
.rec-col .col-label { color: var(--success); }
.doc-field { display: flex; gap: 6px; font-size: .85rem; margin-bottom: 4px; }
.doc-field span { color: var(--muted); white-space: nowrap; }
.check-icon { font-size: 1rem; }

/* ── Document form ── */
.doc-form { margin-top: 16px; border: 2px dashed var(--border); }
.doc-form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 12px 0; }
.doc-form-col { }

/* ── Invoice ── */
.invoice-modal { max-width: 760px; }
.invoice-header { padding-bottom: 16px; border-bottom: 2px solid var(--border); }
.invoice-title { font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.invoice-body { display: flex; flex-direction: column; gap: 16px; padding: 16px 0 0; }

/* خلاصه ۶ کارت */
.inv-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 4px;
}
.inv-summary-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 10px 14px;
}
.inv-summary-item.inv-warn    { border-color: var(--warning); background: var(--warning-bg); }
.inv-summary-item.inv-danger  { border-color: var(--danger);  background: var(--danger-bg);  }
.inv-summary-item.inv-success { border-color: var(--success); background: var(--success-bg); }
.inv-summary-label { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.inv-summary-value { font-size: 1rem; font-weight: 700; }

/* علت ناقص بودن */
.inv-reason-box {
  background: var(--warning-bg);
  border: 1px solid var(--warning);
  border-radius: var(--radius-xs);
  padding: 10px 14px;
  font-size: .88rem;
}
.inv-reason-label { font-weight: 700; color: var(--warning); margin-left: 6px; }
.inv-reason-text  { color: var(--text); }

/* جزئیات اسناد */
.inv-docs-wrap { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--border); margin-top: 4px; }
.invoice-col { padding: 14px 18px; }
.pay-col { border-left: 1px solid var(--border); background: rgba(161,61,85,.04); }
.rec-col { background: rgba(26,107,60,.04); }
.inv-row { padding: 7px 0; border-bottom: 1px solid var(--border); font-size: .87rem; }
.inv-total { margin-top: 10px; font-weight: 700; }

/* فرم علت ناقص */
.incomplete-form { border: 2px solid var(--warning) !important; }
.incomplete-summary { display: flex; flex-direction: column; gap: 6px; }
.inc-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 10px; border-radius: var(--radius-xs); background: var(--surface-2); font-size: .88rem; }
.inc-row.inc-row-warn    { background: var(--warning-bg); }
.inc-row.inc-row-danger  { background: var(--danger-bg);  }
.inc-row.inc-row-success { background: var(--success-bg); }
.inc-label { color: var(--muted); }
.inc-val   { font-weight: 700; }

/* ── Wallet module ── */
.wallet-layout { display: grid; grid-template-columns: 200px 1fr; gap: 20px; }
@media (max-width: 800px) { .wallet-layout { grid-template-columns: 1fr; } }
.wallet-sidebar { display: flex; flex-direction: column; gap: 4px; }
.wallet-type-tabs { display: flex; flex-direction: column; gap: 4px; }
.wtab { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 10px 14px; text-align: right; font-size: .9rem; }
.wtab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.summary-bar { display: flex; gap: 16px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 14px 18px; margin-bottom: 16px; }
.summary-item { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; }
.summary-item span { color: var(--muted); font-size: .78rem; }
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.account-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; background: var(--surface); }
.account-card.acct-bank     { border-top: 3px solid #2563eb; }
.account-card.acct-exchange { border-top: 3px solid #7c3aed; }
.account-card.acct-ledger   { border-top: 3px solid #16a34a; }
.acct-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.acct-icon { font-size: 1.4rem; }
.acct-name { font-weight: 700; }
.acct-type-label { font-size: .78rem; color: var(--muted); }
.acct-actions { margin-right: auto; display: flex; gap: 4px; }
.acct-balance { margin-bottom: 8px; }
.bal-row { display: flex; gap: 8px; font-size: .9rem; margin-bottom: 2px; }
.bal-row span { color: var(--muted); }
.acct-meta { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.limit-bar { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.limit-bar span { font-weight: 600; }

/* ── Slide panels ── */
.slide-panel { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; }
.slide-panel.hidden { display: none; }
.slide-panel-box { background: var(--surface); border-radius: var(--radius); padding: 24px; width: 96vw; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-header h3 { margin: 0; }

/* ── Reports ── */
.reports-layout { max-width: 1200px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-header h2 { margin: 0; }
.report-section { margin-bottom: 32px; }
.section-title { font-size: 1rem; font-weight: 700; color: var(--muted); margin: 0 0 12px; text-transform: uppercase; letter-spacing: .5px; }
.wallet-report { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.report-table th { background: var(--surface-2); padding: 8px 12px; text-align: right; border-bottom: 2px solid var(--border); white-space: nowrap; }
.report-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.report-table tr:hover td { background: var(--surface-2); }

/* ── Order Book 2×2 ── */
.ob-module-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.ob-module-header h2 { margin: 0; }
.ob-interval-sel { padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xs); }
.ob-grid-2x2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .ob-grid-2x2 { grid-template-columns: 1fr; } }
.ob-card-2x2 { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.ob-card-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-top: 3px solid transparent; background: var(--surface-2); }
.ob-best-prices { display: flex; gap: 20px; padding: 8px 14px; font-size: .85rem; font-weight: 600; border-bottom: 1px solid var(--border); }
.ob-tables-inline { display: grid; grid-template-columns: 1fr 1fr; }
.ob-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.ob-table th { padding: 6px 8px; background: var(--surface-2); text-align: right; color: var(--muted); font-size: .75rem; }
.ob-table td { padding: 4px 8px; }
.ob-price-bid { color: var(--bid-color); font-weight: 600; }
.ob-price-ask { color: var(--ask-color); font-weight: 600; }
.ob-vol { color: var(--muted); }
.ob-spread-chip { background: var(--surface-3); border-radius: 99px; padding: 2px 8px; font-size: .75rem; color: var(--muted); }
.ob-error-msg { padding: 16px; color: var(--danger); font-size: .85rem; }
.ob-loading-msg { padding: 16px; text-align: center; color: var(--muted); }
.ob-pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ── Status dots ── */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }
.dot-gray { background: var(--muted); }

/* ── Pos / Neg ── */
.pos { color: var(--success); }
.neg { color: var(--danger); }
.warn { color: var(--warning); }
.muted { color: var(--muted); }

/* ── Empty state ── */
.empty-state { padding: 32px; text-align: center; color: var(--muted); }
.empty-state.error { color: var(--danger); }

/* ── KPI cards ── */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; box-shadow: var(--shadow); transition: box-shadow var(--transition); }
.kpi:hover { box-shadow: var(--shadow-lg); }
.kpi .label { font-size: .78rem; color: var(--muted); margin-bottom: 4px; }
.kpi .value { font-size: 1.2rem; font-weight: 800; }
.kpi .sub { font-size: .75rem; color: var(--muted); margin-top: 4px; }

/* ── Print ── */
@media print {
  .ob-sidebar, .app-topbar, .btn, .tabs, .btn-row, .reports-filters-bar,
  .wallet-sidebar, .slide-panel, .modal-overlay { display: none !important; }
  .main-content { padding: 0; }
  body { background: white; color: black; }
  .kpi, .table-card, .form-card { box-shadow: none; border: 1px solid #ccc; }
  .invoice-modal { box-shadow: none; border: 1px solid #ccc; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   NEW TRADE FORM — full-width dashboard form
   ═══════════════════════════════════════════════════════════════════════════ */
.dash-new-trade-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 24px;
}
.dash-section-title {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 18px;
}
.dash-section-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.new-trade-form { display: flex; flex-direction: column; gap: 14px; }
.ntf-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.ntf-row-bottom { align-items: flex-end; }
.ntf-field { display: flex; flex-direction: column; gap: 5px; min-width: 160px; flex: 1; }
.ntf-field-wide { flex: 2; min-width: 240px; }
.ntf-field-grow { flex: 3; }
.ntf-field-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.ntf-field label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.ntf-input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--transition);
  width: 100%;
}
.ntf-input:focus { outline: none; border-color: var(--primary); }
.ntf-input.sm { padding: 6px 10px; font-size: .85rem; }
.ntf-select {
  padding: 9px 12px;
  padding-right: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  color: var(--text);
  flex: 1;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  outline: none;
}
.ntf-counterparty-wrap { display: flex; gap: 8px; align-items: center; }
.ntf-radio-group { display: flex; gap: 12px; padding: 6px 0; }
.ntf-radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition);
  font-weight: 600;
  font-size: .9rem;
}
.ntf-radio-label.buy:has(input:checked) { border-color: var(--success); background: var(--success-bg); color: var(--success); }
.ntf-radio-label.sell:has(input:checked) { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.ntf-radio-label input { accent-color: var(--primary); }
.ntf-submit { padding: 10px 28px; font-size: 1rem; }
.ntf-msg {
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-size: .88rem;
}
.ntf-msg.hidden { display: none; }
.ntf-msg-success { background: var(--success-bg); color: var(--success); }
.ntf-msg-danger  { background: var(--danger-bg);  color: var(--danger); }
.ntf-msg-muted   { background: var(--surface-2);  color: var(--muted); }
.ntf-ctp-panel {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  margin-top: 8px;
  flex-wrap: wrap;
}
.ntf-ctp-panel.hidden { display: none; }
.jalali-hint { font-size: .75rem; color: var(--muted); }

/* ─── Requirement tag ─── */
.req { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════
   OPEN TRADES TABLE
   ═══════════════════════════════════════════════════════════════════════════ */
.dash-open-trades-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
}
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.badge.buy  { background: var(--success-bg); color: var(--success); }
.badge.sell { background: var(--danger-bg);  color: var(--danger); }
.badge.muted { background: var(--surface-3); color: var(--muted); }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.pos  { background: var(--success-bg); color: var(--success); }
.badge-buy  { background: var(--success-bg); color: var(--success); padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 700; }
.badge-sell { background: var(--danger-bg);  color: var(--danger);  padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 700; }
.badge-open      { background: var(--warning-bg); color: var(--warning); padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 700; }
.badge-closed    { background: var(--surface-3);  color: var(--muted);   padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 700; }
.badge-cancelled { background: var(--danger-bg);  color: var(--danger);  padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 700; }

.table-wrap { overflow-x: auto; }
.dash-trades-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
.dash-trades-table th {
  background: var(--surface-2);
  padding: 9px 12px;
  text-align: right;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-weight: 700;
  color: var(--muted);
  font-size: .78rem;
}
.dash-trades-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.dash-trades-table .trade-row:hover td,
.dash-trades-table .rep-trade-row:hover td { background: var(--surface-2); }
.num  { text-align: left; dir: ltr; font-variant-numeric: tabular-nums; }
.mono { font-family: 'Courier New', monospace; }
.center { text-align: center; }
.small  { font-size: .8rem; }
.p-lg   { padding: 32px !important; }
.p-sm   { padding: 8px !important; }
.error-msg { padding: 16px; color: var(--danger); background: var(--danger-bg); border-radius: var(--radius-xs); }

/* ═══════════════════════════════════════════════════════════════════════════
   REPORTS MODULE
   ═══════════════════════════════════════════════════════════════════════════ */
.rep-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 20px;
}
.rep-filter-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 28px;
  margin-bottom: 20px;
}
.rep-filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.rep-filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 140px; flex: 1; }
.rep-filter-group label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.rep-filter-actions { display: flex; gap: 8px; align-items: flex-end; }

/* KPI grid */
.rep-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.rep-kpi-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.rep-kpi-card.kpi-open   { border-right: 3px solid var(--warning); }
.rep-kpi-card.kpi-closed { border-right: 3px solid var(--success); }
.rep-kpi-card.kpi-warn   { border-right: 3px solid var(--danger); }
.rep-kpi-card.kpi-today  { border-right: 3px solid var(--primary); }
.rep-kpi-label { font-size: .75rem; color: var(--muted); margin-bottom: 6px; }
.rep-kpi-value { font-size: 1rem; font-weight: 800; }

/* Docs expand */
.rep-docs-row.hidden { display: none; }
.rep-docs-cell { padding: 0 !important; background: var(--surface-2); }
.rep-docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
}
.rep-docs-table th {
  padding: 6px 10px;
  background: var(--surface-3);
  text-align: right;
  font-weight: 700;
  color: var(--muted);
}
.rep-docs-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}
.doc-count-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border-radius: 99px;
  padding: 1px 7px;
  font-size: .72rem;
  font-weight: 700;
}

/* ═══════════════════════════════════════════════════════════════════════════
   JALALI DATE PICKER
   ═══════════════════════════════════════════════════════════════════════════ */
.jp-picker {
  position: fixed;
  z-index: 99999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  width: 272px;
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
  user-select: none;
  animation: jp-fade-in .12s ease;
}
@keyframes jp-fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Header */
.jp-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 6px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.jp-nav {
  background: none;
  border: none;
  padding: 4px 7px;
  cursor: pointer;
  color: var(--primary);
  font-size: 1rem;
  font-weight: 700;
  border-radius: var(--radius-xs);
  transition: background var(--transition);
  line-height: 1;
}
.jp-nav:hover { background: var(--surface-3); }
.jp-title { display: flex; gap: 5px; align-items: baseline; }
.jp-mn { font-weight: 700; font-size: .92rem; color: var(--text); }
.jp-yr { font-size: .8rem; color: var(--muted); }

/* Weekday headers */
.jp-wrow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 6px 6px 0;
}
.jp-wd {
  text-align: center;
  font-size: .7rem;
  font-weight: 700;
  color: var(--muted);
  padding: 3px 0;
}

/* Day grid */
.jp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  padding: 4px 6px 6px;
}
.jp-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: .83rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.jp-empty { cursor: default; }
.jp-day:hover:not(.jp-sel) { background: var(--surface-3); }
.jp-today { color: var(--primary); font-weight: 800; position: relative; }
.jp-today::after {
  content: '';
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--primary);
}
.jp-sel { background: var(--primary) !important; color: #fff !important; font-weight: 700; }
.jp-sel.jp-today::after { background: #fff; }

/* Footer */
.jp-footer {
  display: flex;
  justify-content: center;
  padding: 5px 8px 8px;
  border-top: 1px solid var(--border);
}
.jp-today-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-xs);
  padding: 3px 16px;
  font-size: .78rem;
  font-family: 'Vazirmatn', sans-serif;
  cursor: pointer;
  transition: all var(--transition);
}
.jp-today-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Input wrapper (calendar icon button next to input) */
.jp-input-wrap {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--surface-2);
}
.jp-input-wrap .ntf-input {
  flex: 1;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
}
.jp-input-wrap .ntf-input:focus { outline: none; box-shadow: none; }
.jp-input-wrap:focus-within { border-color: var(--primary); }
.jp-icon-btn {
  background: var(--surface-3);
  border: none;
  border-right: 1px solid var(--border);
  padding: 0 10px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.jp-icon-btn:hover { background: var(--primary); color: #fff; }
[dir="rtl"] .jp-icon-btn { border-right: none; border-left: 1px solid var(--border); }

/* ── Fix: .trade-row has display:flex from old styles — override inside table ── */
.dash-trades-table tr.trade-row {
  display: table-row !important;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  gap: 0;
  cursor: pointer;
}
.dash-trades-table tr.trade-row:hover td { background: var(--surface-2); }

/* ── Operations column ── */
.trade-ops-cell {
  white-space: nowrap;
  padding: 5px 8px !important;
  vertical-align: middle !important;
}
.trade-ops {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: nowrap;
}
.trade-ops .btn {
  padding: 3px 8px;
  font-size: .72rem;
  border-radius: 8px;
  white-space: nowrap;
}

/* ── Doc edit log section ── */
.edit-log-section {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.edit-log-header {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted, #888);
  margin-bottom: 6px;
}
.edit-log-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: .8rem;
}
.edit-log-row:last-child { border-bottom: none; }
.edit-log-time  { font-size: .72rem; color: var(--text-muted, #888); }
.edit-log-field { color: var(--primary); font-weight: 500; font-size: .78rem; }
.edit-log-change { color: var(--text); }

/* ── Trade balance cards (بدهکاری/بستانکاری) ── */
.trade-balance-cards {
  display: flex;
  gap: 12px;
  padding: 12px 0 4px;
}
.trade-bal-card {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--surface-2);
}
.trade-bal-card.bed  { border-right: 3px solid var(--danger); }
.trade-bal-card.best { border-right: 3px solid var(--success); }
.tbc-label { font-size: .78rem; color: var(--text-muted, #888); margin-bottom: 4px; }
.tbc-val   { font-size: 1.05rem; font-weight: 700; }

/* ── Doc amount summary bar ── */
.doc-amount-summary {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  margin-bottom: 8px;
  font-size: .82rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   V3 — DESKTOP POLISH + FULL RESPONSIVE / MOBILE REDESIGN
   (appended last so it overrides earlier same-specificity rules; no JS changes)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Global polish ───────────────────────────────────────────────────────── */
body { line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

/* Center content on wide screens instead of stretching edge-to-edge */
.page-section.active { max-width: var(--maxw); margin-inline: auto; }

/* Modern, consistent focus ring in the brand colour (was a generic black shadow) */
input:focus, select:focus, textarea:focus,
.ntf-input:focus, .ntf-select:focus {
  outline: none;
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--ring) !important;
}
button:focus-visible, .nav-tab:focus-visible, a:focus-visible {
  outline: none; box-shadow: 0 0 0 3px var(--ring);
}

/* Softer, layered card shadows + smooth hover lift */
.card, .kpi, .account-card, .rep-section, .rep-filter-section,
.dash-new-trade-section, .dash-open-trades-section, .rpt-result {
  box-shadow: 0 1px 2px rgba(20,16,8,.04), 0 6px 20px rgba(20,16,8,.05);
}
[data-theme="dark"] .card, [data-theme="dark"] .kpi, [data-theme="dark"] .account-card,
[data-theme="dark"] .rep-section, [data-theme="dark"] .rep-filter-section,
[data-theme="dark"] .dash-new-trade-section, [data-theme="dark"] .dash-open-trades-section {
  box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
}
.account-card { transition: transform var(--transition), box-shadow var(--transition); }
.account-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
/* NB: do NOT put filter/backdrop-filter/transform on .app-topbar — it would
   become the containing block for the fixed mobile bottom-nav (its child). */
.app-topbar-logo { letter-spacing: .2px; }

/* Refined nav tabs (desktop): pill style, clearer active state */
.nav-tab { transition: background var(--transition), color var(--transition); }
.nav-tab.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-bottom: none;
  box-shadow: inset 0 0 0 1px var(--ring);
}

/* Buttons: comfortable tap area + subtle press feedback */
.btn, .tab-btn, .theme-toggle, .nav-tab { min-height: 38px; }
.btn:active { transform: translateY(1px); }
.btn.primary, .ntf-submit { box-shadow: 0 2px 8px var(--primary-soft); }

/* Status dot helper used by the connection indicator on small screens */
#serverStatus { white-space: nowrap; }

/* ── Tables: smooth momentum scrolling + scroll hint ─────────────────────── */
.table-wrap, .wallet-report, .scroll, .rpt-result { -webkit-overflow-scrolling: touch; }
.table-wrap, .wallet-report { position: relative; }

/* ═══════════════════════════════ TABLET ═════════════════════════════════ */
@media (max-width: 980px) {
  .dash-grid { grid-template-columns: 1fr; }
  .inv-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .page-section { padding: 18px; }
}

/* ═══════════════════════════════ MOBILE ═════════════════════════════════ */
@media (max-width: 768px) {
  :root { --header-h: 54px; }

  /* — Top bar: single tidy row (logo + compact actions); tabs move to bottom — */
  .app-topbar {
    height: var(--header-h);
    padding: 0 12px;
    gap: 8px;
  }
  .app-topbar-logo { font-size: .95rem; }
  .app-topbar-spacer { display: none; }
  .app-topbar-actions { gap: 6px; margin-inline-start: auto; }

  /* Connection indicator collapses to a coloured dot (keeps JS-set status colour) */
  #serverStatus { font-size: 0 !important; line-height: 0; }
  #serverStatus::before { content: "●"; font-size: .8rem; line-height: 1; }

  .theme-toggle { padding: 6px 8px; font-size: .75rem; }
  .btn.ghost.sm, #logoutBtn { padding: 5px 9px; font-size: .75rem; }

  /* — Bottom navigation bar (reuses the existing .nav-tab buttons & handlers) — */
  .nav-tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 300;
    display: flex;
    gap: 0;
    flex-wrap: nowrap;
    overflow: visible;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -3px 16px rgba(0,0,0,.10);
    padding: 6px 4px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 50px;
    padding: 4px 2px;
    font-size: .68rem;
    border-radius: 12px;
    color: var(--muted);
  }
  .nav-tab.active { background: var(--primary-soft); color: var(--primary); box-shadow: none; }
  .nav-tab::before { font-size: 1.25rem; line-height: 1; display: block; }
  .nav-tab[data-page="dashboard"]::before { content: "🏠"; }
  .nav-tab[data-page="orderbook"]::before { content: "📊"; }
  .nav-tab[data-page="wallet"]::before    { content: "👛"; }
  .nav-tab[data-page="reports"]::before    { content: "📑"; }

  /* Keep content clear of the fixed bottom bar */
  .main-content { padding: 12px; padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px) + 16px); }
  .page-section, .page-section.active { padding: 0; }

  /* — Section cards: tighter padding on phones — */
  .dash-new-trade-section, .dash-open-trades-section,
  .rep-section, .rep-filter-section, .card { padding: 16px; }

  /* — Forms stack fully; comfortable inputs — */
  .ntf-row { gap: 12px; }
  .ntf-field, .ntf-field-wide, .ntf-field-grow, .rep-filter-group, .report-filter-group { min-width: 0; flex: 1 1 100%; }
  .ntf-field-actions, .rep-filter-actions { width: 100%; }
  .ntf-field-actions .btn, .ntf-submit, .rep-filter-actions .btn { flex: 1; }
  .ntf-radio-group { flex-wrap: wrap; }
  .ntf-radio-label { flex: 1; justify-content: center; }
  input, select, textarea, .ntf-input, .ntf-select { font-size: 16px; } /* prevents iOS zoom-on-focus */

  /* — Wallet: horizontal scroll pills instead of a stacked sidebar — */
  .wallet-layout { grid-template-columns: 1fr; gap: 14px; }
  .wallet-type-tabs { flex-direction: row; overflow-x: auto; gap: 8px; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
  .wtab { flex: 0 0 auto; white-space: nowrap; min-height: 40px; }
  .accounts-grid { grid-template-columns: 1fr; }
  .summary-bar { gap: 12px 18px; }

  /* — Reports KPIs: 2-up on phones — */
  .rep-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .inv-summary-grid { grid-template-columns: 1fr 1fr; }

  /* — Trade row actions wrap rather than overflow — */
  .trade-ops { flex-wrap: wrap; }

  /* — Modals & slide panels go full-screen for dense content — */
  .modal-box, .modal-box.modal-lg, .slide-panel-box, .invoice-modal {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    border-radius: 0;
    display: flex; flex-direction: column;
  }
  .modal-body { flex: 1; overflow-y: auto; }
  .modal-header { padding: 16px 16px 0; }
  .modal-footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .doc-cols, .doc-form-cols, .inv-docs-wrap { grid-template-columns: 1fr; }
  .trade-balance-cards { flex-direction: column; gap: 10px; }
  .doc-detail-row { flex-direction: column; gap: 2px; }
  .doc-detail-row > span:first-child { min-width: 0; }

  /* Hide order-book spread chip clutter on very small cards */
  .ob-module-header { flex-wrap: wrap; gap: 10px; }
}

/* ═══════════════════════════════ SMALL PHONES ═══════════════════════════ */
@media (max-width: 420px) {
  .rep-kpi-grid, .inv-summary-grid { grid-template-columns: 1fr; }
  .app-topbar { gap: 6px; padding: 0 10px; }
  .app-topbar-actions { gap: 5px; }
  .ntf-radio-label { font-size: .82rem; padding: 8px 10px; }
}

/* The bottom nav is irrelevant when printing */
@media print { .nav-tabs { position: static !important; box-shadow: none !important; } }
