/* Remote Fleet admin — Apple-inspired design system */

:root {
  color-scheme: light dark;

  --bg: #f5f5f7;
  --bg-elevated: rgba(255, 255, 255, 0.72);
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-inset: #fafafa;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #a1a1a6;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.12);
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, 0.16);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Noto Sans KR", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: rgba(28, 28, 30, 0.72);
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --surface-inset: #141416;
    --text: #f5f5f7;
    --text-2: #98989d;
    --text-3: #636366;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --purple: #bf5af2;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 16px 56px rgba(0, 0, 0, 0.6);
  }
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f7; --bg-elevated: rgba(255, 255, 255, 0.72); --surface: #ffffff;
  --surface-2: #f2f2f7; --surface-inset: #fafafa; --text: #1d1d1f; --text-2: #6e6e73;
  --text-3: #a1a1a6; --border: rgba(0, 0, 0, 0.08); --border-strong: rgba(0, 0, 0, 0.16);
  --accent: #0071e3; --accent-soft: rgba(0, 113, 227, 0.12); --green: #34c759;
  --orange: #ff9500; --red: #ff3b30; --purple: #af52de;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.08); --shadow-lg: 0 12px 48px rgba(0,0,0,0.16);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000; --bg-elevated: rgba(28, 28, 30, 0.72); --surface: #1c1c1e;
  --surface-2: #2c2c2e; --surface-inset: #141416; --text: #f5f5f7; --text-2: #98989d;
  --text-3: #636366; --border: rgba(255, 255, 255, 0.1); --border-strong: rgba(255, 255, 255, 0.2);
  --accent: #0a84ff; --accent-soft: rgba(10, 132, 255, 0.18); --green: #30d158;
  --orange: #ff9f0a; --red: #ff453a; --purple: #bf5af2;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4); --shadow-md: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-lg: 0 16px 56px rgba(0,0,0,0.6);
}

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

html, body { height: 100%; }

html { -webkit-tap-highlight-color: transparent; }
body.sheet-open { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--text-2); font-weight: 600; margin: 18px 0 8px; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.rtt-ok { color: var(--green); }
.rtt-warn { color: var(--orange); }
.rtt-bad { color: var(--red); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ Layout */

#app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px; font-weight: 700; letter-spacing: -0.02em; font-size: 15px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--purple)); box-shadow: 0 0 12px var(--accent-soft); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 10px; border: 0; border-radius: 9px;
  background: transparent; color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-align: left;
  transition: background .15s ease, color .15s ease;
}
.sidebar-nav button svg { width: 17px; height: 17px; flex: none; color: var(--text-2); transition: color .15s ease; }
.sidebar-nav button:hover { background: var(--surface-2); }
.sidebar-nav button.active { background: var(--accent); color: #fff; }
.sidebar-nav button.active svg { color: rgba(255, 255, 255, 0.9); }
.sidebar-nav .count { margin-left: auto; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-variant-numeric: tabular-nums; }
.sidebar-nav button.active .count { background: rgba(255,255,255,0.24); color: #fff; }

.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 0 4px; }
.status-chip { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); }
.status-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.status-chip.online .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.user-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.user-row .badge { text-transform: uppercase; font-size: 10px; letter-spacing: 0.04em; }

.content { padding: 26px 30px 60px; max-width: 1240px; width: 100%; margin: 0 auto; min-width: 0; }

.view { display: none; animation: fade .22s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------- Components */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }

button {
  font: inherit; font-weight: 500;
  border: 0; border-radius: var(--radius-sm);
  padding: 7px 13px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
button:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--text) 8%); }
button:active { transform: scale(0.98); }
button:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 1px; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
button.danger { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
button.danger:hover { background: color-mix(in srgb, var(--red) 22%, transparent); }
button.ghost { background: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.icon { padding: 7px 9px; }
button svg { width: 15px; height: 15px; vertical-align: -2px; }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  min-width: 0;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
input[type="file"] { padding: 5px 8px; }
::placeholder { color: var(--text-3); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }
.pill.warn { background: color-mix(in srgb, var(--orange) 16%, transparent); color: var(--orange); }
.pill.bad { background: color-mix(in srgb, var(--red) 14%, transparent); color: var(--red); }
.pill.live { background: var(--accent-soft); color: var(--accent); }
.pill.live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 11px; font-weight: 600; }
.tag-list { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 500; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text-2); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 38px; height: 23px; border-radius: 999px; background: var(--border-strong); transition: background .2s ease; flex: none; position: relative; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s cubic-bezier(.3,1.4,.5,1); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(15px); }

