/* ============================================================
   Smart Home Dashboard — style.css
   Phase 7: Two-level navigation, mobile-first remote UI.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --border:    #334155;
  --text:      #f1f5f9;
  --muted:     #94a3b8;
  --primary:   #3b82f6;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warning:   #f59e0b;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  /* Prevent horizontal scroll */
  overflow-x: hidden;
}

/* ── Mobile: prevent double-tap zoom & tap highlight on all interactive ── */
button, input, select, textarea {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
/* Remove lingering focus ring after a tap (not keyboard nav) */
button:focus:not(:focus-visible) { outline: none; box-shadow: none; }

/* ── Header ─────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}

header h1 { font-size: 1.2rem; font-weight: 700; }

/* ── Status banner ───────────────────────────────────────────── */
.banner {
  margin: .6rem 1rem;
  padding: .6rem .9rem;
  border-radius: var(--radius);
  font-size: .875rem;
  cursor: pointer;
}
.banner.info  { background: #1e3a5f; color: #93c5fd; border: 1px solid #2563eb; }
.banner.error { background: #4c1d1d; color: #fca5a5; border: 1px solid #b91c1c; }

/* ── Room selector bar ────────────────────────────────────────── */
.room-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.room-select {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .6rem .9rem;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  appearance: auto;
}
.room-select:focus { border-color: var(--primary); }

/* ── Device list ─────────────────────────────────────────────── */
main.device-list {
  display: flex;
  flex-direction: column;
  padding: .75rem 1rem;
  gap: .6rem;
}

.device-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  user-select: none;
}
.device-row:active { background: #263043; border-color: var(--primary); }

.device-row-icon  { font-size: 2.2rem; line-height: 1; flex-shrink: 0; }
.device-row-info  { flex: 1; display: flex; flex-direction: column; gap: .15rem; }
.device-row-name  { font-size: 1.05rem; font-weight: 600; }
.device-row-sub   { font-size: .8rem; color: var(--muted); }
.device-row-chevron { font-size: 1.6rem; color: var(--muted); flex-shrink: 0; line-height: 1; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ── Remote view ─────────────────────────────────────────────── */
header.remote-header {
  padding: .75rem 1rem;
  gap: .5rem;
}

.remote-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1rem;
  font-weight: 700;
  overflow: hidden;
}
.remote-title span:first-child { font-size: 1.4rem; flex-shrink: 0; }
.remote-title span:last-child  { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main.remote-body {
  padding: .75rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.remote-loading {
  color: var(--muted);
  padding: 2rem;
  text-align: center;
}

.remote-card {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Each control row inside a remote card */
.remote-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 0;
  border-bottom: 1px solid var(--border);
}
.remote-row:last-child { border-bottom: none; }

/* Stack label above controls on narrow rows */
.remote-row-col {
  flex-direction: column;
  align-items: flex-start;
}

.remote-label {
  color: var(--muted);
  font-size: .85rem;
  min-width: 72px;
  flex-shrink: 0;
}

/* Buttons in remote view — larger touch targets */
.remote-btn {
  min-height: 48px;
  min-width: 64px;
  font-size: .95rem;
  padding: .55rem 1rem;
}

/* ── Stepper ──────────────────────────────────────────────────── */
.stepper { display: flex; align-items: center; gap: .5rem; }
.stepper-val { font-size: 1.15rem; font-weight: 700; min-width: 44px; text-align: center; }
.stepper-btn { min-width: 48px !important; font-size: 1.2rem !important; }

/* ── Segmented buttons ───────────────────────────────────────── */
.seg { display: flex; gap: .4rem; flex-wrap: nowrap; }
.seg-wrap { flex-wrap: wrap; width: 100%; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .12s, background .12s;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .75; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled):not(:active) { opacity: .88; }

.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover:not(:disabled):not(:active) { opacity: .88; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled):not(:active) { opacity: .88; }

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled):not(:active) { background: rgba(255,255,255,.06); }
.btn-outline:active { background: rgba(255,255,255,.1); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--primary);
}
.btn-ghost:hover:not(:disabled):not(:active) { background: rgba(59,130,246,.1); }

.btn-icon {
  min-width: 44px; min-height: 44px; padding: .4rem;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
}

.back-btn { font-size: 1.4rem; padding: .3rem .6rem; font-weight: 700; }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  padding: 1.5rem 1.25rem 2rem;
  width: 100%;
  max-width: 540px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 92vh;
  overflow-y: auto;
}
.modal h2 { font-size: 1.15rem; font-weight: 700; }

.modal label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .875rem;
  color: var(--muted);
}
.modal input,
.modal select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: .65rem .9rem;
  font-size: 1rem;
  outline: none;
}
.modal input:focus,
.modal select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59,130,246,.2); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: .25rem;
}

