:root {
  --navy-950: #070c1a;
  --navy-900: #0b1226;
  --navy-800: #101b38;
  --navy-700: #16234a;
  --gold-600: #a8823f;
  --gold-500: #c9a15a;
  --gold-400: #ddc182;
  --gold-100: #f3e9d2;
  --cream: #f7f3ea;
  --cream-2: #fbf8f2;
  --paper: #fffdf8;
  --ink: #191d2b;
  --muted: #837c6c;
  --hairline: rgba(168, 130, 63, 0.22);
  --pos: #1e7a52;
  --neg: #9a3b32;
  --shadow: 0 10px 30px -12px rgba(16, 27, 56, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--cream);
  padding-bottom: 48px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  background: linear-gradient(160deg, var(--navy-950) 0%, var(--navy-800) 100%);
  color: #fff;
  padding: 28px 22px 20px;
  border-bottom: 1px solid var(--gold-600);
  position: relative;
}
.brand-kicker {
  font-size: 10.5px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--gold-400);
  margin-bottom: 4px;
  font-weight: 600;
}
.topbar h1 {
  margin: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  font-size: 30px;
  letter-spacing: 0.5px;
  color: #f8f4ea;
}
.icon-btn {
  background: rgba(201, 161, 90, 0.14);
  border: 1px solid rgba(201, 161, 90, 0.4);
  color: var(--gold-400);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.icon-btn:hover { background: rgba(201, 161, 90, 0.26); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  padding: 14px 16px;
  background: var(--navy-900);
}
.tab-btn {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid transparent;
  border-radius: 20px;
  background: transparent;
  color: rgba(243, 233, 210, 0.55);
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab-btn:hover { color: var(--gold-100); }
.tab-btn.active {
  background: var(--gold-500);
  color: var(--navy-950);
  border-color: var(--gold-500);
}

.tab-panel { display: none; padding: 18px 16px; }
.tab-panel.active { display: block; }

/* ---------- Cards ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 700;
  font-size: 19px;
  margin-bottom: 12px;
  color: var(--navy-900);
  letter-spacing: 0.2px;
}
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-title-row .card-title { margin-bottom: 0; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(160deg, var(--navy-950) 0%, var(--navy-700) 100%);
  color: #fff;
  border: 1px solid var(--gold-600);
  padding: 26px 24px 20px;
}
.hero-top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.hero-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--gold-400);
  font-weight: 600;
  margin-bottom: 10px;
}
.refresh-btn {
  background: rgba(201, 161, 90, 0.14);
  border: 1px solid rgba(201, 161, 90, 0.4);
  color: var(--gold-400);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.4s ease, background 0.15s ease;
}
.refresh-btn:hover { background: rgba(201, 161, 90, 0.28); }
.refresh-btn.spinning { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hero-live-badge {
  font-size: 11px;
  font-weight: 600;
  margin-top: 8px;
  min-height: 14px;
}
.hero-live-badge.live { color: #7fd6ab; }
.hero-live-badge.stale { color: rgba(243, 233, 210, 0.55); }
.hero-live-badge.error { color: #e08b7d; }
.hero-value {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 600;
  font-size: 42px;
  line-height: 1.05;
  color: #faf6ea;
  letter-spacing: 0.3px;
}
.hero-value .thb {
  font-family: 'Manrope', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--gold-400);
  letter-spacing: 1px;
  margin-right: 8px;
  vertical-align: middle;
}
.hero-sub {
  font-size: 12.5px;
  color: rgba(243, 233, 210, 0.6);
  margin-top: 8px;
}
.hero-divider {
  height: 1px;
  background: linear-gradient(90deg, rgba(201,161,90,0.5), rgba(201,161,90,0));
  margin: 18px 0 16px;
}
.hero-foot { display: flex; align-items: center; }
.hero-foot > div { flex: 1; }
.hero-foot-sep { flex: 0 0 1px !important; width: 1px; align-self: stretch; background: rgba(201,161,90,0.25); margin: 0 16px; }
.hero-foot-label {
  font-size: 10.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: rgba(243, 233, 210, 0.5);
  margin-bottom: 5px;
  font-weight: 600;
}
.hero-foot-value {
  font-size: 16px;
  font-weight: 700;
  color: #f3ecdb;
  font-variant-numeric: tabular-nums;
}
.hero-foot-value.negative { color: #e08b7d; }
.hero-foot-value.positive { color: #7fd6ab; }

/* ---------- Stat cards (legacy support) ---------- */
.card-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-card {
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; font-weight: 600; }
.stat-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.negative { color: var(--neg); }
.stat-value.positive { color: var(--pos); }

/* ---------- Fund list ---------- */
.fund-list { display: flex; flex-direction: column; gap: 10px; }
.fund-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--cream-2);
  border: 1px solid var(--hairline);
  cursor: pointer;
  transition: all 0.15s ease;
}
.fund-row:hover { background: var(--gold-100); border-color: var(--gold-500); }
.fund-row-name { font-weight: 700; font-size: 14.5px; color: var(--navy-900); }
.fund-row-code { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.row-live-tag {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 8px;
  background: rgba(30, 122, 82, 0.12);
  color: var(--pos);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  vertical-align: middle;
}
.fund-row-value { text-align: right; }
.fund-row-value .v { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; color: var(--navy-900); }
.fund-row-value .d { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- Form fields ---------- */
.field-row { margin-bottom: 12px; }
.field-row label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
select, input[type=text], input[type=number], input[type=date] {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid #ddd3bd;
  font-size: 14px;
  background: var(--cream-2);
  color: var(--ink);
  font-family: 'Manrope', sans-serif;
}
select:focus, input:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(201, 161, 90, 0.18);
}

/* ---------- Buttons ---------- */
.btn-small {
  background: var(--navy-900);
  color: var(--gold-400);
  border: 1px solid var(--gold-600);
  border-radius: 20px;
  padding: 8px 15px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-small:hover { background: var(--navy-700); }
.btn-small-ghost {
  background: var(--cream-2);
  color: var(--navy-900);
  border-color: var(--hairline);
}
.btn-small-ghost:hover { background: var(--gold-100); }
.btn-small.spinning { opacity: 0.6; pointer-events: none; }

.asset-status-line {
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 10px;
  min-height: 14px;
}
.asset-status-line.error { color: var(--neg); }
.asset-status-line.ok { color: var(--pos); }
.btn-primary {
  background: var(--navy-900);
  color: var(--gold-400);
  border: 1px solid var(--gold-600);
  border-radius: 10px;
  padding: 13px 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  flex: 1;
  transition: all 0.15s ease;
}
.btn-primary:hover { background: var(--navy-700); }
.btn-secondary {
  background: var(--cream-2);
  color: var(--navy-900);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 13px 16px;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
}
.btn-secondary:hover { background: var(--gold-100); }

/* ---------- Detail table ---------- */
.detail-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.detail-table td { padding: 9px 4px; border-bottom: 1px solid var(--hairline); }
.detail-table td:first-child { color: var(--muted); font-weight: 500; }
.detail-table td:last-child { text-align: right; font-weight: 700; color: var(--navy-900); font-variant-numeric: tabular-nums; }
.detail-table tr:last-child td { border-bottom: none; }

/* ---------- Asset rows ---------- */
.asset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--hairline);
}
.asset-row:last-child { border-bottom: none; }
.asset-left { display: flex; align-items: center; gap: 12px; }
.asset-badge {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(160deg, var(--navy-800), var(--navy-950));
  color: var(--gold-400);
  border: 1px solid var(--gold-600);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  font-family: 'Cormorant Garamond', Georgia, serif;
  flex-shrink: 0;
}
.asset-name { font-weight: 700; font-size: 13.5px; color: var(--navy-900); }
.asset-units { font-size: 11px; color: var(--muted); margin-top: 2px; }
.asset-right { text-align: right; }
.asset-value { font-weight: 700; font-size: 13.5px; color: var(--navy-900); font-variant-numeric: tabular-nums; }
.asset-pct { font-size: 11px; color: var(--gold-600); margin-top: 2px; font-weight: 600; }
.asset-delta { font-size: 11px; margin-top: 2px; font-weight: 700; font-variant-numeric: tabular-nums; }
.asset-delta.positive { color: var(--pos); }
.asset-delta.negative { color: var(--neg); }
.row-actions { display: flex; gap: 6px; margin-left: 10px; }
.row-actions button {
  border: 1px solid var(--hairline); background: var(--cream-2); border-radius: 8px;
  width: 28px; height: 28px; cursor: pointer; font-size: 12px; color: var(--navy-900);
}
.row-actions button:hover { background: var(--gold-100); }

