:root {
  --bg: #170f18;
  --panel: #3a2532;
  --panel-2: #4b3040;
  --ink: #fff6f8;
  --muted: #f0d5d8;
  --hot: #ffa5cb;
  --gold: #ffd79d;
  --ok: #ffd79d;
  --warn: #ffd5a8;
  --line: #f7cfa3;
  --font-scale: 1;
  --terminal-font-scale: 1.2;
  --layout-sidebar-width: 220px;
  --layout-context-width: 320px;
  --dock-min-height: 300px;
  --dock-pane-min-height: 210px;
  --dock-col-terminal: 1.1fr;
  --dock-col-device: 0.35fr;
  --dock-col-phone: 1.66fr;
  --dock-col-tablet: 1.66fr;
  --dock-col-shortcuts: 0.65fr;
  --layer-1: #ffffff14;
  --layer-2: #ffffff22;
  --layer-3: #ffffff2f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans", system-ui, sans-serif;
  font-size: calc(16px * var(--font-scale));
  background:
    radial-gradient(1200px 520px at 10% -20%, #d48ba9 0%, transparent 55%),
    radial-gradient(1200px 520px at 90% -15%, #ebc080 0%, transparent 55%),
    radial-gradient(1800px 900px at 50% 20%, #7d4a62 0%, #2f1d2d 70%),
    var(--bg);
  color: var(--ink);
}

body.high-contrast {
  --bg: #000;
  --panel: #111;
  --panel-2: #1a1a1a;
  --ink: #fff;
  --muted: #ddd;
  --line: #fff;
  --hot: #fff;
  --gold: #fff;
  --ok: #fff;
  --warn: #fff;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  overflow: hidden;
}

.app::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(2px 2px at 12% 20%, #fff7 0, transparent 70%),
    radial-gradient(2px 2px at 30% 8%, #fff6 0, transparent 70%),
    radial-gradient(2px 2px at 44% 36%, #fff7 0, transparent 70%),
    radial-gradient(2px 2px at 63% 22%, #fff6 0, transparent 70%),
    radial-gradient(2px 2px at 76% 15%, #fff8 0, transparent 70%),
    radial-gradient(2px 2px at 88% 32%, #fff6 0, transparent 70%);
  opacity: 0.8;
}

.topbar {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: 1.2fr 1fr auto;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #6f455f77, #9c7e5a77);
  box-shadow: 0 8px 28px #ffdfb44d, inset 0 -1px 0 #fff3;
  backdrop-filter: blur(6px);
}

.brand h1 { font-size: 1rem; margin: 0; letter-spacing: 0.05em; }
.brand p { margin: 0.3rem 0 0; color: var(--muted); }
.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 0.6rem;
  border: 1px solid var(--line);
  box-shadow: 0 0 18px #ffd79d88;
  margin-bottom: 0.45rem;
  background: #fff;
}

.top-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.top-controls input { min-width: 300px; flex: 1; }
.top-link-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.5rem;
  max-width: 100%;
}
.top-link-btn:hover { filter: brightness(1.08); }
.top-link-btn:focus {
  outline: 3px solid #ffd59f;
  outline-offset: 2px;
}
.status-strip { display: flex; flex-direction: column; gap: 0.4rem; }
.status-strip span {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.3rem 0.6rem;
  background: #ffffff1a;
  box-shadow: inset 0 0 12px #ffd79d55;
}

.active-work-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #6a435a6e, #3c28376e);
  backdrop-filter: blur(4px);
  box-shadow: inset 0 1px 0 #fff3, inset 0 -1px 0 #fff2;
}

.work-chip {
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  padding: 0.45rem 0.55rem;
  background: linear-gradient(140deg, #fff2f833, #ffecc933);
  box-shadow: 0 0 18px #ffd8a35a;
  position: relative;
}

.work-chip h4 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.work-chip p {
  margin: 0.25rem 0 0;
  font-weight: 600;
}

.work-chip.active-chip {
  background: linear-gradient(140deg, #fff7f955, #ffeccf55);
  box-shadow: 0 0 24px #ffd8ab99;
}

.layout {
  display: grid;
  grid-template-columns: var(--layout-sidebar-width) minmax(0, 1fr) var(--layout-context-width);
  min-height: 0;
  width: min(1880px, 100%);
  margin: 0 auto;
}
body.large-layout .layout {
  grid-template-columns: 280px minmax(0, 1fr) 380px;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 0.8rem;
  display: grid;
  gap: 0.45rem;
  background: linear-gradient(180deg, #492f4488, #2e1f2f88);
  backdrop-filter: blur(5px);
  box-shadow: inset -1px 0 0 #fff2;
}

.nav-btn {
  text-align: left;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.55rem;
}
.nav-btn.active, .nav-btn:hover {
  background: linear-gradient(120deg, #f9cdb555, #ffb9d555);
  box-shadow: 0 0 20px #ffd79d80;
}

.main { padding: 1rem; overflow: auto; min-width: 0; }
.main > * {
  width: min(1480px, 100%);
  margin-left: auto;
  margin-right: auto;
}
.context {
  padding: 1rem;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, #4a304477, #2e1f2d77);
  backdrop-filter: blur(5px);
  overflow: auto;
  min-width: 0;
  box-shadow: inset 1px 0 0 #fff2;
}

.dock {
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #5f3d5375, #281b2b85);
  padding: 0.7rem;
  box-shadow: 0 -16px 40px #f2c86b44, inset 0 1px 0 #fff4;
  backdrop-filter: blur(6px);
  min-height: var(--dock-min-height);
  overflow-x: auto;
}

.legal-footer {
  border-top: 1px solid var(--line);
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: linear-gradient(180deg, #2e1f2f99, #1f151f99);
}

body.dashboard-focus .active-work-strip,
body.dashboard-focus .sidebar,
body.dashboard-focus .context,
body.dashboard-focus .dock {
  display: none;
}

body.dashboard-focus .layout {
  grid-template-columns: 1fr;
  width: min(2000px, 100%);
}

body.dashboard-focus .main {
  padding-top: 0.8rem;
}

body.dashboard-focus .main > * {
  width: min(1900px, 100%);
}
.dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.terminal-tabs { display: flex; gap: 0.45rem; flex-wrap: wrap; margin: 0.6rem 0; }
.terminal-tab-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.terminal-tab {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 0.45rem;
  padding: 0.25rem 0.5rem;
}
.terminal-tab.active { background: #6f4e5d; }
.terminal-attention-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1rem;
  height: 1rem;
  margin-left: 0.35rem;
  border-radius: 999px;
  border: 1px solid #ffb3b3;
  background: #c62828;
  color: #fff;
  font-weight: 800;
  font-size: 0.75rem;
  line-height: 1;
}
.terminal-tab-close {
  border: 1px solid var(--line);
  background: #ffffff18;
  color: var(--ink);
  border-radius: 0.4rem;
  padding: 0.15rem 0.4rem;
  line-height: 1;
}
.terminal-output {
  min-height: 130px;
  max-height: 240px;
  overflow-y: auto;
  overflow-x: auto;
  background: linear-gradient(180deg, #2a1f2a, #1a151c);
  border: 1px solid var(--line);
  padding: 0.6rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: calc(0.95rem * var(--terminal-font-scale));
  white-space: pre;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.dock-grid {
  display: grid;
  grid-template-columns:
    minmax(0, var(--dock-col-terminal))
    minmax(0, var(--dock-col-device))
    minmax(0, var(--dock-col-phone))
    minmax(0, var(--dock-col-tablet))
    minmax(0, var(--dock-col-shortcuts));
  gap: 0.7rem;
  min-width: 0;
}

.dock-grid > * {
  min-width: 0;
}

.dock-pane {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: linear-gradient(160deg, #ffe9d420, #ffd3ea1f);
  padding: 0.55rem;
  box-shadow: inset 0 0 18px #fff5;
  min-height: var(--dock-pane-min-height);
  min-width: 0;
}

.dock-pane h3 {
  margin: 0 0 0.45rem;
  font-size: 0.92rem;
  color: var(--gold);
}

.dock-shortcuts {
  display: grid;
  gap: 0.45rem;
}

.dock-shortcuts button {
  text-align: left;
}

#dockSessionFeedPanel,
#dockLogsPanel {
  margin-top: 0.6rem;
}

#dockSessionFeedPanel summary,
#dockLogsPanel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 0.4rem;
}

#deviceBridgePane details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--gold);
  margin-top: 0.55rem;
}

#deviceBridgePane .terminal-output {
  min-height: 80px;
  max-height: 140px;
}

.file-tree-line {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0.15rem 0;
  padding: 0.2rem 0.3rem;
}

.file-tree-line.file-dir {
  font-weight: 700;
}

.terminal-form {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: minmax(130px, 180px) minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
}

.terminal-form > * {
  min-width: 0;
}

button, input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.5rem;
  max-width: 100%;
}
button:hover { filter: brightness(1.08); }
button:focus, input:focus, select:focus, textarea:focus {
  outline: 3px solid #ffd59f;
  outline-offset: 2px;
}

.grid { display: grid; gap: 0.8rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background:
    radial-gradient(500px 140px at 5% -20%, #ffd0e666 0%, transparent 60%),
    radial-gradient(420px 140px at 95% -25%, #ffe0b266 0%, transparent 60%),
    linear-gradient(160deg, #ffffff22, #ffffff15);
  padding: 0.8rem;
  box-shadow: 0 0 22px #ffd8ab55;
  backdrop-filter: blur(3px);
  position: relative;
}
.card h3 { margin: 0 0 0.4rem; }
.muted { color: var(--muted); }
.kpi { font-size: 1.5rem; font-weight: 700; color: var(--gold); }

.hero-card {
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  padding: 1rem;
  background:
    radial-gradient(900px 240px at 15% -40%, #ffd0e67a, transparent 60%),
    radial-gradient(900px 280px at 85% -50%, #ffe5b073, transparent 60%),
    linear-gradient(120deg, #ffffff22, #ffffff14);
  box-shadow: 0 0 30px #ffe7b580;
}

.hero-card h2 {
  margin: 0;
}

.hero-card p {
  margin: 0.35rem 0 0;
  color: #efe9f6;
}
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 0.45rem; text-align: left; }
th, td { overflow-wrap: anywhere; word-break: break-word; }

body.terminal-wrap .terminal-output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.badge {
  display: inline-block;
  padding: 0.2rem 0.45rem;
  border-radius: 0.45rem;
  border: 1px solid var(--line);
  background: #633f4a;
}

.section-title {
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.45rem;
}

.active-row {
  background: linear-gradient(90deg, #fff7f733, #ffe6b633);
  box-shadow: inset 0 0 0 1px #ffd9ae;
}

.project-active-marker {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.08rem 0.35rem;
  border-radius: 999px;
  border: 1px solid #ffd9ae;
  background: #fff2;
  font-size: 0.75rem;
  color: var(--gold);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: #000;
  color: #fff;
  padding: 0.4rem 0.6rem;
  z-index: 1000;
}
.skip-link:focus {
  left: 12px;
}

.session-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.qr-preview-card {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.75rem;
  background: linear-gradient(160deg, #ffffff20, #ffffff12);
  box-shadow: inset 0 0 0 1px #ffd7b733;
}

.qr-preview-head {
  font-size: 0.88rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.45rem;
}

.qr-preview-image {
  width: min(280px, 100%);
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: #fff;
}

.qr-barcode-image {
  width: min(440px, 100%);
  height: auto;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  background: #fff;
}

.qr-camera-wrap {
  margin-top: 0.55rem;
  border: 1px dashed var(--line);
  border-radius: 0.6rem;
  padding: 0.5rem;
  background: #ffffff10;
}

.qr-camera-wrap video {
  width: 100%;
  max-height: 260px;
  border-radius: 0.45rem;
  border: 1px solid var(--line);
  background: #000;
}

.qr-camera-wrap.active {
  box-shadow: 0 0 20px #ffd79d77;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 1fr; }
  .context { display: none; }
  .active-work-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dock-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; padding: 0.7rem; }
  .brand-logo { width: 46px; height: 46px; }
  .status-strip { flex-direction: row; flex-wrap: wrap; }
  .top-controls input { min-width: 100%; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    padding: 0.6rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar .nav-btn {
    flex: 0 0 auto;
    min-width: 132px;
    text-align: center;
  }
  .main { padding: 0.6rem; }
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
  .card { padding: 0.65rem; }
  .table-wrap table { min-width: 640px; }
  .terminal-form { grid-template-columns: 1fr; }
  .session-split { grid-template-columns: 1fr; }
  .active-work-strip { grid-template-columns: 1fr 1fr; }
  .dock-grid { grid-template-columns: 1fr; }
  .terminal-output { max-height: 180px; }
  .dock { padding: 0.55rem; min-height: 220px; }
  .emma-widget {
    right: 8px;
    left: 8px;
    bottom: 8px;
    width: auto;
    max-width: none;
    max-height: 72vh;
  }
  .emma-voice-row { grid-template-columns: 1fr; }
  .emma-image-reader-row { grid-template-columns: 1fr; }
  .emma-image-controls { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .top-controls { gap: 0.35rem; }
  .top-controls button, .top-controls select, .top-controls .top-link-btn { width: 100%; }
  .active-work-strip { grid-template-columns: 1fr; }
  .work-chip { padding: 0.4rem 0.45rem; }
  .dock-header { flex-direction: column; align-items: stretch; gap: 0.45rem; }
  .dock-header > div { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35rem; }
  .dock-header > div label { grid-column: 1 / -1; }
  .emma-widget-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .emma-widget-head { align-items: start; }
}

.read-aloud-menu {
  position: fixed;
  z-index: 2000;
  min-width: 180px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(12, 15, 26, 0.96);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
}

.read-aloud-menu button {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.read-aloud-menu button:hover {
  filter: brightness(1.12);
}

.emma-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 360px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  padding: 0.7rem;
  background: linear-gradient(160deg, #2e1f31ef, #1b1623f0);
  box-shadow: 0 10px 28px #00000066;
  z-index: 900;
}

.emma-widget.always-on-top {
  z-index: 2200;
}

.emma-widget-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(160deg, #2e1f31ef, #1b1623f0);
  padding-bottom: 0.35rem;
}

.emma-widget-actions {
  display: inline-flex;
  gap: 0.4rem;
}

.emma-command-form {
  margin-top: 0.5rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem;
}

.emma-command-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 3.2rem;
}

.emma-command-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.emma-conversation {
  margin-top: 0.45rem;
}

.emma-conversation h4 {
  margin: 0 0 0.35rem;
}

.emma-conversation-log {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #ffffff10;
  padding: 0.45rem;
  display: grid;
  gap: 0.35rem;
  max-height: 150px;
  overflow: auto;
  font-size: 0.85rem;
}

.emma-chat-msg {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.35rem 0.45rem;
}

.emma-chat-msg.user {
  background: #ffffff0f;
}

.emma-chat-msg.assistant {
  background: #9fd6ff1a;
}

.emma-chat-role {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.emma-widget-controls {
  margin-top: 0.5rem;
  display: grid;
  gap: 0.35rem;
}

.emma-voice-row {
  margin-top: 0.5rem;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 0.5rem;
}

.emma-jobs-panel {
  margin-top: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: #ffffff0e;
  padding: 0.45rem;
  max-height: 170px;
  overflow: auto;
  font-size: 0.88rem;
}

.emma-image-reader {
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.55rem;
  background: #ffffff10;
}

.emma-image-reader h4 {
  margin: 0 0 0.4rem;
}

.emma-image-reader-row {
  margin-top: 0.4rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.emma-image-controls {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.45rem;
}

.emma-image-controls button {
  min-height: 2.3rem;
  font-weight: 700;
}

body.emma-widget-hidden .emma-widget {
  display: none;
}

.emma-launcher-btn {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2100;
  border-radius: 999px;
  padding: 0.55rem 0.85rem;
  box-shadow: 0 8px 22px #00000066;
}

body:not(.emma-widget-hidden) .emma-launcher-btn {
  display: none;
}

body.emma-widget-compact .emma-widget {
  width: 300px;
}

body.emma-widget-compact .emma-jobs-panel {
  max-height: 90px;
}

.emma-widget.minimized {
  width: 280px;
  max-height: unset;
  overflow: hidden;
}

.emma-widget.minimized > :not(.emma-widget-head) {
  display: none;
}
