:root {
  --primary: #38b2ac;
  --primary-dark: #0f766e;
  --primary-soft: rgba(56, 178, 172, .12);
  --secondary: #9f7aea;
  --tertiary: #ed8936;
  --surface: #f7fafc;
  --surface-grid: #edf2f7;
  --panel: #ffffff;
  --panel-soft: #fbfdff;
  --line: #e2e8f0;
  --line-strong: #cbd5e0;
  --text: #2d3748;
  --muted: #718096;
  --danger: #e53e3e;
  --danger-soft: rgba(229, 62, 62, .10);
  --success-soft: rgba(56, 178, 172, .12);
  --warning-soft: rgba(237, 137, 54, .12);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-1: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-2: 0 6px 20px rgba(45, 55, 72, .08);
  --shadow-3: 0 18px 42px rgba(45, 55, 72, .13);
  --sidebar-w: 272px;
  /* alias helpers used by new settings UI */
  --text-muted: #718096;
  --input-bg: #ffffff;
  --card-bg: #ffffff;
  --border: #e2e8f0;
}

/* Toastify overrides */
.toastify {
  font-family: Inter, "Segoe UI", Arial, sans-serif !important;
  letter-spacing: .01em !important;
  min-width: 220px !important;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background-color: var(--surface);
  background-image:
    linear-gradient(var(--surface-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--surface-grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: center top;
  -webkit-font-smoothing: antialiased;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  body { color-scheme: light; }
}

a { color: inherit; text-decoration: none; }

button,
input,
select {
  font: inherit;
}

button {
  appearance: none;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, .85fr) minmax(420px, 1.15fr);
  background: var(--surface);
}

.auth-form-side {
  display: grid;
  place-items: center;
  padding: clamp(22px, 5vw, 56px);
}

.auth-card {
  width: min(440px, 100%);
  padding: clamp(24px, 4vw, 40px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
}

.auth-logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  font-weight: 900;
  font-size: 20px;
}

.auth-card h1,
.page-title {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  line-height: 1.18;
}

.auth-card h1 {
  font-size: 28px;
}

.auth-card p,
.page-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.auth-banner-side {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: clamp(28px, 5vw, 60px);
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.auth-banner-side::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("../img/auth-bg.png");
  background-size: cover;
  background-position: center;
  opacity: .78;
}

.auth-banner-card {
  position: relative;
  width: min(520px, 100%);
  padding: 32px;
  border-radius: var(--radius-xl);
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.24);
  backdrop-filter: blur(14px);
  box-shadow: 0 30px 70px rgba(15, 118, 110, .24);
}

.auth-banner-card h2 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.12;
}

.auth-banner-card p {
  margin: 0;
  color: rgba(255,255,255,.88);
  font-size: 16px;
}

.form-group { margin-top: 22px; }

label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56,178,172,.16);
}

.btn,
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}

.btn:hover,
button:hover,
.button:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: var(--shadow-2);
  transform: translateY(-1px);
}

.btn:disabled,
button:disabled,
.button:disabled {
  cursor: wait;
  opacity: .68;
  transform: none;
  box-shadow: none;
}

.btn-full { width: 100%; margin-top: 22px; }
.secondary, .button.secondary, button.secondary { background: #fff; color: var(--text); border-color: var(--line-strong); }
.secondary:hover, .button.secondary:hover, button.secondary:hover { background: var(--panel-soft); border-color: var(--primary); color: var(--primary-dark); }
.danger, .button.danger, button.danger { background: #fff; color: var(--danger); border-color: rgba(229,62,62,.32); }
.danger:hover, .button.danger:hover, button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }

.error {
  margin-top: 14px;
  padding: 11px 12px;
  border: 1px solid rgba(229,62,62,.24);
  border-radius: var(--radius-md);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  overflow-y: auto;
  background: rgba(255,255,255,.94);
  border-right: 1px solid var(--line);
  box-shadow: 12px 0 34px rgba(45,55,72,.05);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  font-weight: 900;
}

.brand-title {
  font-weight: 900;
  font-size: 18px;
  letter-spacing: .01em;
}

.brand-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-toggle {
  display: none;
}

.nav {
  display: grid;
  gap: 8px;
  padding: 22px 0;
}

.nav a {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-radius: var(--radius-md);
  color: var(--muted);
  font-weight: 700;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.nav a:hover {
  background: var(--surface-grid);
  color: var(--primary-dark);
}

.nav a.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: currentColor;
  flex-shrink: 0;
}

.session-box {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

.logout {
  width: 100%;
  margin-top: 12px;
}

.main {
  width: calc(100% - var(--sidebar-w));
  min-width: 0;
  margin-left: var(--sidebar-w);
  padding: clamp(18px, 2.5vw, 32px);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-title {
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 800;
}

.panel,
.card,
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}

.card {
  padding: 18px;
}

.card:hover,
.panel:hover,
.stat:hover {
  box-shadow: var(--shadow-3);
}

.stats {
  display: grid;
  grid-template-columns: repeat(7, minmax(118px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  padding: 16px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-value {
  margin-top: 8px;
  color: var(--text);
  font-size: clamp(22px, 2vw, 28px);
  font-weight: 900;
  line-height: 1;
}

.grid-4,
.grid-2 {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--text);
}

.bank-row,
.kv-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--surface-grid);
}

.bank-row:first-of-type,
.kv-row:first-of-type {
  border-top: 0;
}

.bank-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.bank-code {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.bank-count,
.kv-value {
  color: var(--primary-dark);
  font-weight: 900;
}

.filters,
.copybar {
  display: grid;
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
  align-items: end;
}

.filters {
  grid-template-columns: minmax(220px, 1.4fr) minmax(170px, .8fr) 135px 145px 110px auto auto;
}

.copybar {
  grid-template-columns: 110px 110px auto auto auto auto auto minmax(180px, 1fr);
}

.status-text {
  align-self: center;
  color: var(--muted);
}

.status-text.error {
  color: var(--danger);
  font-weight: 800;
}

.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
  color: var(--muted);
  flex-wrap: wrap;
}

.table-panel {
  overflow: hidden;
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 342px);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface-grid);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(247,250,252,.96);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  backdrop-filter: blur(10px);
}

