/* Algovest — tema gelap konsisten, mobile-friendly (sidebar → bottom-nav <768px). */

:root {
  --bg: #0f1420;
  --surface: #161d2e;
  --surface-2: #1d2740;
  --border: #28324a;
  --text: #e2e8f0;
  --text-muted: #8b93a7;
  --accent: #3b82f6;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 15px; }
p { margin: 6px 0; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
.pos { color: #4ade80; }
.neg { color: #f87171; }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 232px;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; z-index: 30;
}
.main { flex: 1; margin-left: 232px; display: flex; flex-direction: column; min-height: 100vh; }
.content { padding: 20px; width: 100%; max-width: 1280px; margin: 0 auto; flex: 1; }

body.logged-out .sidebar,
body.logged-out .topbar,
body.logged-out .bottom-nav { display: none !important; }
body.logged-out .main { margin-left: 0; }
body.logged-out .content { max-width: 440px; margin: 9vh auto; padding: 16px; }

/* Sidebar */
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 19px; color: #fff;
}
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); padding: 9px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav-ico { width: 22px; text-align: center; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 0 4px; min-width: 0; }
.user-chip .u-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .u-mail { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip > div { min-width: 0; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15, 20, 32, 0.92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; min-height: 56px;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-user .user-name { color: var(--text-muted); font-size: 13px; }

/* Bottom nav (mobile) */
.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  color: var(--text-muted); font-size: 13px; padding: 4px 0; border-radius: 8px;
}
.bottom-nav a span { font-size: 18px; line-height: 1.2; }
.bottom-nav a small { font-size: 10px; }
.bottom-nav a.active { color: var(--accent); }

/* ===== Komponen umum ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

.input, select.input, textarea.input {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px; font-size: 13px; font-family: inherit;
}
.input:focus { outline: 2px solid rgba(59, 130, 246, 0.4); border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }
select.input option { background: var(--surface-2); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; font-weight: 600; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Tabel */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; white-space: nowrap; }
.table th {
  color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface-2); position: sticky; top: 0; cursor: pointer; user-select: none;
}
.table th.no-sort { cursor: default; }
.table tbody tr:hover { background: rgba(29, 39, 64, 0.5); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-muted);
  padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.badge-ok { background: rgba(22, 163, 74, 0.16); border-color: rgba(22, 163, 74, 0.5); color: #4ade80; }
.badge-err { background: rgba(220, 38, 38, 0.16); border-color: rgba(220, 38, 38, 0.5); color: #f87171; }
.badge-warn { background: rgba(217, 119, 6, 0.16); border-color: rgba(217, 119, 6, 0.5); color: #fbbf24; }
.badge-accent { background: rgba(59, 130, 246, 0.16); border-color: rgba(59, 130, 246, 0.5); color: #93c5fd; }

/* Toolbar & filter */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.toolbar .input { width: auto; min-width: 150px; flex: 0 1 auto; }
.toolbar .spacer { flex: 1; }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .k-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.kpi .k-value { font-size: 19px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Kartu quote pasar */
.quote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 10px; margin-bottom: 14px; }
.quote-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; cursor: pointer; position: relative; transition: border-color 0.15s;
}
.quote-card:hover { border-color: var(--accent); }
.quote-card .q-sym { font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.quote-card .q-name { color: var(--text-muted); font-size: 11px; height: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-card .q-price { font-size: 17px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.quote-card .q-chg { margin-top: 3px; font-size: 12px; font-weight: 700; }
.quote-card .q-star {
  position: absolute; top: 8px; right: 8px; color: #fbbf24; cursor: pointer;
  background: none; border: none; font-size: 15px; padding: 2px;
}

/* Kartu saldo kas */
.cash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-bottom: 14px; }
.cash-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.cash-card .c-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dot { width: 10px; height: 10px; border-radius: 999px; flex: 0 0 auto; }
.cash-card .c-name { font-weight: 700; }
.cash-card .c-amount { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.cash-card .c-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 3px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button {
  background: none; border: none; color: var(--text-muted); padding: 9px 14px;
  font-size: 13px; font-weight: 700; cursor: pointer; border-bottom: 2px solid transparent;
  font-family: inherit; margin-bottom: -1px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 8, 16, 0.7);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  width: min(500px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-wide { width: min(680px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
.confirm-msg { margin: 0; }
#modal-form .modal-foot { margin: 0 -18px -18px; padding-bottom: 18px; border-bottom: none; }

/* Toast */
#toast-root { position: fixed; right: 16px; bottom: 76px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  color: var(--text); padding: 11px 16px; border-radius: 8px; min-width: 240px; max-width: 360px;
  opacity: 0; transform: translateY(8px); transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-size: 13px;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }

/* Chart */
.chart { position: relative; width: 100%; min-height: 60px; }
.chart .uplot { font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; }
.legend .lg { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.legend .lg i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; }
.empty { color: var(--text-muted); font-size: 13px; font-style: italic; padding: 18px 4px; text-align: center; }

/* Pagination */
.pager-wrap { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 10px 2px 0; }
.pager { display: flex; gap: 4px; flex-wrap: wrap; }
.pager-info { color: var(--text-muted); font-size: 12px; }

/* Progress (confidence) */
.progress { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; margin: 4px 0 10px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), #8b5cf6); border-radius: 999px; }

/* Login */
.login-wrap { padding: 26px; }
.login-wrap .brand-title { font-size: 24px; text-align: center; margin-bottom: 2px; }
.login-wrap .sub { text-align: center; color: var(--text-muted); margin-bottom: 18px; font-size: 13px; }
.login-logo { width: 54px; height: 54px; border-radius: 14px; margin: 0 auto 10px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 26px; color: #fff; }
.form-err { color: #f87171; font-size: 12px; margin: 8px 0 0; min-height: 16px; }

/* Rekomendasi */
.rec-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: var(--surface-2); }
.rec-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.rec-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 10px 0; }
.rec-grid .rv { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.rec-grid .rv b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.rec-grid .rv span { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.signals { margin: 8px 0 0; padding-left: 18px; }
.signals li { margin-bottom: 5px; font-size: 12.5px; }

/* Responsive */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .bottom-nav { display: flex; }
  .content { padding: 14px 12px 84px; }
  .topbar { padding: 10px 14px; }
  .topbar-user .user-name { display: none; }
  .form-row { grid-template-columns: 1fr; }
  #toast-root { left: 16px; right: 16px; align-items: stretch; }
  .toast { min-width: 0; max-width: none; }
  .table th, .table td { padding: 8px 10px; }
}
