:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --navy: #0f172a;
  --blue-dark: #1e3a8a;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --teal: #0d9488;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(145deg, #0f172a 0%, #1e3a8a 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.login-brand h1 {
  margin: 0;
  font-size: 18px;
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.login-footnote {
  margin: 14px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

/* App Shell */
.app-shell {
  min-height: 100vh;
  padding-bottom: 76px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--navy);
  color: #fff;
  padding: 10px 14px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.topbar-sub {
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 210px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.branch-bar {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.branch-bar label {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  white-space: nowrap;
}

.branch-bar select {
  flex: 1;
  background: #1e293b;
  color: #fff;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
}

/* Main Content */
.main-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-header h2 {
  margin: 0;
  font-size: 16px;
}

/* Forms & Inputs */
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.field.grow-2 {
  flex: 2;
}

.field label {
  font-size: 11.5px;
  font-weight: 700;
  color: #475569;
}

input, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.checkbox-line input {
  width: 18px;
  height: 18px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-success {
  background: var(--green);
  color: #fff;
}

.btn-outline {
  background: #fff;
  color: var(--text);
  border: 1px solid #cbd5e1;
}

.btn-danger-outline {
  background: transparent;
  color: #fca5a5;
  border: 1px solid rgba(252, 165, 165, 0.45);
}

.btn-icon {
  width: 34px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

/* Alerts & Pills */
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  margin-bottom: 10px;
}

.alert-danger {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-warning {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-info {
  background: #eff6ff;
  color: #1e3a8a;
  border: 1px solid #bfdbfe;
}

.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.pill-blue { background: #dbeafe; color: #1e40af; }
.pill-green { background: #dcfce7; color: #166534; }
.pill-red { background: #fee2e2; color: #991b1b; }
.pill-amber { background: #fef3c7; color: #92400e; }
.pill-slate { background: #e2e8f0; color: #334155; }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  border-left: 4px solid var(--blue);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.kpi-blue { border-left-color: var(--blue); }
.kpi-green { border-left-color: var(--green); }
.kpi-emerald { border-left-color: #059669; }
.kpi-teal { border-left-color: var(--teal); }

.kpi-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
}

.kpi-value {
  display: block;
  margin: 4px 0 2px;
  font-size: 17px;
  color: var(--navy);
}

.kpi-sub {
  font-size: 11.5px;
  color: var(--muted);
}

/* Panels & Filters */
.panel, .filter-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-header h3 {
  margin: 0;
  font-size: 14px;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.filter-row:last-child {
  margin-bottom: 0;
}

.field-btn {
  justify-content: flex-end;
}

.action-strip {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.action-strip select {
  flex: 1;
  min-width: 140px;
  padding: 6px 8px;
  font-size: 12.5px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.mini-stats.three-cols {
  grid-template-columns: repeat(3, 1fr);
}

.mini-stats span {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
}

.mini-stats strong {
  font-size: 12.5px;
}

.subtab-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 8px;
}

.subtab {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
}

.subtab.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

/* Card Lists */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  border: 1px solid var(--border);
}

.item-card.clickable {
  cursor: pointer;
}

.item-card.risk-high {
  background: #fef2f2;
  border-color: #fecaca;
}

.item-card.cash-in {
  border-left: 4px solid var(--green);
}

.item-card.cash-out {
  border-left: 4px solid var(--red);
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.item-title {
  font-weight: 700;
  font-size: 14px;
}

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

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: #334155;
}

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.item-actions .btn {
  flex: 1;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 26px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px dashed #cbd5e1;
}

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-muted { color: var(--muted); font-size: 11.5px; }

/* Pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: #fff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.08);
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  cursor: pointer;
}

.nav-item .nav-icon {
  font-size: 17px;
}

.nav-item.active {
  color: var(--blue);
  font-weight: 700;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  background: #fff;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15.5px;
}

.modal-close {
  border: none;
  background: #f1f5f9;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
}

.stock-info-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 10px 12px;
}

.stock-prod-name {
  font-weight: 700;
  color: var(--blue-dark);
}

.stock-prod-curr {
  font-size: 12.5px;
  color: #334155;
  margin-top: 2px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12.5px;
}

.detail-table th, .detail-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.detail-table th.num, .detail-table td.num {
  text-align: right;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
}

@media (min-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  .modal-backdrop {
    align-items: center;
  }
}
