/* ============================================================
   DailyTask Web Control — Design System
   Source DNA: https://www.beautifului.dev/
   ============================================================ */

:root {
  /* Page & surfaces */
  --page: #f8f8f7;
  --surface: #ffffff;
  --inset: #f0f0ed;
  --field: #f0f0ed;

  /* Text */
  --ink: #1a1a1a;
  --ink-2: #5c5c5c;
  --ink-3: #8a8a8a;

  /* Lines & borders */
  --line: #e5e5e0;
  --line-strong: #d0d0cc;

  /* Accent & semantic */
  --accent: #3d9aff;
  --hover: #f5f5f0;
  --orange: #f68f3c;
  --red: #ee5c61;
  --green: #34d399;

  /* Radius */
  --card: 14px;
  --control: 8px;

  /* Shadows */
  --hairline: 0 1px 2px rgba(0, 0, 0, 0.04);
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  --raised: 0 2px 10px rgba(0, 0, 0, 0.045);
  --overlay: 0 8px 24px rgba(0, 0, 0, 0.12);
  --btn: 0 1px 2px rgba(0, 0, 0, 0.04);

  /* Remote screen */
  --remote-hud: rgba(12, 14, 18, 0.7);
  --remote-control: rgba(18, 20, 25, 0.78);
  --remote-control-hover: rgba(255, 255, 255, 0.14);

  /* Legacy mappings (for compatibility) */
  --bg: var(--page);
  --panel: var(--surface);
  --border: var(--line);
  --text: var(--ink);
  --muted: var(--ink-3);
  --primary: var(--accent);
  --primary-dark: #2b7fd9;
  --green: var(--green);
  --red: var(--red);
  --orange: var(--orange);
  --radius: var(--card);
  --shadow: var(--card-shadow);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px / 1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* ============ Buttons ============ */

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--control);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 150ms ease, border-color 150ms ease,
    box-shadow 150ms ease, transform 100ms ease, color 150ms ease;
}

button:hover {
  background: var(--hover);
  border-color: var(--line-strong);
}

button:active {
  transform: scale(0.97);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: var(--btn);
}

button.primary:hover {
  background: #2b7fd9;
  border-color: #2b7fd9;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-3);
}

button.ghost:hover {
  background: var(--hover);
  color: var(--ink);
}

button.full {
  width: 100%;
}

button.danger {
  color: var(--red);
}

/* ============ Inputs ============ */

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--control);
  padding: 9px 12px;
  background: var(--field);
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 154, 255, 0.12);
  background: var(--surface);
}

/* ============ Utility ============ */

.hidden {
  display: none !important;
}

.muted {
  color: var(--ink-3);
}

.error {
  color: var(--red);
}

/* ============ Badges ============ */

.badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  transition: border-color 150ms ease;
}

.badge.online {
  color: #15803d;
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.badge.offline {
  color: var(--ink-3);
  border-color: var(--line);
}

.badge.pending {
  color: #c2410c;
  border-color: #fed7aa;
  background: #fff7ed;
}

.badge.executing {
  color: #c2410c;
  border-color: #fed7aa;
  background: #fff7ed;
}

/* ============ Login ============ */

#login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: none;
  border-radius: var(--card);
  box-shadow: var(--overlay);
  padding: 32px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-panel form {
  margin-top: 20px;
  display: grid;
  gap: 14px;
}

.login-panel label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

/* ============ App Layout ============ */

#app-view {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

/* ============ Sidebar ============ */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  color: var(--ink);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px;
}

.brand strong {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand .ghost {
  color: var(--ink-3);
}

.device-list {
  display: grid;
  gap: 6px;
  overflow: auto;
}

.device-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-2);
  border-radius: var(--control);
  padding: 10px 12px;
  font-weight: 500;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.device-item:hover {
  background: var(--hover);
  border-color: var(--line);
}

.device-item.active {
  background: rgba(61, 154, 255, 0.08);
  border-color: rgba(61, 154, 255, 0.2);
  color: var(--accent);
}

.device-item .name {
  font-weight: 600;
  color: var(--ink);
}

.device-item.active .name {
  color: var(--accent);
}

.device-item .meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--ink-3);
}

.device-item.active .meta {
  color: var(--ink-3);
}

.device-metrics {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 3px;
  color: var(--ink-3);
  font-size: 11px;
}

/* ============ Main Content ============ */

main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
}

.topbar h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.content {
  padding: 24px;
  max-width: 1080px;
  width: 100%;
}

