:root {
  --primary: #378ADD;
  --primary-dark: #2a6bb5;
  --primary-light: #e8f1fb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --card: #ffffff;
  --nav-h: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior: none;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100dvh; }

.header {
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(55,138,221,.3);
}
.header h1 { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.header-actions { display: flex; gap: 8px; }
.btn-icon {
  background: rgba(255,255,255,.18);
  border: none;
  color: white;
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-icon:active { background: rgba(255,255,255,.3); }

.main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + 8px);
}

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 9px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 2px;
  transition: color .15s;
  min-height: 44px;
}
.nav-item .nav-icon { font-size: 22px; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { transform: scale(1.1); }

/* ── Sections ── */
.section { display: none; padding: 16px; }
.section.active { display: block; }

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}

/* ── Home Dashboard ── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  text-align: center;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.1;
}
.stat-value.green { color: var(--success); }
.stat-value.red { color: var(--danger); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}
.quick-btn {
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  border-radius: var(--radius);
  padding: 14px 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 72px;
  transition: background .15s;
}
.quick-btn:active { background: #d0e4f7; }
.quick-btn .qb-icon { font-size: 24px; }

/* ── Forms ── */
.form-group { margin-bottom: 12px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color .15s;
  appearance: none;
  -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(55,138,221,.15);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 20px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  min-height: 48px;
  width: 100%;
}
.btn:active { opacity: .85; transform: scale(.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}
.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  min-height: 36px;
  border-radius: 8px;
  width: auto;
}
.btn-group { display: flex; gap: 8px; }

/* ── Research Result ── */
.result-box {
  background: var(--primary-light);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
  display: none;
}
.result-box.show { display: block; }
.price-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.price-item { text-align: center; }
.price-label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.price-val { font-size: 18px; font-weight: 700; color: var(--text); }

.profit-result {
  background: white;
  border-radius: 10px;
  padding: 14px;
  margin-top: 10px;
}
.profit-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.profit-row:last-child { border-bottom: none; }
.profit-row .label { font-size: 13px; color: var(--text-muted); }
.profit-row .value { font-size: 15px; font-weight: 600; }
.profit-row .value.positive { color: var(--success); }
.profit-row .value.negative { color: var(--danger); }

.ai-response {
  background: white;
  border-radius: 10px;
  padding: 14px;
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ── Lists ── */
.list-item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-blue { background: var(--primary-light); color: var(--primary); }
.badge-green { background: #dcfce7; color: #16a34a; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-orange { background: #ffedd5; color: #ea580c; }

/* ── Tabs ── */
.tabs {
  display: flex;
  background: white;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.tab-btn {
  flex: 1;
  padding: 9px 6px;
  border: none;
  background: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  min-height: 36px;
}
.tab-btn.active { background: var(--primary); color: white; }

.sub-section { display: none; }
.sub-section.active { display: block; }

/* ── Chart ── */
.chart-wrap { position: relative; height: 200px; margin-top: 8px; }

/* ── Loader ── */
.loader {
  display: none;
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 13px;
}
.loader.show { display: block; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 20px 16px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close {
  background: var(--bg);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 600;
  transition: transform .25s ease;
  white-space: nowrap;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Settings ── */
.settings-item {
  display: flex;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.settings-item:last-child { border-bottom: none; }
.settings-item label { flex: 1; font-size: 14px; font-weight: 500; }
.settings-item .form-input { width: auto; flex: 1; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; }

/* ── Section Title ── */
.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── AmaSearch result ── */
.ama-result-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid var(--primary);
}
.ama-result-card.buy { border-left-color: var(--success); }
.ama-result-card.hold { border-left-color: var(--warning); }
.ama-result-card.skip { border-left-color: var(--danger); }

.verdict {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.verdict.buy { background: #dcfce7; color: #16a34a; }
.verdict.hold { background: #ffedd5; color: #ea580c; }
.verdict.skip { background: #fee2e2; color: #dc2626; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

@media (min-width: 480px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .quick-actions { grid-template-columns: repeat(4, 1fr); }
}
