:root {
  --primary: #1a3a5c;
  --primary-light: #2563a8;
  --accent: #f59e0b;
  --success: #16a34a;
  --danger: #dc2626;
  --bg: #f0f4f8;
  --card: #ffffff;
  --border: #d1dae6;
  --text: #1e293b;
  --text-muted: #64748b;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --nav-text: #ffffff;
}

body.theme-dark {
  --bg: #0f172a;
  --card: #111827;
  --border: #243244;
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --surface-2: #0b1220;
  --surface-3: #162235;
  --nav-text: #f8fafc;
  --primary: #0f2740;
  --primary-light: #3b82f6;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Navbar ── */
.navbar {
  background: var(--primary);
  color: var(--nav-text);
  padding: .85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  flex-wrap: wrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
  position: sticky;
  top: 0;
  z-index: 1100;
}
.navbar.role-teller { background: linear-gradient(90deg, #1e4d8c 0%, #2563a8 100%); }
.navbar.role-admin  { background: linear-gradient(90deg, #5b21b6 0%, #7c3aed 100%); }
.navbar.role-owner  { background: linear-gradient(90deg, #065f46 0%, #059669 100%); }
.navbar-brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: .6rem;
  text-decoration: none;
  color: var(--nav-text);
  min-width: 0;
}
.navbar-brand .logo-img { height: 42px; width: auto; flex-shrink: 0; }
.navbar-brand .brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.navbar-right {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: .65rem;
  flex-wrap: wrap;
}
.nav-toggle {
  display: none;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  border-radius: 6px;
  padding: 5px 11px;
  font-size: 1.1rem;
  line-height: 1.3;
  cursor: pointer;
}
.nav-toggle:hover { background: rgba(255,255,255,.28); }
.nav-select-group {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.nav-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.nav-dropdown-toggle {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
}
.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 14px 32px rgba(0,0,0,.18);
  padding: .35rem;
  display: none;
  z-index: 1200;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
}
.nav-dropdown-item {
  display: block;
  padding: .5rem .75rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: .9rem;
  white-space: nowrap;
}
.nav-dropdown-item:hover {
  background: var(--surface-2);
}
.nav-dropdown-item.active {
  background: var(--primary-light);
  color: white;
}
.navbar-right a {
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .9rem;
  white-space: nowrap;
}
.navbar-right a:hover { color: var(--nav-text); }
.role-badge {
  background: var(--accent);
  color: #1e293b;
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
}
.lang-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  letter-spacing: .5px;
  transition: background .15s;
  white-space: nowrap;
}
.lang-btn:hover { background: rgba(255,255,255,.28); color: white; }
.lang-btn.active { background: rgba(255,255,255,.35); }

/* ── Layout ── */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem;
}
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--primary);
  word-break: break-word;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  overflow: hidden;
}
.card-header {
  background: var(--primary);
  color: var(--nav-text);
  padding: .75rem 1.1rem;
  font-weight: 600;
  font-size: .95rem;
  word-break: break-word;
}
.card-header.accent { background: var(--accent); color: #1e293b; }
.card-header.success { background: var(--success); }
.card-body { padding: 1.15rem; }

/* ── Grid ── */
.grid { display: grid; gap: 1.1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ── Stat boxes ── */
.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.15rem;
  text-align: center;
  min-width: 0;
}
.stat-box .currency-flag { font-size: 2rem; margin-bottom: .25rem; }
.stat-box .currency-name { font-size: .8rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.stat-box .amount {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin: .25rem 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.stat-box .amount.negative { color: var(--danger); }
.stat-box .sub { font-size: .8rem; color: var(--text-muted); }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; min-width: 0; }
.form-group label {
  display: block;
  font-size: .875rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--text-muted);
  word-break: break-word;
}
.form-control {
  width: 100%;
  padding: .55rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  color: var(--text);
  background: white;
  transition: border-color .15s;
  min-width: 0;
}
.form-control:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(37,99,168,.12); }
select.form-control { cursor: pointer; }
.tx-srd-display {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
  background: linear-gradient(135deg, var(--surface-2), #ffffff);
  border: 2px solid var(--primary-light);
  box-shadow: 0 6px 18px rgba(37,99,168,.12);
  padding: .8rem .9rem;
}
.tx-srd-display[readonly] {
  cursor: default;
}
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.25rem;
  border-radius: 6px;
  border: none;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
  max-width: 100%;
}
.btn:active { transform: scale(.98); }
.btn:hover { opacity: .9; }
.btn-primary { background: var(--primary-light); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-accent { background: var(--accent); color: #1e293b; }
.btn-outline { background: white; border: 1.5px solid var(--border); color: var(--text); }
.btn-sm { padding: .35rem .85rem; font-size: .82rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0 0 10px 10px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  min-width: 760px;
}
th {
  background: var(--surface-3);
  padding: .6rem .9rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: .6rem .9rem;
  border-bottom: 1px solid #eef2f7;
  color: var(--text);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 700;
  max-width: 100%;
  word-break: break-word;
}
.badge-buy { background: #dcfce7; color: #15803d; }
.badge-sell { background: #fee2e2; color: #b91c1c; }
.badge-open { background: #dbeafe; color: #1d4ed8; }
.badge-closed { background: #f1f5f9; color: #64748b; }

/* ── Alerts ── */
.alerts { margin-bottom: 1rem; }
.alert {
  padding: .75rem 1rem;
  border-radius: 7px;
  margin-bottom: .5rem;
  font-size: .9rem;
  border-left: 4px solid;
  word-break: break-word;
}
.alert-success { background: #f0fdf4; border-color: var(--success); color: #166534; }
.alert-danger  { background: #fef2f2; border-color: var(--danger);  color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: var(--accent);  color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #3b82f6;         color: #1e40af; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, #2563a8 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: var(--card);
  border-radius: 14px;
  padding: 2rem;
  width: min(100%, 420px);
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-logo .icon { font-size: 3rem; display: block; }
.login-logo h1 {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
  margin-top: .25rem;
  word-break: break-word;
}
.login-logo p { font-size: .85rem; color: var(--text-muted); }
.login-lang {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ── Live indicator ── */
.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  margin-right: 5px;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* ── Section spacing ── */
.section { margin-bottom: 1.75rem; }
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: .75rem;
  word-break: break-word;
}

/* ── Utility ── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.flex { display: flex; }
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.no-data { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .95rem; }

/* ── Toasts ── */
.toast-stack {
  position: fixed;
  top: 72px;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  z-index: 1000;
  width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.txn-toast {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(0,0,0,.18);
  padding: .85rem 1rem;
  opacity: 0;
  transform: translateX(24px) scale(.98);
  transition: opacity .25s ease, transform .25s ease;
}
.txn-toast.show {
  opacity: 1;
  transform: translateX(0) scale(1);
}
.txn-toast.hide {
  opacity: 0;
  transform: translateX(24px) scale(.98);
}
.txn-toast-head,
.txn-toast-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
}
.txn-toast-head {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: .45rem;
}
.txn-toast-body {
  flex-wrap: wrap;
  font-size: .92rem;
}
@media (max-width: 600px) {
  .toast-stack {
    top: 64px;
    right: .75rem;
    left: .75rem;
    width: auto;
  }
}

/* ── Footer ── */
.app-footer {
  margin-top: 3rem;
  padding: 1.25rem 0;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: .78rem;
  color: var(--text-muted);
  word-break: break-word;
}
.app-footer a { color: var(--primary-light); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* ── Print closing slip ── */
@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .slip-box { box-shadow: none; border: 1px solid #ccc; }
}
.slip-box {
  max-width: 480px;
  margin: 2rem auto;
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(0,0,0,.12);
  padding: 2rem;
}
.slip-logo { text-align: center; margin-bottom: 1.25rem; }
.slip-logo img { height: 64px; max-width: 100%; }
.slip-logo h2 { font-size: 1.1rem; color: var(--primary); margin-top: .4rem; word-break: break-word; }
.slip-amounts { width: 100%; border-collapse: collapse; margin: 1.25rem 0; }
.slip-amounts td { padding: .6rem .75rem; border-bottom: 1px solid #eef2f7; font-size: 1rem; }
.slip-amounts td:last-child { text-align: right; font-weight: 700; font-size: 1.15rem; }
.slip-footer { font-size: .8rem; color: var(--text-muted); text-align: center; margin-top: 1rem; }

/* ── Responsive ── */
@media (max-width: 992px) {
  .container { padding: 1rem; }
  .grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
  .grid-3 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .grid-2 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  .navbar { padding: .75rem 1rem; }
}

@media (max-width: 768px) {
  .nav-toggle { display: inline-flex; }
  .nav-links {
    display: none;
    order: 10;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin-top: .4rem;
    padding-top: .3rem;
    border-top: 1px solid rgba(255,255,255,.22);
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    padding: .65rem .5rem;
    border-radius: 8px;
    font-size: .95rem;
  }
  .nav-links a:hover { background: rgba(255,255,255,.12); }
  .navbar-right { flex: 1; }
  .card-body { padding: 1rem; }
  .stat-box {
    padding: 1rem;
  }
  .stat-box .amount {
    font-size: 1.75rem;
  }
  .login-page {
    padding: 1rem .85rem;
  }
  .login-card {
    width: min(100%, 500px);
  }
}

@media (max-width: 600px) {
  .form-row,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
  .navbar-brand .brand-text { display: none; }
  .nav-username { display: none; }
  .container { padding: .85rem; }
  .page-title { font-size: 1.2rem; }
  .login-page { padding: .75rem; }
  .login-card {
    padding: 1.35rem;
    border-radius: 12px;
  }
  .login-logo {
    margin-bottom: 1.1rem;
  }
  .login-logo h1 { font-size: 1.25rem; }
  .toast-stack {
    top: 60px;
    right: .5rem;
    left: .5rem;
    width: auto;
  }
  .btn {
    justify-content: center;
  }
}

@media (max-width: 420px) {
  .navbar {
    padding: .65rem .75rem;
  }
  .navbar-right {
    gap: .45rem;
  }
  .lang-btn {
    padding: 4px 8px;
    font-size: .74rem;
  }
  .role-badge {
    font-size: .7rem;
    padding: 2px 7px;
  }
  .login-lang {
    top: .75rem;
    right: .75rem;
    left: .75rem;
    justify-content: flex-end;
  }
  .login-card {
    padding: 1.1rem;
  }
}

/* ── Card-style tables on phones ──
   app.js copies each header onto its cells as data-label and tags the
   table with .card-table; below 640px rows render as labeled cards. */
@media (max-width: 640px) {
  table.card-table { min-width: 0; }
  table.card-table thead { display: none; }
  table.card-table,
  table.card-table tbody { display: block; }
  table.card-table tbody tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: .65rem .15rem;
    padding: .3rem .85rem;
  }
  table.card-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: .45rem 0;
    border-bottom: 1px solid var(--surface-3);
    text-align: right;
  }
  table.card-table tbody td:last-child { border-bottom: none; }
  table.card-table tbody td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: .74rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    text-align: left;
  }
  table.card-table tbody td[colspan] {
    justify-content: center;
    text-align: center;
  }
  table.card-table tbody td[colspan]::before { content: none; }
}

/* ── User actions / password reset ── */
.user-actions { display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.pw-reset summary {
  cursor: pointer;
  color: var(--primary-light);
  font-size: .82rem;
  list-style: none;
  user-select: none;
}
.pw-reset summary::-webkit-details-marker { display: none; }
.pw-reset summary:hover { text-decoration: underline; }
.pw-reset form { margin-top: .4rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.pw-reset input[type=password] { max-width: 220px; }