/* ── Room Manager ─────────────────────────────────────────────── */
.room-manager-list {
  display: flex; flex-direction: column; gap: .4rem;
  max-height: 240px; overflow-y: auto;
}
.room-manager-empty { color: var(--muted); font-size: .9rem; padding: .5rem 0; }
.room-manager-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .75rem;
  background: var(--bg); border-radius: 8px; border: 1px solid var(--border);
}
.room-manager-name  { flex: 1; font-weight: 500; }
.room-manager-count { font-size: .8rem; color: var(--muted); }

.room-add-row { display: flex; gap: .5rem; align-items: center; }
.room-add-row input {
  flex: 1; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: .6rem .9rem;
  font-size: .95rem; outline: none;
}
.room-add-row input:focus { border-color: var(--primary); }

/* ── TV Remote ────────────────────────────────────────────────── */

/* Power button — full width, prominent */
.tv-power-btn {
  width: 100%; margin-bottom: .5rem;
}

/* Main two-column section: vol strip (1/4) + d-pad (3/4) */
.tv-main-row {
  display: flex;
  gap: .5rem;
  align-items: stretch;
  padding: .5rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Left column — vertical volume strip */
.tv-vol-strip {
  flex: 0 0 25%;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  justify-content: space-between;
  align-items: stretch;
}
.tv-vol-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 600;
  padding: 0; border-radius: 10px;
  min-height: 52px;
}
.tv-mute-btn { font-size: 1.2rem; }

/* Right column — D-Pad */
.tv-dpad {
  flex: 0 0 75%;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center;
  gap: .4rem; padding: .25rem 0;
}
.tv-dpad-row {
  display: flex; gap: .4rem; align-items: center; justify-content: center;
}
.tv-dpad-btn {
  width: 62px; height: 62px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; padding: 0; border-radius: 50%;
}
.tv-dpad-ok {
  width: 72px; height: 72px;
  font-size: 1rem; font-weight: 700; border-radius: 50%;
}

/* System row — Back / Home / Menu, full width below the two-col section */
.tv-sys-row {
  display: flex;
  gap: .5rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.tv-sys-btn {
  flex: 1;
  text-align: center;
  font-size: .9rem;
}

/* App chip buttons */
.tv-app-btn { font-size: .85rem; }

/* Keyboard section */
.tv-keyboard-section {
  padding-top: .75rem;
  display: flex; flex-direction: column; gap: .6rem;
}
.tv-keyboard-toggle { align-self: flex-start; }
.tv-keyboard-body   { display: flex; flex-direction: column; gap: .6rem; }

.tv-pair-banner {
  background: rgba(245,158,11,.12); border: 1px solid var(--warning);
  border-radius: var(--radius); padding: .75rem 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.tv-pair-banner p { color: var(--warning); font-weight: 600; font-size: .9rem; }

.tv-ip-label {
  display: flex; flex-direction: column; gap: .3rem;
  font-size: .85rem; color: var(--text-muted);
}
.tv-ip-label input {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .5rem .8rem; font-size: 1rem; outline: none;
}
.tv-ip-label input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,.25);
}

.tv-pin-row {
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
}
.tv-pin-row input {
  flex: 1; min-width: 0; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .5rem .8rem; font-size: 1rem; letter-spacing: .15em; outline: none;
}

.tv-keyboard-row {
  display: flex; gap: .5rem; align-items: center;
}
.tv-keyboard-row input {
  flex: 1; min-width: 0; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: .5rem .8rem; font-size: 1rem; outline: none;
}

.tv-keyboard-row input:focus,
.tv-pin-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,.25);
}