tbody tr:hover td {
  background: #fbfdff;
}

tr.copied td {
  background: var(--success-soft);
}

tr.failed td {
  background: #fff7f7;
}

.col-index { width: 74px; color: var(--muted); }
.col-name { width: 24%; font-weight: 800; }
.col-bank { width: 27%; }
.col-stk { width: 160px; font-family: Consolas, "Courier New", monospace; }
.col-code { width: 110px; font-family: Consolas, "Courier New", monospace; }
.col-time { width: 152px; color: var(--muted); }
.col-copy { width: 185px; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  border-color: rgba(56,178,172,.35);
  background: var(--success-soft);
  color: var(--primary-dark);
}

.badge.warn {
  border-color: rgba(237,137,54,.35);
  background: var(--warning-soft);
  color: #9a551e;
}

.badge.danger {
  border-color: rgba(229,62,62,.35);
  background: var(--danger-soft);
  color: var(--danger);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  color: var(--muted);
}

.pager-actions {
  display: flex;
  gap: 8px;
}

.flash {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(56,178,172,.32);
  border-radius: var(--radius-lg);
  background: var(--success-soft);
  color: var(--primary-dark);
  font-weight: 800;
}

.flash.error {
  border-color: rgba(229,62,62,.28);
  background: var(--danger-soft);
  color: var(--danger);
}

.copy-fallback {
  position: fixed;
  left: -10000px;
  top: -10000px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.process-actions {
  display: grid;
  gap: 10px;
}

.task-loading {
  display: none;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(56,178,172,.28);
  border-radius: var(--radius-md);
  background: var(--success-soft);
  color: var(--primary-dark);
  font-weight: 800;
}

.task-loading.show {
  display: flex;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(15,118,110,.18);
  border-top-color: var(--primary-dark);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: 12px;
  margin-bottom: 16px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.bank-name-form {
  grid-template-columns: minmax(120px, .7fr) minmax(220px, 1.4fr) auto;
}

.settings-table {
  overflow: auto;
  max-height: 420px;
  border: 1px solid var(--surface-grid);
  border-radius: var(--radius-md);
}

.compact-table table {
  min-width: 0;
}

.compact-table th,
.compact-table td {
  padding: 10px 12px;
}

.compact-table th:last-child,
.compact-table td:last-child {
  width: 170px;
}

.actions-cell {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.actions-cell form {
  margin: 0;
}

.actions-cell button {
  min-height: 34px;
  padding: 0 10px;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
}

.sidebar-overlay {
  display: none;
}

@media (max-width: 1320px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .copybar { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .app-shell { display: block; }
  .sidebar {
    width: min(320px, 88vw);
    min-width: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: none;
    background: rgba(45,55,72,.38);
    backdrop-filter: blur(3px);
  }
  .sidebar-overlay.open { display: block; }
  .main {
    width: 100%;
    margin-left: 0;
    padding: 16px;
  }
  .page-head {
    align-items: center;
  }
  .sidebar-toggle {
    display: inline-flex;
    min-width: 42px;
    padding: 0 12px;
  }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .table-scroll { max-height: none; }
}

@media (max-width: 768px) {
  .auth-page {
    grid-template-columns: 1fr;
  }
  .auth-banner-side {
    display: none;
  }
  .auth-form-side {
    min-height: 100vh;
    padding: 18px;
  }
  .auth-card {
    padding: 24px;
  }
  .filters,
  .copybar,
  .inline-form,
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .pager {
    align-items: stretch;
    flex-direction: column;
  }
  .pager-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .pager-actions form,
  .pager-actions button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  body { font-size: 13px; }
  .main { padding: 12px; }
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }
  .stats {
    grid-template-columns: 1fr;
  }
  .stat,
  .card {
    padding: 14px;
  }
  th,
  td {
    padding: 10px 12px;
  }
  .button,
  button,
  .btn {
    width: 100%;
  }
  .actions-cell {
    justify-content: stretch;
  }
  .actions-cell form,
  .actions-cell button {
    width: 100%;
  }
}