/* ============ Empty State ============ */

.empty-state {
  background: var(--surface);
  border: none;
  border-radius: var(--card);
  box-shadow: var(--hairline);
  padding: 48px 24px;
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

/* ============ Tabs ============ */

.tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  border-radius: 0;
  padding: 12px 16px;
  color: var(--ink-3);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.tab:hover {
  color: var(--ink);
  background: transparent;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ============ Cards / Sections ============ */

.grid {
  display: grid;
  gap: 16px;
}

.two-col {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.section {
  background: var(--surface);
  border: none;
  border-radius: var(--card);
  box-shadow: var(--card-shadow);
  padding: 20px;
  transition: box-shadow 150ms ease;
}

.section:hover {
  box-shadow: var(--raised);
}

.section h3 {
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ============ Key-Value Pairs ============ */

.kv {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px 12px;
  margin: 0;
}

.kv dt {
  color: var(--ink-3);
  font-size: 13px;
}

.kv dd {
  margin: 0;
  word-break: break-all;
  font-size: 13px;
  font-weight: 500;
}

/* ============ Command Grid ============ */

.command-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.command-grid button {
  text-align: left;
}

/* ============ Tables ============ */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: none;
  border-radius: var(--card);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 13px;
}

th {
  background: var(--inset);
  color: var(--ink-3);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tr:last-child td {
  border-bottom: 0;
}

tr:hover td {
  background: var(--hover);
}

/* ============ Code / Pre ============ */

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--inset);
  border: none;
  border-radius: var(--control);
  padding: 12px;
  margin: 0;
  max-height: 240px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
}

/* ============ Screenshots ============ */

.screenshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.screenshot-item {
  background: var(--surface);
  border: none;
  border-radius: var(--card);
  box-shadow: var(--card-shadow);
  padding: 12px;
  transition: box-shadow 150ms ease;
}

.screenshot-item:hover {
  box-shadow: var(--raised);
}

.screenshot-item img {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: var(--control);
  background: var(--inset);
  cursor: zoom-in;
}

.screenshot-timeline {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.timeline-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline-date {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.timeline-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.screenshot-preview {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(0, 0, 0, 0.72);
}

.screenshot-preview img {
  max-width: min(92vw, 900px);
  max-height: 86vh;
  object-fit: contain;
  border-radius: var(--control);
  background: #000;
}

.screenshot-preview button {
  position: fixed;
  top: 20px;
  right: 24px;
  color: #fff;
}

/* ============ Calendar ============ */

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 14px;
}

.calendar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.calendar-month-heading {
  margin: 0 0 2px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

.calendar-grid {
  border: none;
  border-radius: var(--card);
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.calendar-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--inset);
}

.calendar-header-day {
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.calendar-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar-day {
  padding: 10px;
  text-align: center;
  min-height: 44px;
  cursor: pointer;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 150ms ease;
  font: inherit;
  color: inherit;
  background: var(--surface);
}

.calendar-day small {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
}

.calendar-day:hover:not(.empty) {
  background: var(--hover);
}

.calendar-day.empty {
  background: var(--page);
  cursor: default;
}

.calendar-day.today {
  background: #eff6ff;
  color: var(--accent);
  font-weight: 700;
}

.calendar-day.workday {
  color: #15803d;
}

.calendar-day.holiday {
  color: var(--red);
  background: #fef2f2;
}

.calendar-day.override-punch {
  color: #c2410c;
  background: #fff7ed;
  font-weight: 600;
}

.calendar-day.override-workday {
  color: #047857;
  background: #ecfdf5;
  font-weight: 600;
}

.calendar-day.override-skip {
  color: var(--ink-3);
  background: var(--inset);
  text-decoration: line-through;
}

.calendar-day.override-pause {
  color: #7c3aed;
  background: #f5f3ff;
  font-weight: 600;
}

.calendar-day.rest {
  color: var(--ink-3);
}

.calendar-legend {
  display: flex;
  gap: 16px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-3);
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.legend-color.workday {
  background: #f0fdf4;
}

.legend-color.holiday {
  background: #fef2f2;
}

.legend-color.override-punch {
  background: #fff7ed;
}

.legend-color.override-workday {
  background: #ecfdf5;
}

.legend-color.override-skip {
  background: var(--inset);
}

.legend-color.override-pause {
  background: #f5f3ff;
}

.calendar-day-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  min-width: 180px;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--control);
  background: var(--surface);
  box-shadow: var(--raised);
}

.calendar-day-menu strong {
  padding: 4px 8px 6px;
  font-size: 12px;
}

.calendar-day-menu button {
  justify-content: flex-start;
  min-height: 36px;
  padding: 7px 8px;
  border: 0;
  background: transparent;
  text-align: left;
}

.calendar-day-menu button:hover {
  background: var(--hover);
}

.legend-color.rest {
  background: var(--page);
}

/* ============ Override Row ============ */

.override-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 110px auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
}

.check-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
}

