:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-input: #0f172a;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --border: #334155;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34,197,94,0.1);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.1);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245,158,11,0.1);
  --blue: #60a5fa;
  --blue-bg: rgba(96,165,250,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --top-bar-h: 96px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* ============ App Shell: column layout ============ */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
}

/* ============ Top Navigation Bar ============ */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.top-bar-brand {
  padding: 10px 16px 4px;
  font-size: 17px;
  font-weight: 800;
  color: var(--accent);
}
.top-bar-brand span {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 8px;
}

.top-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.top-tabs::-webkit-scrollbar { display: none; }

.top-tab {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.top-tab:hover { color: var(--text); }
.top-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ============ Main Content ============ */
.main-content {
  flex: 1;
  padding: 16px;
  min-width: 0;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============ Alert Banner ============ */
.alert-banner {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 15px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.5;
}
.alert-banner.critical { background: var(--red-bg); border: 1px solid var(--red); color: var(--red); }
.alert-banner.warning { background: var(--yellow-bg); border: 1px solid var(--yellow); color: var(--yellow); }
.alert-banner.success { background: var(--green-bg); border: 1px solid var(--green); color: var(--green); }
.alert-banner.info { background: var(--blue-bg); border: 1px solid var(--blue); color: var(--blue); }

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(239,68,68,0.3); }
  50% { box-shadow: 0 0 20px rgba(239,68,68,0.6); }
}
.alert-banner.critical { animation: pulse-glow 2s infinite; }

/* ============ Cards ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-card { text-align: center; padding: 14px 12px; }
.stat-card .stat-value {
  font-size: 28px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.positive { color: var(--green); }
.negative { color: var(--red); }

/* ============ Market Ticker (calendar page top) ============ */
.market-ticker {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 4px;
  margin-bottom: 12px;
}
.market-ticker::-webkit-scrollbar { display: none; }

.ticker-card {
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  min-width: 110px;
  text-align: center;
}
.ticker-name { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; white-space: nowrap; }
.ticker-price { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ticker-change { font-size: 13px; font-weight: 600; margin-top: 2px; }

.pig-ticker {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 6px 0;
  margin-bottom: 12px;
}
.pig-ticker strong { color: var(--text); }

/* ============ Action Checklist ============ */
.action-card {
  border: 2px solid var(--accent);
  background: linear-gradient(135deg, rgba(59,130,246,0.05), rgba(59,130,246,0.02));
  margin-bottom: 16px;
}
.action-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.action-header .title {
  font-size: 16px;
  font-weight: 800;
}
.action-header .date-label {
  font-size: 13px;
  color: var(--text-muted);
}
.action-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  gap: 8px;
}
.action-item.completed {
  opacity: 0.5;
  background: var(--green-bg);
  border-color: var(--green);
}
.action-item.muted {
  opacity: 0.5;
}
.action-item .item-left { flex: 1; min-width: 0; }
.action-item .item-name { font-size: 15px; font-weight: 700; }
.action-item .item-detail { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.action-item .item-right { text-align: right; flex-shrink: 0; }
.action-item .item-amount { font-size: 18px; font-weight: 800; }
.action-item .item-sub { font-size: 12px; color: var(--text-muted); }

.action-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  font-size: 15px;
}

.action-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  padding: 6px 10px;
  background: rgba(59,130,246,0.06);
  border-radius: var(--radius-sm);
}

/* ============ Rolling State ============ */
.rolling-card {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.rolling-card .stock-label { font-weight: 700; margin-bottom: 4px; font-size: 14px; }
.rolling-bar-track {
  height: 8px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0 4px;
}
.rolling-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s; }
.rolling-status { font-size: 13px; color: var(--text-muted); }

/* ============ Info Flow (Dashboard) ============ */
.hero-number {
  text-align: center;
  padding: 20px 16px 8px;
}
.hero-number .big {
  font-size: 40px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}