/* Segmented control */
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); margin: 14px 0 16px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button { padding: 6px 14px; border-radius: 7px; background: transparent; color: var(--text-2); font-size: 13px; white-space: nowrap; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tab-panel { display: none; animation: fade .2s ease; }
.tab-panel.active { display: block; }

/* -------------------------------------------------------------- Device list */

.device-layout { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 767px) { .device-layout { grid-template-columns: 1fr; } }
@media (min-width: 768px) and (max-width: 1199px) {
  .device-layout { grid-template-columns: minmax(260px, 300px) minmax(0, 1fr); gap: 14px; }
}

.device-list { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow-y: auto; margin: 0 -6px; }
.device-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 10px 12px; border-radius: 11px;
  background: transparent; text-align: left;
}
.device-item:hover { background: var(--surface-2); }
.device-item.selected { background: var(--accent-soft); }
.device-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; transition: background .2s; }
.device-item.online .device-dot { background: var(--green); box-shadow: 0 0 9px color-mix(in srgb, var(--green) 60%, transparent); }
.device-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.device-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-meta { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-side { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex: none; }

.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.detail-sub { display: flex; align-items: center; gap: 8px; margin-top: 6px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.grid .item { background: var(--surface-inset); border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; }
.grid .item .k { color: var(--text-2); font-size: 11.5px; }
.grid .item .v { font-size: 13px; word-break: break-word; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: 0; }
tbody tr.selectable { cursor: pointer; }
tbody tr.selectable:hover { background: var(--surface-2); }
tbody tr.selected { background: var(--accent-soft); }

.log {
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  max-height: 240px;
  min-height: 44px;
  overflow: auto;
  font: 12px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
}

#screen-frame, #rtc-video { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; background: #000; transform-origin: center center; will-change: transform; user-select: none; -webkit-user-drag: none; }
#screen-frame.controllable { cursor: crosshair; }
#rtc-video { object-fit: contain; }
#rtc-video.zoomed { cursor: grab; }
.monitor-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; }
.monitor-tiles.hidden { display: none; }
.monitor-tile { position: relative; background: #000; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.monitor-tile { cursor: pointer; transition: transform .12s ease, box-shadow .15s ease; }
.monitor-tile:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.monitor-tile img { width: 100%; display: block; }
.monitor-tile .tile-head { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; align-items: center; justify-content: space-between; z-index: 2; }
.monitor-tile .tile-action { padding: 3px 9px; border-radius: 999px; background: rgba(37,99,235,.85); color: #fff; font-size: 11px; font-weight: 700; }
.monitor-tile .tile-label {
  position: absolute; top: 8px; left: 8px; padding: 3px 9px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 12px; font-weight: 600;
}
.remote-cursor {
  position: absolute; width: 16px; height: 22px; margin-left: -1px; margin-top: -1px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='22' viewBox='0 0 16 22'><path d='M1 1 L1 17 L5.4 12.9 L8.4 19 L11.2 17.7 L8.3 11.7 L13.5 11.3 Z' fill='white' stroke='%23111827' stroke-width='1.4' stroke-linejoin='round'/></svg>") no-repeat;
  pointer-events: none; z-index: 3;
  transition: opacity .2s ease;
}
.screen-controls { margin-bottom: 10px; }
.clipboard-area { width: 100%; min-height: 64px; margin-top: 8px; resize: vertical; }
#stats-panel { margin-top: 10px; }
#shell-output { min-height: 160px; }
.drop-target { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 10px; }

/* ------------------------------------------------------------------- Views */

body { transition: background-color .25s ease, color .25s ease; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }


.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(120% 80% at 18% 0%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(100% 70% at 92% 8%, color-mix(in srgb, var(--purple) 14%, transparent), transparent 55%),
    var(--bg);
  transition: opacity .3s ease;
}
.landing-stack { display: flex; flex-direction: column; gap: 14px; width: 440px; max-width: 92vw; }
.login-card {
  width: 100%; display: flex; flex-direction: column; gap: 12px;
  padding: 30px; border-radius: 24px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 5%, var(--surface)), var(--surface) 45%);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  text-align: center;
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
}
a.primary, a.ghost {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; border-radius: var(--radius-sm);
  padding: 7px 13px; font-weight: 500; font-size: 14px;
}
a.primary { background: var(--accent); color: #fff; }
a.primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
a.ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
a.ghost:hover { background: var(--surface-2); color: var(--text); }
.login-card .logo { font-size: 40px; }
.login-card p { margin: 0; }
.login-card .actions { justify-content: center; }
.install-cta { width: 100%; padding: 13px 16px; font-size: 15px; }
.install-advanced { width: 100%; text-align: left; }
.install-advanced summary { cursor: pointer; color: var(--text-2); font-size: 13px; padding: 4px 0; }
.install-advanced .actions { justify-content: flex-start; margin-top: 8px; }
.install-advanced p { margin-top: 8px; }

/* ------------------------------------------------------------------ Toasts */

#toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 300; pointer-events: none; }
.toast {
  padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 500;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  animation: toast-in .25s cubic-bezier(.2,1.2,.4,1);
  max-width: min(560px, 90vw);
}
.toast.ok { color: var(--green); }
.toast.error { color: var(--red); }
.toast.leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.97); } }