.check-row input[type="checkbox"] {
  width: auto;
}

/* ============ Actions List ============ */

dl.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0 0;
}

/* ============ Toast ============ */

#toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--control);
  padding: 12px 16px;
  box-shadow: var(--overlay);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  z-index: 1000;
}

/* ============ Dialog ============ */

dialog {
  border: none;
  border-radius: var(--card);
  box-shadow: var(--overlay);
  padding: 28px;
  width: min(520px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

dialog form {
  display: grid;
  gap: 14px;
}

dialog label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}

.registration-qr {
  display: block;
  width: min(320px, 100%);
  aspect-ratio: 1;
  margin: 18px auto;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--control);
}

/* ============ Remote Screen ============ */

.remote-screen-panel {
  max-width: none;
}

.remote-screen-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.remote-screen-heading h3,
.remote-screen-heading p {
  margin: 0;
}

.remote-screen-heading p {
  margin-top: 4px;
}

.remote-screen-stage {
  --remote-screen-aspect: 9 / 16;
  --remote-screen-ratio: 0.5625;
  --remote-screen-inverse-ratio: 1.7778;
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, calc(72vh * var(--remote-screen-ratio)));
  height: min(72vh, calc(100vw * var(--remote-screen-inverse-ratio)));
  min-height: 420px;
  margin: 18px auto 0;
  overflow: hidden;
  background: #050607;
  border-radius: var(--control);
}

.remote-screen-media {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: var(--remote-screen-aspect);
  background: #050607;
}

.remote-screen-controls {
  position: absolute;
  z-index: 6;
  top: 56px;
  right: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  max-width: calc(100% - 24px);
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--control);
  background: rgba(248, 248, 247, 0.96);
  box-shadow: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 150ms ease, transform 150ms ease, visibility 150ms;
}

.remote-screen-stage.settings-open .remote-screen-controls {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.remote-screen-hud,
.remote-screen-dock {
  transition: opacity 180ms ease, transform 180ms ease;
}

.remote-screen-controls label {
  min-width: 120px;
}

.remote-quality-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: auto !important;
}

.remote-quality-toggle input {
  width: auto;
}

.remote-screen-hud {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 24px);
  padding: 7px 10px;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--control);
  background: var(--remote-hud);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 10px;
}

.remote-screen-hud > span {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.remote-screen-hud strong {
  color: #fff;
  font-weight: 600;
  font-size: 11px;
}

.remote-screen-hud small {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.58);
}

.remote-screen-live-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--ink-3);
  box-shadow: 0 0 0 3px rgba(138, 138, 138, 0.18);
}

.remote-screen-stage.is-streaming .remote-screen-live-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}

#remote-screen-video {
  display: none;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}

.remote-screen-video-container.webrtc-active #remote-screen-video {
  display: block;
}

#remote-screen-canvas {
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.remote-screen-video-container.webrtc-active #remote-screen-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.remote-screen-start {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.remote-screen-start:active {
  transform: translate(-50%, -50%) scale(0.97);
}

.remote-screen-dock {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: var(--remote-control);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

.remote-screen-dock button {
  width: 42px;
  height: 40px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #fff;
  border: 0;
  border-radius: var(--control);
  background: transparent;
  font-size: 19px;
}

.remote-screen-dock button:hover {
  background: var(--remote-control-hover);
}

.remote-screen-dock .remote-screen-app-button {
  color: #a9d4ff;
  background: rgba(61, 154, 255, 0.22);
  font-size: 11px;
  font-weight: 700;
}

.remote-screen-edge {
  display: none;
  position: absolute;
  z-index: 8;
  top: 50%;
  width: 18px;
  height: 64px;
  padding: 0;
  color: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--remote-control);
  font-size: 18px;
  transform: translateY(-50%);
}

.remote-screen-edge-left {
  left: 0;
  border-left: 0;
  border-radius: 0 8px 8px 0;
}

.remote-screen-edge-right {
  right: 0;
  border-right: 0;
  border-radius: 8px 0 0 8px;
}

