:root { color-scheme: dark; }
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font: 14px/1.5 system-ui, sans-serif;
  background: #0e1116; color: #e6e6e6;
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: #8a939f; font-size: 12px; }
.error { color: #ff6b6b; font-size: 12px; min-height: 16px; }

.center-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { font-size: 18px; color: #00ff88; }

.card {
  background: #161b22; border: 1px solid #232a33;
  border-radius: 10px; padding: 14px;
}

header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 18px;
}
h1 { font-size: 16px; color: #00ff88; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip {
  font-size: 11px; padding: 3px 10px; border-radius: 12px;
  background: #1c222b; border: 1px solid #2d3540; color: #b8c0cc;
}
.chip b { color: #00ff88; }
button.chip { cursor: pointer; font-family: inherit; }
button.chip:hover { background: #242c37; }

button {
  padding: 8px 14px; border: 1px solid #2d3540; border-radius: 7px;
  background: #1c222b; color: #e6e6e6; cursor: pointer; font-size: 13px;
  min-height: 40px;
}
button:hover { background: #242c37; }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: #00ff88; border-color: #00ff88; color: #04140c; font-weight: 600; }
button.primary:hover { background: #00e07a; }
button.ghost { background: transparent; }

input, select {
  padding: 8px 10px; border: 1px solid #2d3540; border-radius: 7px;
  background: #1c222b; color: #e6e6e6; font-size: 13px;
}
input[type="text"], input[type="password"] { flex: 1; min-width: 160px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 0 18px 10px; }
.filters-body { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1; }
.f-toggle { display: none; }
.chk { display: flex; gap: 5px; align-items: center; font-size: 12px; color: #b8c0cc; white-space: nowrap; }
.chk input { accent-color: #00ff88; width: 16px; height: 16px; }

body { -webkit-tap-highlight-color: transparent; }
button, .tag, .flag-star, .row-pick { touch-action: manipulation; }

#app section.card { margin: 0 18px 12px; }
.chain-card h3 { font-size: 11px; color: #8a939f; text-transform: uppercase; margin-bottom: 10px; letter-spacing: 0.04em; }

/* ── Chain distribution bar ─────────────────────────────────────────── */
.cb-row { display: flex; align-items: center; gap: 10px; padding: 3px 0; cursor: pointer; }
.cb-row:hover .cb-label { color: #00ff88; }
.cb-label { width: 78px; font-size: 12px; color: #b8c0cc; text-align: right; }
.cb-track { flex: 1; display: flex; height: 14px; background: #12171e; border-radius: 4px; overflow: hidden; }
.cb-seg { height: 100%; }
.cb-gold { background: #ffc83d; }
.cb-silver { background: #c0c8d4; }
.cb-bronze { background: #d49161; }
.cb-none { background: #2d3540; }
.cb-val { width: 56px; font-size: 12px; color: #8a939f; font-variant-numeric: tabular-nums; }

/* ── Tag bar + tags ─────────────────────────────────────────────────── */
.tag-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 0 18px 10px; }
.tag-bar:empty { display: none; }
.tag {
  display: inline-block; font-size: 10px; padding: 2px 7px; border-radius: 9px;
  background: #1c222b; border: 1px solid #2d3540; color: #8a939f; cursor: pointer;
  white-space: nowrap; line-height: 1.6; margin: 2px 4px 2px 0;
}
.tag:hover { border-color: #00ff88; color: #00ff88; }
.tag b { color: #8a939f; font-weight: 500; }
.tag-filter.on, .tag.active { background: #00ff8822; border-color: #00ff88; color: #00ff88; }
.tag-filter.on b { color: #00ff88; }
.tag-more { cursor: pointer; }
.tag-src { cursor: default; background: #1a2430; }
.tag-src:hover { border-color: #2d3540; color: #8a939f; }

/* ── Selection bar ──────────────────────────────────────────────────── */
.sel-bar {
  display: flex; gap: 10px; align-items: center; margin: 0 18px 10px;
  padding: 8px 12px; background: #161b22; border: 1px solid #00ff8844; border-radius: 8px;
}
.banner { margin: 0 18px 10px; padding: 8px 12px; border-radius: 8px; font-size: 12px; }
.banner.error { background: #ff6b6b1a; border: 1px solid #ff6b6b55; color: #ff9b9b; }

/* ── Deep-dive (analisa API) ────────────────────────────────────────── */
.dd-panel h3 { font-size: 11px; color: #8a939f; text-transform: uppercase; margin-bottom: 8px; letter-spacing: 0.04em; }
.dd-verdict { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.dd-score { font-size: 13px; padding: 2px 10px; }
.dd-verdict-txt { font-size: 12px; font-weight: 600; }
.dd-summary { margin: 4px 0 8px; font-size: 12px; }
.dd-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.dd-metrics .d-stat { font-size: 11px; }
.dd-reasons { margin-top: 8px; font-size: 12px; }
.dd-reasons ul { margin: 4px 0 0 16px; }
.dd-reasons li { color: #b8c0cc; }
.dd-caution { color: #ffca47; }
#d-dd-refresh { margin-top: 10px; font-size: 12px; }

/* Sembunyikan seluruh fitur deep-dive bila URL service belum diset */
body.dd-off .dd-only,
body.dd-off #d-dd { display: none !important; }

/* ── Groups ─────────────────────────────────────────────────────────── */
.groups h3 { font-size: 11px; color: #8a939f; text-transform: uppercase; margin-bottom: 10px; letter-spacing: 0.04em; }
.grp-tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.grp-tools select { max-width: 260px; }
.grp-status { display: block; margin-bottom: 8px; min-height: 15px; }
.grp-status.error { color: #ff6b6b; }
.grp-list { display: flex; flex-direction: column; gap: 6px; }
.grp-list:empty { display: none; }
.grp {
  display: flex; align-items: center; gap: 8px;
  background: #12171e; border: 1px solid #232a33; border-radius: 8px; padding: 6px 8px;
}
.grp-emoji { font-size: 15px; width: 22px; text-align: center; }
.grp-name { font-size: 13px; color: #e6e6e6; flex: 1; min-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grp-n {
  font-size: 11px; color: #04140c; background: #00ff88; border-radius: 10px;
  padding: 1px 8px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.grp button { padding: 5px 9px; font-size: 12px; min-height: 0; }
button.danger { color: #ff6b6b; }
button.danger:hover { background: #ff6b6b1a; }

/* ── Table ──────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; text-align: left; font-size: 13px; border-bottom: 1px solid #1d232c; }
thead th {
  color: #8a939f; font-weight: 500; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; position: sticky; top: 0; background: #161b22; z-index: 2;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: #e6e6e6; }
th.sorted { color: #00ff88; }
.sort-ind { font-size: 9px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:nth-child(even) { background: #12171e40; }
tbody tr:hover { background: #1c222b; }
tbody tr.sel { background: #00ff8814; }
tr.tier-gold { background: #ffc83d0d; }
tr.tier-gold:hover { background: #ffc83d1a; }
.c-box { width: 30px; }
.c-tags { max-width: 220px; }
.c-note { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-pick { accent-color: #00ff88; cursor: pointer; }

.w-addr { font-family: ui-monospace, monospace; font-size: 12px; color: #00ff88; }
.tier { padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.tier-gold { background: #ffc83d22; color: #ffc83d; }
.tier-silver { background: #c0c8d422; color: #c0c8d4; }
.tier-bronze { background: #d4916122; color: #d49161; }
.tier-manual { background: #00ff8822; color: #00ff88; }
.w-pos { color: #00ff88; } .w-neg { color: #ff6b6b; }

.tbl-loading, .tbl-empty { padding: 28px; text-align: center; color: #8a939f; font-size: 13px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 10px; }

/* Tabel butuh ≈1051px. Di bawah itu jangan pernah buat halaman ikut menggulir
   horizontal — gulir hanya di dalam pembungkus tabel. */
#tbl-wrap { overflow-x: auto; }
@media (min-width: 901px) { #tbl { min-width: 900px; } }
/* Layar menengah (tablet landscape / laptop kecil): sembunyikan kolom yang
   paling tidak penting (source & note) supaya tabel tetap muat. */
@media (min-width: 901px) and (max-width: 1120px) {
  #tbl th.c-src, #tbl td.c-src,
  #tbl th.c-note, #tbl td.c-note { display: none; }
}

/* ── Detail drawer ──────────────────────────────────────────────────── */
.detail {
  position: fixed; inset: 0; z-index: 50;
  background: #0e1116f2; overflow-y: auto; padding: 18px;
}
.detail-inner { max-width: 1180px; margin: 0 auto; }
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.detail-head h2 { font-family: ui-monospace, monospace; font-size: 14px; color: #00ff88; word-break: break-all; }
.detail-nav { display: flex; gap: 6px; }
.meta-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.detail-grid .card:last-child { grid-column: 1 / -1; }
.detail-grid h3 { font-size: 12px; color: #8a939f; text-transform: uppercase; margin-bottom: 8px; }
.d-stat { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid #1d232c; font-size: 12px; }
.d-stat:last-child { border-bottom: none; }
.tok { color: #00ff88; text-decoration: none; }
.tok:hover { text-decoration: underline; }

.trend { font-size: 11px; padding: 2px 8px; border-radius: 9px; }
.trend-naik { background: #00ff8822; color: #00ff88; }
.trend-turun { background: #ff6b6b22; color: #ff6b6b; }
.trend-stagnan { background: #2d354033; color: #8a939f; }

/* portfolio share bar in holdings */
.hbar { display: inline-block; width: 46px; height: 6px; background: #12171e; border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: 5px; }
.hbar > span { display: block; height: 100%; background: #00ff88; }

/* Flag editor */
.flag-star { text-align: center; cursor: pointer; font-size: 15px; }
.flag-star:hover { transform: scale(1.2); }
#d-note {
  width: 100%; margin: 8px 0; padding: 8px 10px; resize: vertical;
  border: 1px solid #2d3540; border-radius: 7px;
  background: #1c222b; color: #e6e6e6; font: 13px/1.5 system-ui, sans-serif;
}
.note-foot { display: flex; gap: 10px; align-items: center; }
.note-foot #d-note-save { margin-right: 0; }
#d-note-count { margin-left: auto; font-variant-numeric: tabular-nums; }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .cb-label { width: 60px; }
}

/* ══════════════════════════════════════════════════════════════════════
   MOBILE — tabel 11 kolom diubah jadi kartu (satu DOM, murni CSS grid)
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  header { padding: 10px 12px; gap: 8px; }
  h1 { font-size: 15px; }
  .chip { font-size: 10px; padding: 3px 8px; }
  #app section.card, .filters, .tag-bar, .sel-bar, .banner { margin-left: 10px; margin-right: 10px; }
  .card { padding: 11px; }

  /* Panel filter dilipat */
  .f-toggle { display: inline-flex; width: 100%; justify-content: center; min-height: 42px; }
  .filters-body { display: none; margin-top: 10px; width: 100%; }
  .filters-body.open { display: flex; flex-direction: column; align-items: stretch; }
  .filters-body.open > * { width: 100%; max-width: none; }
  .filters-body.open > .chk { width: auto; padding: 4px 0; }

  /* Tombol & target sentuh */
  button { min-height: 42px; padding: 8px 12px; }
  input, select { min-height: 42px; }
  .tag { padding: 5px 9px; font-size: 11px; }
  .row-pick { width: 20px; height: 20px; }
  /* Tag di tabel hanya label (klik baris = buka detail) → tidak perlu target besar.
     Yang interaktif: bar filter + modal detail. */
  #tag-filter .tag, #d-tags .tag {
    min-height: 40px; display: inline-flex; align-items: center; padding: 6px 11px; font-size: 11px;
  }

  /* Bar filter tag → scroll horizontal */
  .tag-bar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .tag-bar::-webkit-scrollbar { display: none; }
  .tag-bar .tag { flex: 0 0 auto; }

  /* Bar chain */
  .cb-label { width: 58px; font-size: 11px; }
  .cb-val { width: 44px; font-size: 11px; }

  /* ── Tabel utama → kartu ─────────────────────────────────────────── */
  #tbl, #tbl tbody, #tbl tr, #tbl td { display: block; width: 100%; }
  #tbl thead { display: none; }        /* urutan lewat #f-sort + #f-order */

  #tbl tbody tr {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas:
      "box  addr  addr star"
      "ch   src   src  src"
      "tags tags  tags tags"
      "p7   p30   wr   score"
      "note note  note note";
    gap: 2px 8px;
    align-items: center;
    background: #161b22;
    border: 1px solid #232a33;
    border-radius: 10px;
    padding: 10px 11px;
    margin-bottom: 8px;
  }
  #tbl tbody tr:nth-child(even) { background: #161b22; }
  #tbl tbody tr:hover { background: #1c222b; }
  #tbl tbody tr.sel { border-color: #00ff88; background: #00ff8814; }
  #tbl tr.tier-gold { background: #ffc83d0d; border-color: #ffc83d33; }

  #tbl td { border-bottom: none; padding: 0; font-size: 13px; }
  /* caption kecil di atas tiap nilai */
  #tbl td::before {
    content: attr(data-label);
    display: block; font-size: 9px; text-transform: uppercase;
    letter-spacing: 0.05em; color: #6b7480; margin-bottom: 1px;
  }
  #tbl td.c-box::before,
  #tbl td.w-addr::before,
  #tbl td.c-tags::before,
  #tbl td.flag-star::before { display: none; }
  #tbl td.c-note:empty { display: none; }

  .c-box   { grid-area: box; }
  .w-addr  { grid-area: addr; font-size: 13px; }
  .c-chain { grid-area: ch; }
  .c-src   { grid-area: src; }
  /* chain & source: label sejajar, teks membungkus (jangan dipotong ellipsis) */
  #tbl td.c-chain, #tbl td.c-src { font-size: 12px; }
  #tbl td.c-chain::before, #tbl td.c-src::before { display: inline-block; margin: 0 6px 0 0; }
  #tbl td.c-src { word-break: break-word; }
  .c-tags  { grid-area: tags; max-width: none; }
  .c-pnl7  { grid-area: p7; }
  .c-pnl30 { grid-area: p30; }
  .c-wr    { grid-area: wr; }
  .c-score { grid-area: score; }
  .flag-star { grid-area: star; min-height: 42px; min-width: 42px;
               display: flex; align-items: center; justify-content: center; font-size: 19px; }
  .c-note  { grid-area: note; max-width: none; white-space: normal; }

  /* metrik: angka lebih kecil agar 4 kolom muat */
  #tbl td.c-pnl7, #tbl td.c-pnl30, #tbl td.c-wr, #tbl td.c-score { font-size: 12px; }
  #tbl td.c-score .tier { display: inline-block; }

  /* ── Tabel sekunder (holdings, compare) → kartu ─────────────────── */
  .rt thead { display: none; }
  .rt, .rt tbody, .rt tr, .rt td { display: block; width: 100%; }
  .rt tr {
    border: 1px solid #232a33; border-radius: 8px;
    padding: 8px 10px; margin-bottom: 8px; background: #12171e;
  }
  .rt td {
    display: flex; justify-content: space-between; gap: 12px;
    border-bottom: 1px solid #1d232c; padding: 4px 0; text-align: left; font-size: 12px;
  }
  .rt td:last-child { border-bottom: none; }
  .rt td::before {
    content: attr(data-label);
    color: #6b7480; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
    flex: 0 0 auto;
  }
  .rt td.num { text-align: right; font-variant-numeric: tabular-nums; }

  /* ── Pager & selection bar ──────────────────────────────────────── */
  .pager { justify-content: space-between; gap: 6px; }
  .pager button { flex: 1; }
  .sel-bar { position: sticky; top: 0; z-index: 6; flex-wrap: wrap; }
  .sel-bar button { flex: 1; }

  /* ── Grup ────────────────────────────────────────────────────────── */
  .grp-tools { flex-direction: column; align-items: stretch; }
  .grp-tools > * { width: 100%; max-width: none; }
  .grp-tools > .chk { padding: 4px 0; }
  .grp { flex-wrap: wrap; row-gap: 8px; }
  .grp-name { flex: 1 1 100%; white-space: normal; }
  .grp button { flex: 1; min-height: 42px; }

  /* ── Deep-dive ───────────────────────────────────────────────────── */
  .dd-metrics { grid-template-columns: 1fr; }
  .sel-bar .dd-only { flex: 1 1 100%; }

  /* ── Modal: full screen + aman untuk notch/home bar ─────────────── */
  .detail { padding: 10px; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .detail-inner { max-width: 100%; }
  .detail-head h2 { font-size: 12px; }
  .detail-nav button { min-width: 44px; padding: 8px 10px; }
  #d-chart, #cmp-chart { max-height: 220px; }
  .meta-row { gap: 6px; }
  .hbar { width: 40px; }
}

@media (max-width: 480px) {
  #tbl tbody tr {
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas:
      "box  addr  addr star"
      "ch   src   src  src"
      "tags tags  tags tags"
      "p7   p30   p30  p30"
      "wr   score score score"
      "note note  note note";
  }
  #tbl td.c-pnl7, #tbl td.c-pnl30, #tbl td.c-wr, #tbl td.c-score { font-size: 11px; }
  .cb-label { width: 48px; }
}
