/* NUKI TV - dashboard kontrol (prototipe). Mobile-first, tema gelap, aksen oranye. */

:root {
    --bg: #0b0f14;
    --surface: #121821;
    --surface-2: #19212c;
    --surface-3: #212b38;
    --line: #243042;
    --text: #e8edf3;
    --muted: #8d99a8;
    --accent: #ff8a3d;
    --accent-ink: #1b1206;
    --accent-soft: rgba(255, 138, 61, .14);
    --danger: #ff6b5b;
    --s-p1: #3ecf8e;
    --s-p2: #5aa9ff;
    --s-siap: #f0b429;
    --s-uji: #b48cff;
    --s-na: #6b7685;
    --r-lg: 20px;
    --r-md: 14px;
    --tap: 48px;
    color-scheme: dark;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.ic {
    width: 20px; height: 20px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.9;
    stroke-linecap: round; stroke-linejoin: round;
}

.app {
    max-width: 1180px;
    margin: 0 auto;
    padding: 12px 16px 40px;
    padding-top: max(12px, env(safe-area-inset-top));
}

/* ---------- Header ---------- */
.hdr { display: grid; gap: 8px; margin-bottom: 12px; }
.hdr-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hdr-row:first-child { justify-content: space-between; }

.title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }

.badge {
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(255, 138, 61, .45);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
}

.switch {
    display: inline-flex;
    padding: 3px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    flex: none;
}

.switch a {
    display: inline-flex; align-items: center;
    min-height: 36px; padding: 0 14px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 14px; font-weight: 600;
    text-decoration: none;
}

.switch a[aria-current="page"] { background: var(--surface-3); color: var(--text); }

.device { flex-wrap: wrap; font-size: 13px; color: var(--muted); row-gap: 4px; }
.device-name { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 600; }
.device-name .ic { width: 16px; height: 16px; }

.conn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    font-size: 12px; font-weight: 600;
}

.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--s-na); }
.conn[data-state="sim"]::before { background: var(--s-uji); }
.conn[data-state="user"]::before { background: var(--s-p1); }
.conn[data-state="anon"]::before { background: var(--danger); }
.conn[data-state="tv-on"]::before { background: var(--s-p1); }
.conn[data-state="tv-off"]::before { background: var(--s-siap); }
.conn[data-state="tv-err"]::before { background: var(--danger); }

a.link-btn { display: inline-flex; align-items: center; text-decoration: none; }
a.link-btn[hidden] { display: none; }

.link-btn {
    min-height: 44px; padding: 0 6px;
    border: 0; background: none;
    color: var(--accent); font-size: 13px; font-weight: 600;
    cursor: pointer;
}

/* ---------- Kartu ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 14px;
    min-width: 0;
}

.card h2 {
    margin: 0 0 12px;
    font-size: 12px; font-weight: 700;
    color: var(--muted);
    letter-spacing: .09em;
    text-transform: uppercase;
}

/* ---------- Pencarian ---------- */
.search { margin-bottom: 12px; }

.search-row {
    position: relative;
    display: flex; gap: 8px;
}

.search-ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }

#cmd {
    flex: 1; min-width: 0;
    min-height: 54px;
    padding: 0 12px 0 44px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    background: var(--surface-2);
    font-size: 16px;
    outline: none;
}

#cmd::placeholder { color: #6f7b8b; }
#cmd:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-accent, .btn-ghost {
    min-height: 54px; padding: 0 20px;
    border-radius: var(--r-md);
    font-weight: 700; cursor: pointer;
    touch-action: manipulation;
}

.btn-accent { border: 0; background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { filter: brightness(1.06); }
.btn-ghost { border: 1px solid var(--line); background: var(--surface-2); }
.btn-ghost:hover { background: var(--surface-3); }

.chips {
    display: flex; gap: 8px;
    margin: 10px -14px 0;
    padding: 2px 14px 4px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
    flex: none;
    min-height: 44px; padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--surface-2);
    font-size: 14px; font-weight: 600;
    white-space: nowrap;
    scroll-snap-align: start;
    cursor: pointer;
    touch-action: manipulation;
}

.chip:hover { border-color: rgba(255, 138, 61, .5); }
.chip.danger { color: var(--danger); }