.remote-screen-stage.overlay-collapsed .remote-screen-hud,
.remote-screen-stage.overlay-collapsed .remote-screen-dock {
  opacity: 0;
  pointer-events: none;
}

.remote-screen-stage.overlay-collapsed .remote-screen-hud {
  transform: translate(-50%, -10px);
}

.remote-screen-stage.overlay-collapsed .remote-screen-dock {
  transform: translate(-50%, 12px);
}

.remote-screen-stage.overlay-collapsed .remote-screen-controls {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
}

.remote-screen-stage.overlay-collapsed .remote-screen-hud,
.remote-screen-stage.overlay-collapsed .remote-screen-dock {
  pointer-events: none;
}

.remote-screen-stage.overlay-collapsed .remote-screen-edge {
  display: block;
}

.remote-screen-stage.dock-pinned-left .remote-screen-dock {
  left: 14px;
  right: auto;
  transform: none;
}

.remote-screen-stage.dock-pinned-right .remote-screen-dock {
  left: auto;
  right: 14px;
  transform: none;
}

.remote-screen-debug {
  margin-top: 12px;
  color: var(--ink-3);
  font-size: 12px;
}

.remote-screen-debug summary {
  cursor: pointer;
}

.remote-screen-log {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--card);
  padding: 10px;
  font-size: 12px;
  max-height: 180px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ============ Responsive ============ */

@media (max-width: 760px) {
  #app-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 12px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .device-list {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 16px;
  }

  .topbar {
    padding: 12px 16px;
  }

  .tabs {
    gap: 4px;
    padding: 0 12px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

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

  .tab {
    flex: 0 0 auto;
    padding: 11px 13px;
    white-space: nowrap;
  }

  body.remote-screen-tab {
    overflow: hidden;
    background: #050607;
  }

  body.remote-screen-tab #app-view {
    display: block;
    min-height: 100dvh;
    background: #050607;
  }

  body.remote-screen-tab .sidebar,
  body.remote-screen-tab .topbar,
  body.remote-screen-tab .tabs,
  body.remote-screen-tab .remote-screen-heading,
  body.remote-screen-tab .remote-screen-debug {
    display: none;
  }

  body.remote-screen-tab main,
  body.remote-screen-tab #device-view,
  body.remote-screen-tab #tab-remote-screen,
  body.remote-screen-tab .remote-screen-panel {
    width: 100%;
    max-width: none;
    height: 100dvh;
    min-height: 100dvh;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: #050607;
    box-shadow: none;
  }

  body.remote-screen-tab .remote-screen-stage {
    width: 100vw;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    border-radius: 0;
  }

  body.remote-screen-tab .remote-screen-media {
    width: min(100vw, calc(100dvh * var(--remote-screen-ratio)));
    height: min(100dvh, calc(100vw * var(--remote-screen-inverse-ratio)));
    flex: none;
  }

  body.remote-screen-tab .remote-screen-controls {
    top: auto;
    right: 12px;
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px);
    left: 12px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: none;
  }

  body.remote-screen-tab .remote-screen-controls label:nth-child(3),
  body.remote-screen-tab .remote-quality-toggle,
  body.remote-screen-tab #stop-remote-screen {
    grid-column: 1 / -1;
  }

  body.remote-screen-tab .remote-screen-hud-detail {
    display: none;
  }

  body.remote-screen-tab .remote-screen-dock {
    gap: 4px;
  }

  body.remote-screen-tab .remote-screen-dock button {
    width: 40px;
  }

  body.remote-screen-tab .remote-screen-stage.dock-pinned-left .remote-screen-dock,
  body.remote-screen-tab .remote-screen-stage.dock-pinned-right .remote-screen-dock {
    top: 50%;
    bottom: auto;
    flex-direction: column;
    transform: translateY(-50%);
  }

  body.remote-screen-tab .remote-screen-stage.dock-pinned-left .remote-screen-dock {
    left: 10px;
    right: auto;
  }

  body.remote-screen-tab .remote-screen-stage.dock-pinned-right .remote-screen-dock {
    left: auto;
    right: 10px;
  }

  body.remote-screen-tab .remote-screen-stage.overlay-collapsed .remote-screen-edge {
    display: grid;
    place-items: center;
  }
}

.remote-screen-stage:fullscreen,
.remote-screen-stage.browser-fullscreen {
  width: 100vw;
  height: 100vh;
  min-height: 0;
  margin: 0;
  border-radius: 0;
  background: #050607;
}