/* ---------- History ---------- */
.history-item {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--cream-2);
  border: 1px solid var(--hairline);
  margin-bottom: 10px;
}
.history-item-top { display: flex; justify-content: space-between; font-weight: 700; font-size: 13.5px; color: var(--navy-900); }
.history-item-top span:last-child { font-variant-numeric: tabular-nums; }
.history-item-sub { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.history-item-actions { margin-top: 10px; display: flex; gap: 8px; }
.history-item-actions button {
  border: 1px solid var(--hairline); background: var(--paper); border-radius: 8px; padding: 7px 12px; font-size: 11.5px; cursor: pointer; font-weight: 600; color: var(--navy-900);
}
.history-item-actions button:hover { background: var(--gold-100); }

/* ---------- Manage rows ---------- */
.manage-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--hairline);
}
.manage-row:last-child { border-bottom: none; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(7, 12, 26, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--paper); width: 100%; max-width: 480px;
  border-radius: 22px 22px 0 0; padding: 22px;
  max-height: 88vh; overflow-y: auto;
  border-top: 1px solid var(--gold-500);
}
.modal-scroll { overflow-y: auto; }
.modal-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-weight: 700;
  font-size: 22px;
  margin-bottom: 16px;
  color: var(--navy-900);
}
.modal label { display: block; font-size: 11.5px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 12px; line-height: 1.5; }

.empty-hint { font-size: 13px; color: var(--muted); padding: 10px 0; }

/* ---------- Lock / loading screens ---------- */
.lock-screen {
  align-items: center;
  z-index: 200;
  background: linear-gradient(160deg, var(--navy-950) 0%, var(--navy-700) 100%);
}
.lock-modal {
  border-radius: 22px;
  border-top: 1px solid var(--gold-500);
  max-width: 380px;
}
.lock-loading { text-align: center; color: var(--gold-100); }
.lock-loading-text {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 20px;
  margin-top: 10px;
  color: #faf6ea;
}
