:root {
  --bg: #EAF1FB;
  --card-radius: 28px;
  --blue: #2F7DE1;
  --blue-dark: #1E5FBF;
  --green: #21A366;
  --green-dark: #17804E;
  --red: #E8432C;
  --red-dark: #C6301C;
  --ink: #1F2A44;
  --ink-soft: #5C6B87;
  --white: #FFFFFF;
  --shadow: 0 10px 24px rgba(31, 42, 68, 0.12);
  --focus-ring: 4px solid #FFC940;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden; /* no accidental scroll-bounce on a kiosk tablet */
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans Thai", "TH Sarabun New", "Sarabun", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none; /* prevent accidental text-selection popovers */
}

#app {
  height: 100%;
  width: 100%;
}

#view-root {
  height: 100%;
  width: 100%;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  touch-action: manipulation;
}

button:focus-visible, a:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 3px;
}

/* ---------- Top bar (shared across views) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  background: var(--white);
  box-shadow: 0 2px 10px rgba(31,42,68,0.06);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-icon {
  width: 48px;
  height: 48px;
}
.brand-text .title {
  font-size: 22px;
  font-weight: 800;
  color: #E91E63;
  line-height: 1.1;
}
.brand-text .subtitle {
  font-size: 13px;
  color: var(--ink-soft);
}

.page-title {
  font-size: 26px;
  font-weight: 800;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  padding: 14px 22px;
  border-radius: 18px;
  min-height: 60px;
}
.nav-btn:active { transform: scale(0.96); }
.nav-btn .icon { font-size: 22px; }

.greeting {
  text-align: center;
}
.greeting .hello {
  font-size: 30px;
  font-weight: 800;
}
.greeting .date {
  font-size: 16px;
  color: var(--ink-soft);
}
.clock {
  font-size: 30px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- Dashboard grid ---------- */
.dash-wrap {
  height: calc(100% - 92px);
  display: flex;
  flex-direction: column;
  padding: 28px 32px;
  overflow-y: auto;
}

.dash-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 26px;
}

.tile {
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: var(--white);
  font-size: 32px;
  font-weight: 800;
  padding: 20px;
  min-height: 200px;
  transition: transform 0.08s ease;
}
.tile:active { transform: scale(0.97); }

.tile .emoji { font-size: 64px; line-height: 1; }
.tile .sub { font-size: 17px; font-weight: 500; opacity: 0.9; }

.tile-tv { background: linear-gradient(160deg, var(--blue), var(--blue-dark)); }
.tile-youtube { background: linear-gradient(160deg, var(--red), var(--red-dark)); }
.tile-call { background: linear-gradient(160deg, var(--green), var(--green-dark)); }

.dash-footer {
  margin-top: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.emergency-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--red);
  color: var(--white);
  font-size: 24px;
  font-weight: 800;
  padding: 20px 44px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.emergency-btn:active { transform: scale(0.97); }
.emergency-btn .emoji { font-size: 28px; }

/* ---------- List views (channels / videos / contacts) ---------- */
.list-wrap {
  height: calc(100% - 92px);
  padding: 28px 32px;
  overflow-y: auto;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 22px;
}

.card {
  background: var(--white);
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 22px 12px;
  min-height: 170px;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}
.card:active { transform: scale(0.97); }
.card .thumb {
  width: 72px;
  height: 72px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  background: var(--bg);
}
.card img.thumb {
  object-fit: cover;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  gap: 16px;
  color: var(--ink-soft);
  font-size: 20px;
  text-align: center;
}
.empty-state .emoji { font-size: 56px; }

/* ---------- Contacts (phone) ---------- */
.contact-card {
  background: var(--white);
  border-radius: 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 20px 24px;
}
.contact-card .avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  overflow: hidden;
  flex-shrink: 0;
}
.contact-card .avatar img { width: 100%; height: 100%; object-fit: cover; }
.contact-card .info { flex: 1; }
.contact-card .name { font-size: 22px; font-weight: 800; }
.contact-card .relation { font-size: 15px; color: var(--ink-soft); }
.contact-card .call-btn {
  background: var(--green);
  color: var(--white);
  font-size: 18px;
  font-weight: 800;
  padding: 16px 28px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.contact-card .call-btn:active { transform: scale(0.96); }

.contact-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

/* ---------- Fullscreen player (TV / YouTube) ---------- */
.player-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.player-frame-holder {
  flex: 1;
  background: #000;
  position: relative;
}
.player-frame-holder iframe {
  width: 100%;
  height: 100%;
  border: 0;
}
.player-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 22px;
  background: #000;
}

/* ---------- Confirm overlay (emergency call only) ---------- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 26, 44, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.confirm-overlay.hidden { display: none; }
.confirm-box {
  background: var(--white);
  border-radius: 26px;
  padding: 40px 48px;
  box-shadow: var(--shadow);
  text-align: center;
  min-width: 380px;
}
.confirm-box p {
  font-size: 26px;
  font-weight: 800;
  margin: 0 0 28px;
}
.confirm-actions {
  display: flex;
  gap: 18px;
  justify-content: center;
}
.btn {
  font-size: 20px;
  font-weight: 800;
  padding: 16px 32px;
  border-radius: 16px;
  min-width: 140px;
}
.btn-secondary { background: var(--bg); color: var(--ink); }
.btn-danger { background: var(--red); color: var(--white); }
.btn:active { transform: scale(0.96); }

/* ---------- Responsive: smaller tablets ---------- */
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-cards { grid-template-columns: repeat(3, 1fr); }
  .contact-list { grid-template-columns: 1fr; }
}

/* ---------- Responsive: phones (portrait test devices) ---------- */
@media (max-width: 600px) {
  .topbar { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .brand-icon { width: 36px; height: 36px; }
  .brand-text .title { font-size: 17px; }
  .brand-text .subtitle { font-size: 11px; }
  .clock { font-size: 20px; }
  .page-title { font-size: 19px; }
  .nav-btn { font-size: 14px; padding: 10px 14px; min-height: 44px; }

  .dash-wrap { padding: 16px; }
  .greeting .hello { font-size: 21px; }
  .greeting .date { font-size: 13px; }
  .dash-grid { grid-template-columns: 1fr; gap: 14px; }
  .tile { min-height: 110px; flex-direction: row; font-size: 22px; padding: 16px 20px; justify-content: flex-start; }
  .tile .emoji { font-size: 36px; }
  .tile .sub { display: none; }

  .emergency-btn { font-size: 16px; padding: 14px 26px; }

  .list-wrap { padding: 16px; }
  .grid-cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .card { min-height: 120px; font-size: 15px; padding: 14px 8px; }
  .card .thumb { width: 52px; height: 52px; font-size: 26px; }

  .contact-card { padding: 14px 16px; }
  .contact-card .avatar { width: 52px; height: 52px; font-size: 22px; }
  .contact-card .name { font-size: 17px; }
  .contact-card .call-btn { font-size: 14px; padding: 10px 16px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .tile, .card, .nav-btn, .emergency-btn, .contact-card .call-btn, .btn {
    transition: none !important;
  }
}
