/* ============================================================
   public/css/style.css
   Desain dashboard profesional: sidebar (desktop) + bottom nav
   (mobile), mode terang & gelap, dashboard harga/chart kripto,
   dan kalkulator dengan pratinjau langsung yang ramah pengguna.
============================================================ */

:root {
  --font-sans: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eaf1ff;
  --green: #17915a;
  --green-soft: #e8f8ef;
  --red: #dc2626;
  --red-soft: #fdeceb;
  --amber: #b98900;

  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8f0;
  --text: #0f1b2d;
  --text-muted: #64748b;
  --sidebar-bg: #0b1524;
  --sidebar-text: #c3cee0;
  --sidebar-active: #2563eb;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 8px rgba(16, 24, 40, 0.05);
  --shadow-lift: 0 6px 20px rgba(16, 24, 40, 0.09);
}

[data-theme="dark"] {
  --bg: #0a0f1a;
  --surface: #121a2b;
  --surface-2: #0f1626;
  --border: #21304a;
  --text: #e8edf6;
  --text-muted: #92a1ba;
  --blue-soft: rgba(37, 99, 235, 0.16);
  --green-soft: rgba(23, 145, 90, 0.16);
  --red-soft: rgba(220, 38, 38, 0.16);
  --sidebar-bg: #060a13;
  --sidebar-text: #aebbd4;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-lift: 0 10px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Offline banner ---------------- */
.offline-banner {
  background: #fff3cd;
  color: #7a5b00;
  text-align: center;
  font-size: 13px;
  padding: 8px 12px;
  position: sticky;
  top: 0;
  z-index: 200;
}

/* ---------------- App shell layout ---------------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 26px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; }
.brand-name { font-size: 16.5px; font-weight: 700; color: white; letter-spacing: -0.01em; }
.brand-name b { font-weight: 800; color: #5b9bff; }

.nav-rail { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: none; color: var(--sidebar-text);
  padding: 10px 12px; border-radius: 10px; font-size: 14.5px; font-weight: 500;
  cursor: pointer; text-align: left; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255,255,255,0.07); }
.nav-item.active { background: var(--sidebar-active); color: white; box-shadow: 0 4px 14px rgba(37,99,235,0.35); }
.nav-icon { font-size: 17px; }

.sidebar-footer { margin-top: 12px; padding: 10px 6px 2px; }
.sidebar-brand-mini { font-size: 11px; color: var(--text-muted); opacity: 0.7; }

/* ---------------- Main content ---------------- */
.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
}
.topbar-title { display: flex; align-items: center; gap: 12px; }
.topbar-title h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
.sync-status { font-size: 12.5px; color: var(--text-muted); background: var(--bg); padding: 4px 10px; border-radius: 20px; }
.topbar-actions .user-chip-top { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.topbar-actions button { font-size: 13px; }
.topbar-chip {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; padding: 7px 13px; border-radius: 20px; white-space: nowrap;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
}
.topbar-chip:hover { border-color: var(--blue); color: var(--blue); }

.page-content { padding: 24px 28px 60px; max-width: 1160px; }
.page { display: none; }
.page.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------- Cards & grid ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin-top: 0; font-size: 16.5px; letter-spacing: -0.01em; }
.card h3 { margin: 0; font-size: 14.5px; letter-spacing: -0.005em; }
.grid { display: grid; gap: 16px; margin-bottom: 20px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .grid-3 { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 24px; font-weight: 800; margin: 6px 0 2px; letter-spacing: -0.02em; }
.stat-sub { font-size: 12.5px; color: var(--text-muted); }
.stat-sub.up { color: var(--green); }
.stat-sub.down { color: var(--red); }

/* ---------------- Buttons & inputs ---------------- */
input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft);
}
button {
  background: var(--blue); color: white; border: none; cursor: pointer; font-weight: 600;
  transition: filter 0.15s, transform 0.1s;
}
button:hover { filter: brightness(1.07); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
button.danger { color: var(--red); }
.link-btn { background: none !important; color: var(--blue) !important; padding: 0 !important; font-weight: 600; font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.space-between { justify-content: space-between; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.quick-btn { background: var(--bg); color: var(--text); border: 1px solid var(--border); font-weight: 500; font-size: 13.5px; padding: 10px 14px; border-radius: 10px; }
.quick-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ---------------- Dashboard: harga & chart kripto ---------------- */
.dashboard-head-card { padding-bottom: 20px; }
.dashboard-head-row { align-items: flex-start; margin-bottom: 6px; }
#dashFetchStatus { font-size: 12px; }

.coin-cards {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
  margin: 16px 0 20px;
}
@media (max-width: 760px) { .coin-cards { grid-template-columns: 1fr; } }

.coin-card {
  background: var(--surface-2); border: 1.5px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 16px; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.coin-card:hover { border-color: var(--blue); transform: translateY(-1px); }
.coin-card.active { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.coin-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.coin-icon { width: 26px; height: 26px; border-radius: 50%; }
.coin-name { font-weight: 700; font-size: 13.5px; }
.coin-symbol { font-size: 11.5px; color: var(--text-muted); }
.coin-change { margin-left: auto; font-size: 12.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.coin-change.up { color: var(--green); background: var(--green-soft); }
.coin-change.down { color: var(--red); background: var(--red-soft); }
.coin-price { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 6px; }
.coin-price.skeleton { color: var(--text-muted); font-weight: 600; font-size: 14px; }
.coin-spark { width: 100%; height: 44px; display: block; }

.chart-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px 18px;
}
.chart-head { margin-bottom: 4px; flex-wrap: wrap; gap: 8px; }
.chart-range-tabs { display: flex; gap: 6px; }
.chart-range-tabs button {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 20px;
}
.chart-range-tabs button.active { background: var(--blue); color: white; border-color: var(--blue); }
.chart-canvas-wrap { position: relative; height: 260px; margin-top: 8px; }
#mainChart { width: 100% !important; height: 100% !important; }

/* ---------------- Calculator tabs & form ---------------- */
.group-tabs { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
.group-tabs::-webkit-scrollbar { display: none; }
.group-tabs button { display: flex; align-items: center; gap: 6px; background: var(--bg); color: var(--text-muted); font-size: 13px; padding: 7px 14px; border-radius: 20px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.group-tabs button.active { background: var(--blue); color: white; }
.tab-icon { font-size: 13px; }
.group-desc { margin: 0 0 14px; }

.tabs { display: flex; flex-wrap: nowrap; gap: 6px; margin-bottom: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: var(--bg); color: var(--text); font-weight: 500; font-size: 13px; padding: 7px 12px; white-space: nowrap; flex-shrink: 0; }
.tabs button.active { background: var(--blue-dark); color: white; }

.calc-desc { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }

.calc-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
@media (max-width: 620px) { .calc-form { grid-template-columns: 1fr; } }
.calc-form .field { display: flex; flex-direction: column; }
.calc-form .field.field-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.calc-form .field.field-checkbox label { margin-bottom: 0; order: 2; }
.calc-form .field.field-checkbox input { order: 1; width: auto; }
.calc-form label { font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
.calc-form input, .calc-form select, .calc-form textarea { width: 100%; }
.calc-form textarea { min-height: 80px; font-family: var(--font-mono); font-size: 13px; }
.calc-form .full-width { grid-column: 1 / -1; }
.field-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.calc-form-actions { display: flex; align-items: center; gap: 14px; margin-top: 4px; flex-wrap: wrap; }
.calc-form-actions button[type="submit"] { padding: 12px 20px; font-size: 14.5px; }
.live-badge { font-size: 11.5px; color: var(--green); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }

.result {
  margin-top: 18px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 18px 20px; font-size: 13.5px;
  animation: fadeIn 0.15s ease;
}
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px 20px; }
.result-item .r-label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.result-item .r-value { font-size: 17px; font-weight: 800; margin-top: 3px; letter-spacing: -0.01em; }
.result-item .r-value.pos { color: var(--green); }
.result-item .r-value.neg { color: var(--red); }
.result-raw { margin-top: 12px; font-size: 12px; color: var(--text-muted); white-space: pre-wrap; font-family: var(--font-mono); }

.hint { color: var(--text-muted); font-size: 12.5px; margin-top: 8px; }
.error { color: var(--red); font-size: 13px; }

.user-chip-full {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; font-size: 14px;
}
.convert-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.convert-row input { flex: 1 1 140px; min-width: 0; }
.convert-sep { font-size: 12.5px; color: var(--text-muted); }

/* ---------------- History ---------------- */
.history-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.history-item {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 13px; position: relative; background: var(--surface-2);
}
.history-item .h-title { font-weight: 700; color: var(--blue); font-size: 13.5px; }
.history-item .h-date { color: var(--text-muted); font-size: 11px; margin-bottom: 4px; }
.history-item .h-delete { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--red); cursor: pointer; font-size: 12px; padding: 2px 6px; }
.history-item .h-summary { font-size: 13px; margin-top: 4px; }

/* ---------------- Holdings rows (portfolio) ---------------- */
.holdings-rows { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.holding-row { display: grid; grid-template-columns: 1.4fr 1fr 1.2fr auto; gap: 8px; }
@media (max-width: 620px) { .holding-row { grid-template-columns: 1fr 1fr; } }
.holding-row button { background: var(--bg); color: var(--red); border: 1px solid var(--border); padding: 8px; }

.portfolio-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 14px; }
.portfolio-table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 13px; }
.portfolio-table th { text-align: left; font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.portfolio-table td { padding: 10px; border-bottom: 1px solid var(--border); }
.alloc-bar { height: 6px; border-radius: 4px; background: var(--blue); }
.alloc-track { background: var(--border); border-radius: 4px; height: 6px; width: 100px; overflow: hidden; }
.portfolio-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-top: 16px; }

/* ---------------- Bottom nav (mobile) ---------------- */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  justify-content: space-around; padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 50;
}
.bn-item { background: none; border: none; color: var(--text-muted); font-size: 11px; padding: 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bn-item span { font-size: 18px; }
.bn-item.active { color: var(--blue); font-weight: 700; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .page-content { padding: 18px 16px 90px; }
  .topbar { padding: 14px 16px; }

  /* Cegah auto-zoom Safari iOS saat fokus ke input (butuh font-size >= 16px) */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Perbesar area sentuh tombol supaya nyaman ditekan jari */
  button {
    min-height: 40px;
  }
  .tabs button, .group-tabs button, .quick-btn {
    min-height: 36px;
  }

  .card { padding: 18px 16px; border-radius: 14px; }
  .stat-value { font-size: 21px; }
  .topbar-title h1 { font-size: 17px; }
  .sync-status { display: none; } /* hemat ruang di layar kecil, status tetap ada di banner offline */
  .holding-row { grid-template-columns: 1fr; }
  .convert-row { flex-direction: column; align-items: stretch; }
  .convert-row input, .convert-row button { width: 100%; }
  .dashboard-head-row { flex-direction: column; align-items: stretch; }
  .dashboard-head-row .row { justify-content: space-between; }
  .chart-canvas-wrap { height: 220px; }
}

@media (max-width: 380px) {
  .page-content { padding: 14px 12px 90px; }
  .card { padding: 14px 12px; }
  .quick-actions { gap: 8px; }
  .quick-btn { padding: 9px 11px; font-size: 12.5px; }
}

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(9,14,24,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 300; padding: 16px;
}
.modal-content { background: var(--surface); border-radius: 18px; padding: 26px 28px; width: min(340px, 92vw); position: relative; box-shadow: var(--shadow-lift); max-height: 90vh; overflow-y: auto; }
.modal-close { position: absolute; top: 12px; right: 14px; background: none; color: var(--text-muted); border: none; font-size: 16px; padding: 2px 6px; }
.modal-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-brand img { width: 30px; height: 30px; border-radius: 8px; }
.modal-brand h2 { margin: 0; font-size: 17px; }
.modal-content form { display: flex; flex-direction: column; gap: 8px; }
.modal-content label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