/* ------------------------------------------------------------------ Modals */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade .18s ease;
}
.modal {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 22px;
  animation: modal-in .25s cubic-bezier(.2,1.2,.4,1);
}
.modal h3 { margin: 0 0 6px; color: var(--text); font-size: 16px; }
.modal p { margin: 0 0 14px; color: var(--text-2); font-size: 13px; }
.modal input, .modal textarea, .modal select { width: 100%; margin-bottom: 12px; }
.modal textarea { min-height: 90px; resize: vertical; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
@keyframes modal-in { from { opacity: 0; transform: scale(.94) translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------- Search & filters */

.search-row { margin-bottom: 8px; }
.search-row input { width: 100%; border-radius: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.chip { padding: 4px 12px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 500; }
.chip:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--text) 10%); }
.chip.active { background: var(--accent); color: #fff; }
.empty-state { text-align: center; padding: 26px 14px; color: var(--text-2); font-size: 13px; line-height: 1.7; }
.empty-state strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }

/* ----------------------------------------------------- Command palette */

.palette-backdrop { align-items: flex-start; padding-top: 12vh; }
.palette {
  width: 100%; max-width: 560px; border-radius: 16px; overflow: hidden;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: modal-in .2s cubic-bezier(.2,1.2,.4,1);
}
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent; padding: 15px 18px; font-size: 15px; }
.palette input:focus { box-shadow: none; background: transparent; }
.palette-list { max-height: 46vh; overflow-y: auto; padding: 6px; }
.palette-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 9px; background: transparent; text-align: left; font-size: 13.5px; }
.palette-item .hint { margin-left: auto; color: var(--text-3); font-size: 11.5px; }
.palette-item.active { background: var(--accent); color: #fff; }
.palette-item.active .hint { color: rgba(255,255,255,0.75); }
.palette-empty { padding: 18px; text-align: center; color: var(--text-2); font-size: 13px; }
.kbd { display: inline-block; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-family: var(--mono); font-size: 11px; color: var(--text-2); }

/* ------------------------------------------- Screen stage (CRD style) */

#screen-stage { position: relative; display: flex; flex-direction: column; gap: 10px; }
.session-help { margin-top: 10px; }
.session-bar { display: none; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; color: #fff; background: linear-gradient(to bottom, rgba(0, 0, 0, .72), rgba(0, 0, 0, .32)); }
#screen-stage.session-open .session-bar { display: flex; }
.session-title-wrap { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.session-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-status { font-size: 11.5px; opacity: .72; }
.session-icon { width: 38px; height: 38px; min-height: 0; padding: 8px; flex: none; border-radius: 10px; background: rgba(255, 255, 255, .14); color: #fff; }
.session-icon:hover { background: rgba(255, 255, 255, .26); }
.session-icon svg { width: 20px; height: 20px; display: block; margin: auto; }

#session-viewport {
  position: relative; display: flex; align-items: center; justify-content: center;
  height: min(62vh, 560px); background: #000; border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; overscroll-behavior: contain; touch-action: none;
}
#screen-frame.zoomed { cursor: grab; }
#session-viewport .monitor-tiles { width: 100%; height: 100%; overflow: auto; align-content: start; padding: 6px; }

.session-dock { display: flex; gap: 8px; flex-wrap: wrap; }
.session-dock button { flex: none; }

.session-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 90;
  width: min(92vw, 360px); display: flex; flex-direction: column;
  padding: calc(12px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-elevated); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .28s cubic-bezier(.2, .9, .3, 1);
  overflow-y: auto; overscroll-behavior: contain;
}
.session-drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-head .session-icon { background: var(--surface-2); color: var(--text); }
.drawer-body { display: flex; flex-direction: column; gap: 14px; }
.drawer-section { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.drawer-section:last-child { border-bottom: 0; }
.drawer-label { font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
.drawer-row { display: flex; gap: 8px; }
.drawer-row > * { flex: 1; }
.drawer-backdrop { position: fixed; inset: 0; z-index: 85; background: rgba(0, 0, 0, .45); }
.drawer-backdrop.hidden { display: none; }
.session-drawer .segmented { display: flex; }
.session-drawer .segmented button { flex: 1; }
.session-drawer select { width: 100%; }

#screen-stage.session-open { position: fixed; inset: 0; z-index: 80; gap: 0; padding: 0; background: #000; border-radius: 0; }
#screen-stage.session-open #session-viewport { flex: 1; height: auto; min-height: 0; border: 0; border-radius: 0; }
#screen-stage.session-open .session-dock {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 4;
  padding: 8px; border-radius: 14px; flex-wrap: nowrap; max-width: calc(100vw - 24px);
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#screen-stage.session-open .session-dock button { background: rgba(255, 255, 255, .14); color: #fff; border-radius: 10px; padding: 8px 12px; }
#screen-stage.session-open .session-dock button.primary { background: var(--accent); }
#screen-stage.session-open .session-dock button:hover { background: rgba(255, 255, 255, .26); }
body.session-open { overflow: hidden; }

#screen-stage:fullscreen { display: flex; flex-direction: column; background: #000; }
#screen-stage:fullscreen #session-viewport { flex: 1; height: auto; min-height: 0; border: 0; border-radius: 0; }
#screen-stage:fullscreen .session-bar { display: flex; }

.stream-stats {
  position: absolute; top: 10px; left: 10px;
  padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums; pointer-events: none; z-index: 3;
}

.screen-advanced { margin: 0; }
.screen-advanced > summary { cursor: pointer; color: var(--text-2); font-size: 13px; padding: 4px 0; }
.screen-advanced > .actions { margin-top: 8px; }
@media (max-width: 767px) {
  #session-viewport { height: min(58vh, 520px); }
  .screen-advanced > summary { font-size: 12.5px; }
  #screen-stage.session-open .session-dock button { padding: 9px 11px; font-size: 12.5px; }
}

/* ------------------------------------------------------ File browser */

.breadcrumb { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); flex: 1; min-width: 0; }
.breadcrumb button { padding: 3px 7px; border-radius: 7px; background: transparent; color: var(--accent); font-size: 12.5px; font-weight: 500; }
.breadcrumb button:hover { background: var(--accent-soft); }
.breadcrumb .sep { color: var(--text-3); }
.breadcrumb .current { color: var(--text); font-weight: 600; padding: 3px 7px; }
th button.sort { padding: 0; background: transparent; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; }
th button.sort:hover { color: var(--accent); }
th button.sort::after { content: ""; }
th button.sort[data-active="asc"]::after { content: " ↑"; }
th button.sort[data-active="desc"]::after { content: " ↓"; }
progress { width: 100%; height: 6px; border: 0; border-radius: 999px; overflow: hidden; margin: 6px 0; appearance: none; }
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

/* ------------------------------------------------------------ Login */

.login-error { color: var(--red); font-size: 12.5px; margin: 0; }
.copy-btn { padding: 2px 7px; margin-left: 6px; border-radius: 6px; background: transparent; color: var(--text-3); font-size: 11px; }
.copy-btn:hover { background: var(--surface-2); color: var(--accent); }

/* ------------------------------------------------- Flows & feedback */

button.busy { pointer-events: none; }
button.busy::after {
  content: ""; display: inline-block; width: 11px; height: 11px; margin-left: 7px;
  border-radius: 50%; border: 2px solid color-mix(in srgb, currentColor 30%, transparent);
  border-top-color: currentColor; animation: spin .7s linear infinite; vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.conn-banner {
  display: flex; align-items: center; gap: 9px;
  margin: 0 0 14px; padding: 9px 13px; border-radius: 11px;
  font-size: 13px;
  background: color-mix(in srgb, var(--orange) 12%, transparent);
  color: var(--orange);
}
.conn-banner.offline { background: color-mix(in srgb, var(--red) 12%, transparent); color: var(--red); }
.conn-banner::before {
  content: ""; width: 12px; height: 12px; flex: none; border-radius: 50%;
  border: 2px solid color-mix(in srgb, currentColor 30%, transparent); border-top-color: currentColor;
  animation: spin .8s linear infinite;
}
.conn-banner.offline::before { border: 0; animation: none; width: 8px; height: 8px; background: currentColor; }

.skeleton-row { height: 46px; border-radius: 11px; margin-bottom: 6px; background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.3s ease infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty-state svg { width: 42px; height: 42px; margin-bottom: 8px; color: var(--text-3); }

.tab-panel.slide-left { animation: slide-left .24s cubic-bezier(.2,.9,.3,1); }
.tab-panel.slide-right { animation: slide-right .24s cubic-bezier(.2,.9,.3,1); }
@keyframes slide-left { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
@keyframes slide-right { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

.toast { display: flex; align-items: center; gap: 12px; }
.toast button { padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 12.5px; }
.toast button:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

@media (min-width: 768px) {
  .detail-sticky {
    position: sticky; top: 0; z-index: 5;
    margin: -20px -20px 6px; padding: 16px 20px 6px;
    background: var(--bg-elevated);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .detail-sticky .segmented { margin: 10px 0 6px; }
}

/* ---------------------------------------------------- Mobile sheet */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0; pointer-events: none;
  transition: opacity .25s ease;
}
.sheet-backdrop.show { opacity: 1; pointer-events: auto; }
.grabber { display: none; }
#btn-sheet-close { display: none; }

@media (max-width: 767px) {
  #device-detail {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    max-height: 92vh; overflow-y: auto; margin: 0;
    border-radius: 22px 22px 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.2, .9, .3, 1);
  }
  #device-detail.sheet-open { transform: none; }
  #device-detail.dragging { transition: none; }
  .grabber {
    display: block; width: 42px; height: 5px; border-radius: 999px;
    background: var(--border-strong); margin: 8px auto 2px;
    touch-action: none; cursor: grab;
  }
  #btn-sheet-close { display: inline-flex; }
  #bulk-bar { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 45; margin: 0; }
}

/* --------------------------------------------------- Bulk selection */

.device-check {
  width: 18px; height: 18px; flex: none; border-radius: 6px;
  border: 1.5px solid var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; transition: background .15s ease, border-color .15s ease;
}
.device-item.checked .device-check { background: var(--accent); border-color: var(--accent); }
.device-item.checked .device-check::after { content: "✓"; }

.bulk-bar {
  position: sticky; bottom: 8px; z-index: 6;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 10px -6px -4px; padding: 10px 12px;
  border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  box-shadow: var(--shadow-md);
}
.bulk-bar button { padding: 5px 11px; font-size: 12.5px; }
.bulk-bar .muted { margin-right: auto; }

/* ------------------------------------------------------ Notifications */

#btn-notifications { position: relative; }
.notif-badge {
  position: absolute; top: 1px; right: 1px;
  min-width: 15px; height: 15px; padding: 0 4px; border-radius: 999px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.notification-panel {
  position: fixed; left: 16px; bottom: 78px; z-index: 60;
  width: min(360px, calc(100vw - 32px)); max-height: 60vh; overflow-y: auto;
  padding: 8px; border-radius: 16px;
  background: var(--bg-elevated);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: modal-in .2s cubic-bezier(.2, 1.2, .4, 1);
}
@media (max-width: 767px) { .notification-panel { left: 12px; right: 12px; bottom: 86px; width: auto; } }
.notification-row {
  display: flex; gap: 10px; align-items: flex-start; width: 100%;
  padding: 9px 10px; border-radius: 11px; background: transparent;
  text-align: left; font-size: 13px;
}
.notification-row:hover { background: var(--surface-2); }
.notification-row .notif-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; flex: none; background: var(--text-3); }
.notification-row.unread .notif-dot { background: var(--red); }
.notification-row .notif-main { flex: 1; min-width: 0; }
.notification-row .notif-when { color: var(--text-3); font-size: 11px; flex: none; }
.notification-empty { padding: 16px; text-align: center; color: var(--text-2); font-size: 13px; }

/* ------------------------------------------------------------ Dashboard */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat-card { background: var(--surface-inset); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.stat-card .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-card .label { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.stat-card.accent .value { color: var(--accent); }
.stat-card.ok .value { color: var(--green); }
.stat-card.warn .value { color: var(--orange); }

.alert-list, .activity-list { display: flex; flex-direction: column; }
.alert-row, .activity-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid var(--border); font-size: 13px;
}
.alert-row:last-child, .activity-row:last-child { border-bottom: 0; }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.alert-dot.warn { background: var(--orange); }
.alert-dot.bad { background: var(--red); }
.alert-row .grow, .activity-row .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-row .when, .activity-row .when { color: var(--text-3); font-size: 11.5px; flex: none; }
.stat-card.clickable, .alert-row.clickable { cursor: pointer; }
.stat-card.clickable { transition: transform .12s ease, box-shadow .15s ease; }
.stat-card.clickable:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.alert-row.clickable { transition: background .15s ease; border-radius: 8px; }
.alert-row.clickable:hover { background: var(--surface-2); }
.stat-card.clickable:focus-visible, .alert-row.clickable:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.two-col .card + .card { margin-top: 0; }
@media (max-width: 767px) { .two-col { grid-template-columns: 1fr; gap: 12px; } }
.quickstart { margin: 0; padding-left: 20px; color: var(--text-2); font-size: 13px; line-height: 2; }
.quickstart button { margin-left: 4px; }

/* ------------------------------------------------------------- Responsive */

/* Tablet (768-1199): collapsed icon rail ---------------------------------- */

@media (min-width: 768px) and (max-width: 1199px) {
  #app { grid-template-columns: 76px 1fr; }
  .sidebar { padding: 14px 8px; align-items: center; gap: 12px; }
  .brand { font-size: 0; justify-content: center; padding: 0 0 6px; }
  .brand-dot { width: 14px; height: 14px; }
  .sidebar-nav { width: 100%; }
  .sidebar-nav button { font-size: 0; justify-content: center; padding: 10px 0; position: relative; width: 100%; }
  .sidebar-nav button svg { width: 22px; height: 22px; }
  .sidebar-nav .count { position: absolute; top: 2px; right: 10px; margin: 0; font-size: 10px; }
  .sidebar-footer { align-items: center; width: 100%; gap: 6px; }
  .sidebar-footer .user-row, .sidebar-footer #build-status { display: none; }
  .sidebar-footer .actions { flex-direction: column; width: 100%; }
  .sidebar-footer .actions button { width: 100%; }
  #conn-status { justify-content: center; }
  #conn-status .label { display: none; }
  #conn-status .dot { width: 9px; height: 9px; }
  .content { padding: 20px 22px 48px; }
}

/* Touch devices (<=1023): 터치 타깃 확대 + iOS 자동 확대 방지 */
@media (max-width: 1023px) {
  input, select, textarea { font-size: 16px; }
  button { min-height: 40px; }
  .segmented button, .chip, .table td button, .toast button { min-height: 34px; }
  .sidebar-footer button, .mobile-nav button { min-height: 0; }
}

/* Tablet: 표 가로 스크롤 */
@media (min-width: 768px) and (max-width: 1023px) {
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll table { min-width: 560px; white-space: nowrap; }
}

/* Mobile (<768): bottom tab bar + bottom sheet ----------------------------- */

.mobile-nav { display: none; }

.mobile-more-list { display: flex; flex-direction: column; gap: 6px; }
.mobile-more-item { justify-content: flex-start; text-align: left; width: 100%; padding: 12px 14px; background: var(--surface-2); }

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

  .sidebar {
    position: sticky; top: 0; height: auto; flex-direction: row; align-items: center;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px; gap: 10px;
    overflow: visible; border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { flex: none; }
  .sidebar-nav { display: none; }
  .sidebar-footer { margin: 0 0 0 auto; flex-direction: row; align-items: center; gap: 6px; }
  .sidebar-footer .user-row,
  .sidebar-footer #btn-help,
  .sidebar-footer #theme-toggle,
  .sidebar-footer #logout,
  .sidebar-footer #build-status { display: none; }

  .content { padding: 14px 12px calc(104px + env(safe-area-inset-bottom)); }

  .mobile-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: var(--bg-elevated);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--border);
  }
  .mobile-nav button {
    flex: 1; min-height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; background: transparent; color: var(--text-2); font-size: 10.5px; font-weight: 600; padding: 4px 0;
  }
  .mobile-nav button svg { width: 20px; height: 20px; }
  .mobile-nav button.active { color: var(--accent); }
  .mobile-nav button { position: relative; }
  .mobile-nav .count {
    position: absolute; top: 3px; left: calc(50% + 12px); margin: 0;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px; background: var(--surface-2); color: var(--text-2);
    font-size: 10px; display: inline-flex; align-items: center; justify-content: center;
  }

  /* iOS 자동 확대 방지 + 터치 타깃 확대 */
  input, select, textarea { font-size: 16px; }
  button { min-height: 40px; }
  .segmented button, .chip { min-height: 34px; }
  .sidebar-footer button, .mobile-nav button { min-height: 0; }

  /* 표는 가로 스크롤 */
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-scroll table { min-width: 520px; white-space: nowrap; }

  /* 상세 시트 헤더+탭 고정 */
  .detail-sticky {
    position: sticky; top: 0; z-index: 5;
    margin: -20px -20px 6px; padding: 12px 20px 0;
    background: var(--bg-elevated);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
  }
  .detail-sticky .segmented { margin: 8px 0 6px; }
  #device-detail { padding-bottom: calc(90px + env(safe-area-inset-bottom)); overscroll-behavior: contain; }

  /* 토스트는 하단 탭바 위로 */
  #toast-host { left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); transform: none; align-items: stretch; }
  .toast { text-align: center; border-radius: 14px; }

  /* 모달/팔레트 여유 */
  .modal { max-height: 86vh; overflow-y: auto; }
  .palette { max-height: 80vh; }
  .palette-backdrop { padding-top: 8vh; }

  .stat-card { padding: 12px 14px; }
  .stat-card .value { font-size: 22px; }
  .two-col { gap: 12px; }
  .card { padding: 16px; }
  .detail-header { margin: 0; }

  /* 폼은 세로로 쌓아 입력 폭을 넓힌다 */
  form.row { flex-direction: column; align-items: stretch; }
  form.row input, form.row select, form.row button, form.row label { width: 100%; }

  /* 목록에서는 위치 텍스트를 숨기고 배터리/태그만 표시 */
  .device-side .side-loc { display: none; }

  .actions { gap: 6px; }
  .login-card { padding: 20px; }
  .modal { padding: 18px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-scroll table { min-width: 480px; }
  .palette-list, .notification-panel { overscroll-behavior: contain; }
  #screen-stage { border-radius: 12px; }
}

#screen-frame.controllable { touch-action: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