.result {
    margin: 10px 0 0;
    min-height: 20px;
    font-size: 14px; line-height: 1.45;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.result[data-tone="ok"] { color: var(--text); }
.result[data-tone="warn"] { color: #f5c76b; }
.result[data-tone="error"] { color: var(--danger); }

/* Indikator antrean kirim (tombol navigasi beruntun) */
.queue {
    display: inline-block;
    margin: 6px 0 0;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px; line-height: 1.5;
    color: var(--text);
    background: color-mix(in srgb, var(--text) 10%, transparent);
}
.queue[hidden] { display: none; }

/* ---------- Panel ---------- */
.panels {
    display: grid; gap: 12px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "nav" "vol" "apps" "basic" "media" "extra" "log";
}

.p-nav { grid-area: nav; }
.p-vol { grid-area: vol; }
.p-media { grid-area: media; }
.p-apps { grid-area: apps; }
.p-basic { grid-area: basic; }
.p-extra { grid-area: extra; }
.p-log { grid-area: log; }

@media (min-width: 768px) {
    .app { padding: 20px 24px 48px; }
    .title h1 { font-size: 26px; }
    .panels {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas: "nav vol" "nav media" "apps basic" "extra log";
    }
}

@media (min-width: 1100px) {
    .panels {
        grid-template-columns: 1.05fr 1fr 1fr;
        grid-template-areas: "nav vol apps" "nav media basic" "extra log log";
    }
}

.grid { display: grid; gap: 8px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------- Tombol kontrol ---------- */
.ctl {
    position: relative;
    display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    min-height: 60px; min-width: 0;
    padding: 8px 4px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
    font-size: 13px; font-weight: 600;
    line-height: 1.15; text-align: center;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    transition: background-color .12s ease, transform .08s ease, opacity .12s ease;
}

/* Boleh pindah baris di spasi, tapi kata tidak dipotong; kata yang kepanjangan
   akan meluap (dan terdeteksi oleh tes "Label tidak terpotong"). */
.ctl span { max-width: 100%; overflow: hidden; overflow-wrap: normal; word-break: normal; }
.ctl:hover { background: var(--surface-3); }
.ctl:active { transform: scale(.97); }
.ctl.is-busy { opacity: .55; }

.ctl:focus-visible, .chip:focus-visible, .btn-accent:focus-visible, .btn-ghost:focus-visible,
.switch a:focus-visible, .link-btn:focus-visible, summary:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Titik status di sudut tombol */
.ctl[data-s]::after {
    content: "";
    position: absolute; top: 7px; right: 7px;
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--s-na);
}
.ctl[data-s="p1"]::after { background: var(--s-p1); }
.ctl[data-s="p2"]::after { background: var(--s-p2); }
.ctl[data-s="siap"]::after { background: var(--s-siap); }
.ctl[data-s="uji"]::after { background: var(--s-uji); }

.ctl[data-s="na"] { color: var(--muted); border-style: dashed; background: transparent; }
.ctl[data-s="na"] > span:last-child::after { content: " · belum ada"; font-weight: 500; }

.ctl[data-live="off"] { opacity: .5; border-style: dashed; }
.ctl[data-live="off"] > span:last-child::after { content: " · belum aktif"; font-weight: 500; }

.ctl.power { color: var(--danger); }

/* D-pad */
.dpad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas: ". up ." "left ok right" ". down .";
    gap: 8px;
    width: 100%;
    max-width: 300px;
    margin: 0 auto 12px;
    aspect-ratio: 1;
}

.dpad .ctl { min-height: 64px; border-radius: 18px; }
.dpad .ctl .ic { width: 26px; height: 26px; }
.d-up { grid-area: up; }
.d-down { grid-area: down; }
.d-left { grid-area: left; }
.d-right { grid-area: right; }

.d-ok {
    grid-area: ok;
    border-radius: 50% !important;
    background: var(--accent) !important;
    color: var(--accent-ink);
    border-color: transparent !important;
    font-size: 18px; font-weight: 800;
}

.d-ok:hover { filter: brightness(1.06); }
.d-ok[data-s]::after { top: 10%; right: 10%; box-shadow: 0 0 0 2px var(--accent); }

/* Volume & channel */
.rockers {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: stretch;
}

.rocker {
    display: grid;
    grid-template-rows: 1fr auto 1fr;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface-2);
}

.rocker .ctl { min-height: 56px; border: 0; background: transparent; }
.rocker .ctl:hover { background: var(--surface-3); }
.rocker .cap { text-align: center; font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--muted); }
.mute { min-width: 76px; padding: 8px 10px; }

/* Aplikasi */
.tile .logo {
    display: inline-grid; place-items: center;
    width: 26px; height: 26px; border-radius: 8px;
    font-weight: 800; font-size: 15px;
}

