:root {
  --bg: #0f1012; --panel: #17181c; --panel2: #1e2026; --line: #2a2d35;
  --text: #e8eaed; --muted: #9aa0ab; --primary: #E50914; --gold: #f5b301;
  --green: #2ecc71; --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 14px; }
a { color: inherit; text-decoration: none; }
svg { display: block; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 250px; background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; font-weight: 800; font-size: 18px; }
.brand .name { color: #fff; } .brand .name b { color: var(--primary); }
.nav-sec { margin-top: 14px; }
.nav-sec h4 { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; margin: 0 8px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--muted); }
.nav-item:hover { background: var(--panel2); color: var(--text); }
.nav-item.active { background: rgba(229,9,20,.12); color: #fff; }
.nav-item.active svg { color: var(--primary); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 17px; margin: 0; }
.who { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.pill { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 12px; }
.content { padding: 24px; max-width: 1100px; }

/* Cards / grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 28px; font-weight: 800; }
.stat .l { color: var(--muted); display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.stat .l svg { color: var(--primary); }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 20px; }
.panel h2 { margin: 0 0 4px; font-size: 15px; }
.panel .desc { color: var(--muted); margin: 0 0 14px; font-size: 13px; }
.section-title { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.section-title svg { color: var(--primary); }

/* Forms */
label { display: block; color: var(--muted); font-size: 12px; margin: 12px 0 5px; }
input, select, textarea { width: 100%; background: var(--panel2); border: 1px solid var(--line);
  color: var(--text); border-radius: 9px; padding: 10px 12px; font-size: 14px; font-family: inherit; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 160px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.check input { width: auto; }
.btn { display: inline-flex; align-items: center; gap: 8px; background: var(--primary); color: #fff;
  border: none; border-radius: 9px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; margin-top: 16px; }
.btn.ghost { background: var(--panel2); border: 1px solid var(--line); }
.btn.sm { padding: 6px 10px; font-size: 12px; margin: 0; }
.btn.danger { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.danger:hover { color: var(--primary); border-color: var(--primary); }

/* Table */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
td.actions { text-align: right; white-space: nowrap; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.tag.on { background: rgba(46,204,113,.15); color: var(--green); }
.tag.off { background: rgba(154,160,171,.15); color: var(--muted); }
.tag.gold { background: rgba(245,179,1,.15); color: var(--gold); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.empty { color: var(--muted); padding: 22px; text-align: center; }
.note { background: rgba(245,179,1,.08); border: 1px solid rgba(245,179,1,.25); color: #f0d68a;
  border-radius: 9px; padding: 12px 14px; font-size: 13px; margin-bottom: 16px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 30px; }
.login .brand { justify-content: center; }
.err { background: rgba(229,9,20,.12); border: 1px solid rgba(229,9,20,.35); color: #ff8a94;
  border-radius: 9px; padding: 10px 12px; font-size: 13px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 12px; text-align: center; margin-top: 16px; line-height: 1.6; }

/* Language switcher */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.lang-switcher { display: flex; gap: 6px; }
.lang-btn { display: inline-flex; align-items: center; justify-content: center; padding: 4px;
  border-radius: 7px; background: var(--panel2);
  border: 1px solid var(--line); transition: all .15s; opacity: .55; }
.lang-btn:hover { opacity: 1; }
.lang-btn.active { border-color: var(--primary); opacity: 1; box-shadow: 0 0 0 1px var(--primary); }
.lang-btn .flag { width: 26px; height: 18px; display: block; border-radius: 3px; }

/* Bulk select + delete */
.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: rgba(229,9,20,.08); border: 1px solid rgba(229,9,20,.3);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.bulk-bar .sel-count { color: var(--muted); font-size: 13px; flex: 1; min-width: 120px; }
input[type="checkbox"].row-check { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.hamburger { display: none; background: var(--panel2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; width: 40px; height: 40px; align-items: center; justify-content: center; cursor: pointer; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; }

/* Chart */
.chart { margin-top: 6px; position: relative; }
.chart-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.chart-tab { background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: 6px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s ease, color .15s ease; }
.chart-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chart-svg { width: 100%; height: auto; display: block; touch-action: none; }
.chart .axis { fill: var(--muted); font-size: 9px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; pointer-events: none; }
.chart-marker { stroke: var(--panel); stroke-width: 2; pointer-events: none; }

/* Legend (klik untuk toggle siri) */
.chart-legend { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.chart-leg-item { display: inline-flex; align-items: center; gap: 7px; background: none; border: 0;
  color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer; padding: 4px 6px; }
.chart-leg-dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.chart-leg-item.off { opacity: .4; }
.chart-leg-item.off .chart-leg-name { text-decoration: line-through; }

/* Tooltip overlay (ikut kursor) */
.chart-tip { position: absolute; z-index: 6; pointer-events: none; min-width: 130px;
  background: rgba(20,22,27,.96); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
  transition: opacity .12s ease; }
.chart-tip .tip-title { color: var(--muted); font-size: 11px; margin-bottom: 6px; font-weight: 700; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 7px; margin-top: 3px; }
.chart-tip .tip-dot { width: 9px; height: 9px; border-radius: 3px; }
.chart-tip .tip-name { color: var(--muted); }
.chart-tip .tip-val { margin-left: auto; color: #fff; font-weight: 700; }

/* ---- Editor Drama & Cast (master–detail) ---- */
.content:has(#dramaForm) { max-width: 1400px; }
.ed-grid { display: grid; grid-template-columns: 1fr 1.1fr 0.9fr; gap: 16px; align-items: start; }
.ed-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ed-col .panel { margin-bottom: 0; }
.ed-col h3 { font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.chip b { cursor: pointer; color: var(--muted); font-weight: 400; }
.chip b:hover { color: var(--primary); }
.ep-item { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; margin-bottom: 7px; cursor: pointer; }
.ep-item.active { border-color: var(--primary); background: rgba(229,9,20,.10); }
.ep-item .ep-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ep-item .ep-main small { color: var(--muted); font-size: 11px; }
table.mini th, table.mini td { padding: 6px 6px; font-size: 12px; }
table.mini input, table.mini select { padding: 6px 8px; font-size: 12px; }
.cast-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 10px; }
.cast-card label { margin: 8px 0 4px; }
.cast-card-head { display: flex; align-items: center; gap: 9px; }
.cast-card-head b { font-size: 13px; }
.cast-av { width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  background: var(--panel); display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.cast-av img { width: 100%; height: 100%; object-fit: cover; }
.sum-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sum-row { background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 10px;
  display: flex; flex-direction: column; }
.sum-row span { color: var(--muted); font-size: 11px; }
.sum-row b { font-size: 20px; margin-top: 2px; }
.res-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.res-badge { background: var(--panel2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; font-size: 12px; }
.res-badge b { color: var(--primary); }
@media (max-width: 1100px) { .ed-grid { grid-template-columns: 1fr; } }

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .25s ease; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .overlay { display: block; }
  .hamburger { display: inline-flex; }
  .content { padding: 16px; overflow-x: hidden; }
  .topbar { padding: 12px 16px; }
  .who .pill { display: none; }

  /* Cegah bocor margin kanan di HP */
  .main { min-width: 0; max-width: 100%; }
  .panel { overflow: hidden; }               /* tahan kandungan dalam kad */
  .row { flex-direction: column; gap: 12px; }
  .row > div { min-width: 0; width: 100%; }

  /* Jadual boleh skrol mendatar sendiri (tidak potong halaman) */
  .panel > table,
  .panel > form + table,
  #listPanel > table { display: block; width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch; white-space: nowrap; }
  th, td { padding: 9px 10px; }
  .content, .panel, img, textarea, input, select { max-width: 100%; }
}
