:root { color-scheme: dark; --bg: #0b0b0c; --panel: #17171a; --raise: #202024; --line: #2c2c31; --text: #f2f2f4; --muted: #9a9aa3;
        --accent: #2d6cdf; --ok: #3ccf6e; --warn: #f2b84b; --err: #ff6b6b; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }

button, input { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
input { font-size: 16px; padding: 12px 14px; } /* 16px: Safari iOS không tự phóng to khi chạm */
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { cursor: pointer; padding: 10px 14px; font-size: 15px; touch-action: manipulation; }
button:active { background: #2a2a30; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }

/* ---------- Đăng nhập ---------- */
body.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
        background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.card button { background: var(--accent); border-color: var(--accent); font-weight: 600; padding: 13px; font-size: 16px; }
.error { margin: 0; padding: 10px 12px; border-radius: 10px; background: #4a1e1e; color: #ffb4b4; font-size: 14px; }

/* ---------- Điều khiển: điện thoại dọc (mặc định) ---------- */
body.app { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; overscroll-behavior: none;
           padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
           user-select: none; -webkit-user-select: none; }
.desk { display: none !important; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.top { display: flex; justify-content: center; padding: 6px 10px 2px; }
.pill { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 6px 12px; border-radius: 999px;
        font-size: 13px; color: var(--muted); }
.pill #status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); }
.warn { margin: 4px 10px; padding: 8px 12px; border-radius: 10px; background: #4a3a10; color: #ffd98a; font-size: 13px; text-align: center; }

#stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 8px; }
#wrap { position: relative; display: flex; max-width: 100%; max-height: 100%; }
#screen, #vscreen { display: block; max-width: 100%; max-height: calc(100dvh - 150px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
          width: auto; height: auto; border-radius: 18px; background: #000; color: transparent; /* ẩn chữ thay thế khi chưa có hình */
          min-height: min(60dvh, 560px); min-width: calc(min(60dvh, 560px) * 0.5622);
          touch-action: none; -webkit-touch-callout: none; outline: none; }
#screen:focus-visible, #vscreen:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
#wrap.blank { background: #000; border-radius: 18px; }
#wrap.blank #screen { opacity: 0; } /* chưa có hình: ẩn icon ảnh hỏng, giữ khung đen */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center; border-radius: 18px;
           background: rgba(0,0,0,.6); color: var(--muted); font-size: 14px; pointer-events: none; }
.dot-touch { position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%;
             background: rgba(80,180,255,.45); pointer-events: none; animation: fade .4s forwards; }
@keyframes fade { to { opacity: 0; transform: scale(1.8); } }

.dock { display: flex; justify-content: space-around; align-items: flex-end; gap: 4px; padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
        background: var(--panel); border-top: 1px solid var(--line); }
.dock button, .grid button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
        background: transparent; border: 0; padding: 6px 2px; font-size: 11px; color: var(--muted); min-height: 52px; }
.dock button:active, .grid button:active { color: var(--text); background: #2a2a30; }
svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dock .home { color: var(--text); }
.dock .home svg { width: 30px; height: 30px; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--panel); border-top: 1px solid var(--line);
         border-radius: 18px 18px 0 0; padding: 8px 14px calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px;
         max-width: 560px; margin: 0 auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(100%); } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 4px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.keys button { flex: 1; padding: 10px 6px; }
.grid { display: flex; gap: 6px; }
.grid button { background: var(--raise); border-radius: 12px; font-size: 12px; color: var(--text); padding: 10px 4px; }
.grid button[aria-pressed="true"] { background: #1f5130; }
.vol { align-items: center; margin-top: 8px; }
.vol button { flex: none; width: 44px; height: 44px; padding: 0; font-size: 20px; background: var(--raise); }
.vol input { padding: 0; height: 44px; background: none; border: 0; accent-color: var(--accent); }
.vol output { flex: none; width: 46px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
h2 { margin: 6px 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.note, .help p { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.note { text-align: center; }
.logout { margin: 0; }
.wide { width: 100%; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
         max-width: 90vw; padding: 10px 14px; border-radius: 12px; background: #2a1d1d; color: #ffc4c4; font-size: 13px; }
.toast.info { background: #1b2a3d; color: #cfe3ff; }

/* Chuông thông báo cạnh viên trạng thái */
.top { gap: 8px; }
.bell { position: relative; padding: 6px 10px; color: var(--text); }
.bell svg { width: 18px; height: 18px; }
.bell .count { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
               background: var(--err); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }

/* Cửa sổ nổi: thông báo, cài đặt */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: 16px;
         padding-top: calc(16px + env(safe-area-inset-top)); background: rgba(0,0,0,.55); user-select: auto; -webkit-user-select: auto; }
.modal-card { width: 100%; max-width: 440px; max-height: calc(100dvh - 32px - env(safe-area-inset-top)); overflow-y: auto;
              display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 16px 18px;
              background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-head h2 { margin: 0; font-size: 17px; color: var(--text); text-transform: none; letter-spacing: 0; }
.modal h3 { margin: 8px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.modal label.switch { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--text); }
.modal label.switch.small { font-size: 13px; color: var(--muted); }
.modal input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.close { padding: 6px 10px; font-size: 16px; }
textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
           border-radius: 12px; padding: 12px 14px; resize: vertical; min-height: 96px; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
#sms-status.err { color: var(--err); }
#sms-status.ok { color: var(--ok); }
.note.left { text-align: left; margin: 0; }
#s-status.err, .note.err { color: var(--err); }
#s-status.ok { color: var(--ok); }
.notif-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.notif-list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-radius: 10px; background: var(--raise); }
.notif-list .app { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-list .time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.notif-list .dev { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.notif-list li.new { outline: 1px solid var(--accent); }

/* ---------- Điện thoại xoay ngang: thanh nút sang bên phải ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  body.app { flex-direction: row; padding-bottom: env(safe-area-inset-bottom); }
  .top { position: absolute; top: calc(4px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); z-index: 5; padding: 0; }
  .warn { display: none; }
  #screen, #vscreen { max-height: calc(100dvh - 16px - env(safe-area-inset-bottom)); }
  .side { display: flex; }
  .dock { flex-direction: column; justify-content: center; border-top: 0; border-left: 1px solid var(--line);
          padding: 6px calc(6px + env(safe-area-inset-right)) 6px 6px; }
  .dock button { flex: 0 0 auto; min-width: 64px; }
}

/* ---------- Máy tính: màn hình iPhone bên trái, bảng điều khiển luôn hiện bên phải ---------- */
@media (min-width: 900px) and (min-height: 600px) {
  body.app { flex-direction: row; padding: 0; user-select: auto; -webkit-user-select: auto; }
  .desk { display: revert !important; }
  .mob, .grip, .scrim { display: none !important; }
  .view { padding: 12px 0; }
  .top { padding: 0 0 6px; }
  #stage { padding: 0 24px; }
  #screen, #vscreen { max-height: calc(100dvh - 70px); border-radius: 26px; border: 1px solid var(--line); cursor: pointer; }
  #screen.dragging, #vscreen.dragging { cursor: grabbing; }
  .overlay { border-radius: 26px; }

  .side { width: 320px; flex: none; display: flex; flex-direction: column; gap: 18px; padding: 20px 18px;
          background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
  .side h1 { margin: 0; font-size: 18px; }
  .dock { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0; background: none; border: 0; }
  .dock button:not(.mob) { display: flex !important; flex-direction: column; min-height: 64px; border-radius: 12px;
                                    background: var(--raise); color: var(--text); font-size: 12px; }
  .dock button:hover, .grid button:hover, .keys button:hover { background: #2a2a30; }
  .dock .home svg { width: 26px; height: 26px; }

  /* Tấm trượt thành các khối cố định trong bảng bên */
  .sheet, .sheet[hidden] { display: flex !important; position: static; padding: 0; border: 0; border-radius: 0; background: none;
                           max-width: none; margin: 0; animation: none; gap: 10px; }
  .sheet .note { text-align: left; }
  .logout { margin-top: auto; }
  .toast { bottom: 24px; left: calc(50% - 160px); }
}
.devsel { font-family: inherit; font-size: 13px; color: var(--text); background: var(--panel); border: 1px solid var(--line); max-width: 46vw;
          text-overflow: ellipsis; cursor: pointer; }