.logo.nf { color: #e50914; background: rgba(229, 9, 20, .12); }
.logo.yt { color: #fff; background: #ff0033; }
.logo.yt .ic { width: 14px; height: 14px; fill: currentColor; stroke: none; }
.logo.pv { color: #36b2ff; background: rgba(54, 178, 255, .12); }

.kb { display: grid; gap: 10px; margin-top: 12px; }
.kb[hidden] { display: none; }
.kb input {
    width: 100%; min-width: 0; min-height: 60px; padding: 0 16px;
    border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2);
    font-size: 20px; letter-spacing: .02em; outline: none;
}
.kb input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.kb input[aria-invalid="true"] { border-color: var(--danger); }
.kb .btn-ghost, .kb .btn-accent { min-height: 48px; padding: 0 12px; }
.kb .btn-ghost:disabled { opacity: .5; cursor: not-allowed; }

.kb-status { margin: 0; min-height: 20px; font-size: 13px; color: var(--muted); }
.kb-status[data-state="sending"] { color: var(--text); }
.kb-status[data-state="ok"] { color: var(--s-p1); }
.kb-status[data-state="error"] { color: var(--danger); }

/* Tombol edit keyboard (ketikan dari keyboard fisik PC; tidak ada tombol huruf/angka/simbol layar) */
.kbk {
    min-width: 44px; min-height: 48px; padding: 0 12px;
    border-radius: var(--r-md); border: 1px solid var(--line); background: var(--surface-2);
    font-size: 15px; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.kbk:hover { background: var(--surface-3); }
.kbk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kb-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kb-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kb-actions .btn-accent, .kb-actions #kb-cancel { grid-column: 1 / -1; }
.kb-hint { margin: 0; font-size: 12px; line-height: 1.45; }

/* Tambahan (buka-tutup) */
.p-extra summary {
    list-style: none;
    display: flex; align-items: center; justify-content: space-between;
    min-height: 32px;
    cursor: pointer;
}

.p-extra summary::-webkit-details-marker { display: none; }
.p-extra summary h2 { margin: 0; }
.p-extra summary::after { content: "+"; color: var(--muted); font-size: 20px; }
.p-extra[open] summary::after { content: "−"; }
.p-extra[open] summary { margin-bottom: 12px; }
.p-extra .grid + .grid { margin-top: 8px; }

.color { min-height: 48px; }
.color i { display: block; width: 60%; height: 8px; border-radius: 4px; }
.c-red i { background: #ff453a; }
.c-green i { background: #30d158; }
.c-yellow i { background: #ffd60a; }
.c-blue i { background: #0a84ff; }

/* Aktivitas */
.log {
    list-style: none; margin: 0; padding: 0;
    display: grid; gap: 6px;
    max-height: 220px; overflow: auto;
    font-size: 13px;
}

.log li {
    display: flex; gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--surface-2);
    overflow-wrap: anywhere;
}

.log:empty::before { content: "Belum ada aktivitas."; color: var(--muted); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.log [data-tone="warn"] { color: #f5c76b; }
.log [data-tone="error"] { color: var(--danger); }

.legend-wrap { margin-top: 10px; font-size: 13px; }
.legend-wrap summary { cursor: pointer; color: var(--muted); min-height: 32px; display: flex; align-items: center; }
.legend { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.legend li { display: flex; gap: 10px; line-height: 1.4; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 5px; background: var(--s-na); }
.dot[data-s="p1"] { background: var(--s-p1); }
.dot[data-s="p2"] { background: var(--s-p2); }
.dot[data-s="siap"] { background: var(--s-siap); }
.dot[data-s="uji"] { background: var(--s-uji); }
.hint { margin: 10px 0 0; color: var(--muted); }

/* Dialog */
.overlay {
    position: fixed; inset: 0; z-index: 10;
    display: grid; place-items: end center;
    padding: 16px;
    background: rgba(0, 0, 0, .6);
}

.overlay[hidden] { display: none; }

.sheet {
    width: 100%; max-width: 400px;
    padding: 20px;
    border-radius: 22px;
    border: 1px solid var(--line);
    background: var(--surface);
}

.sheet h3 { margin: 0 0 6px; font-size: 18px; }
.sheet p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }

@media (min-width: 600px) { .overlay { place-items: center; } }

@media (max-width: 380px) {
    .app { padding-left: 12px; padding-right: 12px; }
    .card { padding: 12px; }
    .chips { margin-left: -12px; margin-right: -12px; padding-left: 12px; padding-right: 12px; }
    .btn-accent { padding: 0 14px; }
    .ctl { font-size: 12px; }
    .mute { min-width: 64px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