.hero-number .sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.progress-bar-section {
  padding: 12px 16px;
}
.progress-track {
  height: 10px;
  background: var(--bg);
  border-radius: 5px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.6s ease;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.quick-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 0 8px;
  margin-bottom: 12px;
}
.quick-scroll::-webkit-scrollbar { display: none; }
.quick-card {
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 140px;
  text-align: center;
}
.quick-card .qc-value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.quick-card .qc-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.position-list { margin-bottom: 16px; }
.position-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.position-row .pos-left {}
.position-row .pos-name { font-size: 15px; font-weight: 700; }
.position-row .pos-meta { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.position-row .pos-right { text-align: right; }
.position-row .pos-pnl { font-size: 20px; font-weight: 800; }
.position-row .pos-mv { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ============ Profit Targets ============ */
.profit-bar-track {
  height: 20px;
  background: var(--bg);
  border-radius: 10px;
  position: relative;
  overflow: visible;
  margin: 16px 0 8px;
}
.profit-bar-fill {
  height: 100%;
  border-radius: 10px;
  transition: width 0.6s ease;
  min-width: 2px;
}
.profit-marker {
  position: absolute;
  top: -6px;
  width: 2px;
  height: 32px;
  transform: translateX(-50%);
}
.profit-marker .marker-label {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  white-space: nowrap;
  color: var(--text-muted);
}
.profit-marker.reached .marker-label { color: var(--green); font-weight: 700; }

/* ============ Contingency ============ */
.contingency-bar { flex: 1; height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.contingency-fill { height: 100%; border-radius: 5px; background: var(--accent); transition: width 0.3s; }

/* ============ Tables ============ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  text-align: left;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  white-space: nowrap;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tr:hover td { background: var(--bg-card-hover); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============ Schedule Cards ============ */
.schedule-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.schedule-card.executed { opacity: 0.5; }
.schedule-card.current { border-color: var(--accent); }
.schedule-card .sc-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.schedule-card .sc-week { font-weight: 800; font-size: 16px; }
.schedule-card .sc-allocs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}
.schedule-card .sc-allocs strong { color: var(--text); }
.schedule-card .sc-event {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
}

.schedule-phase-label {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.sc-event.red { color: var(--red); }
.sc-event.yellow { color: var(--yellow); }
.sc-event.blue { color: var(--blue); }

/* ============ Forms ============ */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.form-input, .form-select {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  min-height: 44px;
  user-select: none;
  -webkit-user-select: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text); }
.btn-sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }
.btn-xs { padding: 6px 10px; font-size: 12px; min-height: 32px; }
.btn-block { width: 100%; }

/* ============ Chart container ============ */
.chart-container { position: relative; height: 240px; margin: 12px 0; }

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-size: 15px;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ============ Indicator Health ============ */
.health-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}
.health-badge.healthy { background: var(--green-bg); color: var(--green); }
.health-badge.warning { background: var(--yellow-bg); color: var(--yellow); }
.health-badge.critical { background: var(--red-bg); color: var(--red); }

/* ============ Toast ============ */
.toast-container {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  animation: slideDown 0.3s ease;
  max-width: 400px;
  width: auto;
  text-align: center;
  pointer-events: auto;
}
.toast.success { background: var(--green); color: white; }
.toast.error { background: var(--red); color: white; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } }

/* ============ Transaction Card List ============ */
.tx-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 8px;
}
.tx-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.tx-card .card-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 14px;
}
.tx-card .card-body .label { color: var(--text-muted); font-size: 12px; }
.tx-card .card-body .value { font-weight: 600; }
.tx-card .card-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-sheet {
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px 16px;
  padding-bottom: calc(20px + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}
.modal-sheet h3 {
  font-size: 17px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-close {
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border: none;
  background: none;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }

/* ============ Loading ============ */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 12px;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Holiday Tag ============ */
.holiday-tag {
  font-size: 12px;
  color: var(--yellow);
  background: rgba(245, 158, 11, 0.1);
  padding: 2px 8px;
  border-radius: 6px;
  margin-top: 4px;
}

/* ============ Utility ============ */
.section-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============ Desktop: wider max-width, centered ============ */
@media (min-width: 769px) {
  .app-shell { max-width: 640px; }
  .card { padding: 18px; }
}

/* ============ Small phones ============ */
@media (max-width: 375px) {
  .main-content { padding: 12px; }
  .top-tab { padding: 10px 12px; font-size: 13px; }
  .hero-number .big { font-size: 32px; }
}