.remote-screen-stage:fullscreen .remote-screen-media,
.remote-screen-stage.browser-fullscreen .remote-screen-media {
  width: min(100vw, calc(100vh * var(--remote-screen-ratio)));
  height: min(100vh, calc(100vw * var(--remote-screen-inverse-ratio)));
}

/* ============ Approved Workflow Layout A ============ */

:root {
  --page: #f4f6f8;
  --surface: #ffffff;
  --inset: #eef1f3;
  --field: #f3f5f6;
  --ink: #18202a;
  --ink-2: #4f5b68;
  --ink-3: #72808e;
  --line: #dfe4ea;
  --line-strong: #c6ced7;
  --accent: #176b5d;
  --accent-soft: #eaf5f1;
  --accent-line: #9bc9bf;
  --primary-dark: #10584d;
  --hover: #f1f4f5;
  --card: 8px;
  --control: 6px;
  --card-shadow: 0 1px 3px rgba(24, 32, 42, 0.08);
  --raised: 0 5px 16px rgba(24, 32, 42, 0.09);
}

html,
body {
  min-width: 0;
  overflow-x: clip;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(23, 107, 93, 0.22);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-only {
  display: inline-grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
}

#app-view {
  grid-template-columns: 248px minmax(0, 1fr);
  background: var(--page);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  gap: 14px;
  padding: 20px 16px;
}

.brand {
  min-height: 42px;
  padding: 0;
}

.brand-name {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: var(--control);
  background: var(--accent);
  color: #fff;
  font-weight: 750;
}

.sidebar-label {
  padding: 2px 4px 0;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 650;
}

.device-list {
  align-content: start;
  gap: 8px;
}

.device-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 9px;
  border-color: var(--line);
  background: var(--surface);
}

.device-item.active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent);
}

.device-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: #dcebe7;
  color: var(--accent);
  font-weight: 750;
}

.device-copy,
.device-copy > span {
  min-width: 0;
}

.device-copy .name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-item .meta,
.device-metrics {
  overflow: hidden;
}

.device-item .meta span,
.device-metrics span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  gap: 8px;
  background: var(--surface);
}

main {
  min-height: 100dvh;
  background: var(--page);
}

.topbar {
  min-height: 72px;
  padding: 12px 24px;
}

.page-heading {
  min-width: 0;
}

.page-heading h2 {
  overflow-wrap: anywhere;
}

.page-heading p {
  margin: 3px 0 0;
  color: var(--ink-3);
  font-size: 12px;
}

#connection-state.online::before,
#connection-state.pending::before {
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.workspace-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-width: 0;
  min-height: 58px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.workspace-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 58px;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-3);
  white-space: nowrap;
}

.workspace-nav-item:hover {
  background: #f8faf9;
  color: var(--ink);
}

.workspace-nav-item.active {
  color: var(--accent);
  font-weight: 650;
}

.workspace-nav-item.active::after {
  position: absolute;
  right: 22%;
  bottom: 0;
  left: 22%;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
  content: "";
}

.feature-subnav {
  display: none;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.feature-subnav.has-active-group {
  display: block;
}

.feature-tab-group {
  display: none;
  align-items: center;
  gap: 4px;
}

.feature-tab-group.active {
  display: flex;
}

.feature-subnav .tab {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  gap: 7px;
  padding: 7px 12px;
  border: 0;
  border-radius: var(--control);
  white-space: nowrap;
}

.feature-subnav .tab.active {
  border-bottom-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.content {
  width: min(1180px, 100%);
  max-width: none;
  margin: 0 auto;
  padding: 24px;
}

.section {
  border: 1px solid var(--line);
  box-shadow: var(--card-shadow);
}

.section:hover {
  box-shadow: var(--card-shadow);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 16px;
}

.section-heading h3 {
  margin: 0;
  font-size: 16px;
}

.section-heading p {
  margin: 3px 0 0;
  font-size: 12px;
}

.overview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.85fr);
  gap: 16px;
}

.status-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 -20px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.status-kpis > div {
  min-width: 0;
  padding: 16px 20px;
  border-right: 1px solid var(--line);
}

.status-kpis > div:last-child {
  border-right: 0;
}

.status-kpis span,
.status-kpis small {
  display: block;
  color: var(--ink-3);
  font-size: 12px;
}

