:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #135eb1;
  --primary-dark: #0d47a1;
  --primary-soft: #e8f0fe;
  --accent: #ff6a00;
  --accent-soft: #fff0e6;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

/* LOGIN */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #e8f0fe 0%, #f8fafc 50%, #fff0e6 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px 22px;
  box-shadow: 0 18px 45px rgba(19, 94, 177, 0.12);
}

.brand-logo-login {
  display: block;
  height: 44px;
  width: auto;
  margin: 0 auto 14px;
  object-fit: contain;
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; color: var(--primary-dark); }
.subtitle { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; text-align: center; }
.hint { margin: 14px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }

/* APP SHELL */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 680px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.04);
}

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo {
  height: 30px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.topbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}
.topbar-title { font-weight: 700; font-size: 15px; line-height: 1.2; color: var(--primary-dark); }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--primary-dark);
  font-size: 18px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); background: var(--primary-soft); }

.main-content {
  flex: 1;
  padding: 14px 14px calc(var(--nav-h) + var(--safe-bottom) + 20px);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* STATS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--primary);
}
.stat-card:nth-child(2) { border-top-color: var(--accent); }
.stat-card:nth-child(3) { border-top-color: #059669; }
.stat-card:nth-child(4) { border-top-color: #7c3aed; }
.stat-card.skeleton { height: 84px; opacity: 0.5; }
.stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -0.5px; color: var(--text); }
.stat-sub { font-size: 11.5px; color: var(--primary); margin-top: 2px; font-weight: 600; }

/* SECTION HEADS */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
}
.section-head h2, .section-head h3 { margin: 0; font-size: 15.5px; font-weight: 700; color: var(--text); }
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 0;
}

/* QUICK ACTIONS */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.quick-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.quick-btn:active { background: var(--primary-soft); border-color: var(--primary); transform: scale(0.98); }
.q-ico { font-size: 20px; }
.pill-count {
  margin-left: auto;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
}

/* STICKY CONTROLS */
.sticky-controls {
  position: sticky;
  top: calc(59px + var(--safe-top));
  z-index: 20;
  background: var(--bg);
  padding: 6px 0 10px;
  margin-bottom: 6px;
}
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background: var(--surface);
  color: var(--text);
  font-size: 14.5px;
}
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.filter-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filter-pills::-webkit-scrollbar { display: none; }
.pill {
  flex-shrink: 0;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.list-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 500;
}

/* CARDS */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card-list .card { margin-bottom: 0; }
.card-title { margin: 0 0 6px; font-size: 15.5px; font-weight: 700; color: var(--primary-dark); }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.item-title { font-weight: 700; font-size: 15px; line-height: 1.3; word-break: break-word; color: var(--text); }
.item-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; word-break: break-word; }
.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* BADGES */
.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-green { background: #dcfce7; color: #047857; }
.badge-yellow { background: #fff0e6; color: #c2410c; }
.badge-blue { background: #e8f0fe; color: #135eb1; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 11px;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; pointer-events: none; }
.btn-lg { height: 48px; font-size: 15.5px; border-radius: 13px; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 12.5px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, #135eb1, #0d47a1);
  color: #fff;
  box-shadow: 0 4px 12px rgba(19, 94, 177, 0.22);
}
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid #cbd5e1; }
.btn-success { background: #dcfce7; color: #047857; border: 1px solid #86efac; }
.btn-danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }

/* FORMS */
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12.5px; color: #334155; font-weight: 600; }
.field input, .field select, .field textarea, .textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
}
.field input[readonly] { background: #f1f5f9; color: #64748b; }
.field input:focus, .field select:focus, .field textarea:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-gap { display: flex; gap: 8px; margin-top: 10px; }
.check-row { display: flex; gap: 14px; flex-wrap: wrap; padding: 4px 0; }
.check-row label { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--text); }

.error-box {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
}

/* BOTTOM NAV */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  max-width: 680px;
  margin: 0 auto;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.05);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.nav-item {
  background: none;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.nav-ico { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--accent); }

/* MODAL BOTTOM SHEET */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: 680px;
  max-height: 90dvh;
  background: var(--surface);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  border: 1px solid var(--border);
  border-bottom: none;
  box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.16);
  display: flex;
  flex-direction: column;
  padding-bottom: calc(14px + var(--safe-bottom));
}
.modal-handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: #cbd5e1;
  margin: 10px auto 4px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16.5px; color: var(--primary-dark); }
.modal-body {
  padding: 14px 16px 10px;
  overflow-y: auto;
}

/* AI PREVIEW */
.ai-preview {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 13.5px;
  white-space: pre-wrap;
  color: var(--text);
}

/* TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 80;
  background: var(--primary-dark);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(13, 71, 161, 0.35);
  max-width: 92vw;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  font-size: 14px;
}

.info-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.info-box-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.info-row .k { color: var(--muted); }
.info-row .v { color: var(--text); font-weight: 600; text-align: right; word-break: break-word; }
.mini-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.mini-list-item {
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: 9px;
  background: #ffffff;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* AI MULTIMODAL CONTROLS */
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}
.mode-btn {
  height: 38px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.mode-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.upload-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 14px;
  margin-bottom: 10px;
  border: 1.5px dashed #93c5fd;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.upload-box:active { opacity: 0.85; }
.upload-ico { font-size: 18px; }

.img-preview-wrap {
  position: relative;
  margin-bottom: 10px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.img-preview-wrap img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}
.img-remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

.inline-key-box {
  margin-top: 10px;
  padding: 10px;
  border-radius: 11px;
  background: var(--accent-soft);
  border: 1px solid #fed7aa;
}

.match-banner {
  margin-bottom: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #047857;
  font-size: 13px;
  font-weight: 600;
}

.logo-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-input-row input[name="logo"] {
  flex: 1;
  min-width: 0;
}
.logo-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  object-fit: contain;
  flex-shrink: 0;
  padding: 2px;
}

.ai-top-btn {
  height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid #fed7aa;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.ai-top-btn:active { transform: scale(0.96); }

.overdue-tag {
  display: inline-block;
  margin-top: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 11.5px;
  font-weight: 700;
}

.score-bar-bg {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-top: 8px;
}
.score-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--success);
}
.score-bar-fill.mid { background: var(--warning); }
.score-bar-fill.low { background: var(--danger); }