.status-kpis strong {
  display: block;
  margin: 4px 0 2px;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.device-details {
  margin-top: 16px;
}

.device-details summary {
  min-height: 40px;
  padding: 9px 0;
  color: var(--ink-2);
  cursor: pointer;
  font-weight: 650;
}

.device-details .kv {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.next-task-card {
  align-self: start;
}

#next-task-area p:first-child {
  font-size: 20px !important;
  font-weight: 650;
}

.overview-actions {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

.overview-actions button {
  min-height: 44px;
}

.overview-remote-card {
  margin-top: 16px;
}

.overview-remote-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.overview-remote-actions button {
  min-height: 42px;
}

#command-table,
#log-table,
#notification-table {
  max-width: 100%;
  overflow-x: auto;
}

#command-table table,
#log-table table,
#notification-table table {
  min-width: 680px;
}

@media (max-width: 1180px) and (min-width: 701px) {
  #app-view {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .sidebar {
    align-items: center;
    padding-inline: 10px;
  }

  .brand {
    flex-direction: column;
  }

  .brand-name strong,
  .sidebar-label,
  .device-copy,
  .sidebar-add span {
    display: none;
  }

  .device-list {
    width: 100%;
  }

  .device-item {
    display: grid;
    width: 52px;
    min-height: 52px;
    margin-inline: auto;
    padding: 7px;
    place-items: center;
  }

  .sidebar-add {
    width: 44px;
    padding: 0;
  }

  .overview-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) and (min-width: 701px) {
  .workspace-nav-item {
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
  }

  .content {
    padding: 20px;
  }
}

@media (max-width: 760px) {
  body.remote-screen-tab .workspace-nav,
  body.remote-screen-tab .feature-subnav {
    display: none;
  }

  .calendar-day-menu.mobile-sheet {
    top: auto !important;
    right: 0;
    bottom: 0;
    left: 0 !important;
    width: 100%;
    min-width: 0;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 14px 14px 0 0;
  }

  .calendar-day-menu.mobile-sheet button {
    min-height: 44px;
    padding: 10px 12px;
  }
}

@media (max-width: 700px) {
  body:not(.remote-screen-tab) #app-view {
    display: block;
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  body:not(.remote-screen-tab) .sidebar {
    position: static;
    display: grid;
    height: auto;
    padding: 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    min-height: 40px;
  }

  .sidebar-label {
    display: none;
  }

  .device-list {
    display: flex;
    width: 100%;
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .device-list::-webkit-scrollbar {
    display: none;
  }

  .device-item {
    flex: 0 0 min(230px, calc(100vw - 24px));
    min-height: 66px;
  }

  .sidebar-add {
    width: 100%;
  }

  .topbar {
    min-height: 64px;
    padding: 10px 14px;
  }

  .topbar #connection-state {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace-nav {
    position: fixed;
    z-index: 30;
    right: 0;
    bottom: 0;
    left: 0;
    min-height: calc(62px + env(safe-area-inset-bottom));
    padding: 5px 6px env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    border-bottom: 0;
    box-shadow: 0 -8px 24px rgba(24, 32, 42, 0.08);
  }

  .workspace-nav-item {
    min-height: 52px;
    flex-direction: column;
    gap: 2px;
    padding: 3px 2px;
    border-radius: var(--control);
    font-size: 10px;
  }

  .workspace-nav-item.active {
    background: var(--accent-soft);
  }

  .workspace-nav-item.active::after {
    display: none;
  }

  .feature-subnav {
    padding: 7px 12px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .feature-subnav::-webkit-scrollbar {
    display: none;
  }

  .feature-tab-group.active {
    width: max-content;
  }

  .feature-subnav .tab {
    min-height: 44px;
  }

  .content {
    padding: 14px;
  }

  .overview-layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .status-kpis {
    grid-template-columns: 1fr;
  }

  .status-kpis > div {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding-block: 13px;
  }

  .status-kpis > div:last-child {
    border-bottom: 0;
  }

  .status-kpis strong {
    margin: 0;
    font-size: 18px;
  }

  .status-kpis small {
    grid-column: 1 / -1;
  }

  .device-details .kv,
  .kv {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .overview-remote-card {
    margin-top: 12px;
  }

  .overview-remote-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .override-row {
    grid-template-columns: 1fr;
  }

  .calendar-nav {
    justify-content: space-between;
    gap: 6px;
  }

  .calendar-nav button {
    min-height: 44px;
    padding-inline: 10px;
  }

  .calendar-day,
  .calendar-header-day {
    min-width: 0;
    padding-inline: 4px;
  }

  dialog {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  #toast {
    right: 12px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    left: 12px;
    max-width: none;
  }
}
