:root {
  --bg: #202b33;
  --panel: #263540;
  --panel2: #2d3d49;
  --panel3: #172129;
  --border: #3b4c58;
  --text: #eef6f8;
  --muted: #a7b5b5;
  --accent: #f8f000;
  --cyan: #00f8fa;
  --success: #38d16a;
  --danger: #fa1e1e;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  --topbar-h: 56px;
  --menu-z: 9999;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  background-size: contain;
  color: var(--text);
  overflow: hidden;
}

body {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  height: 100dvh;
  padding: 16px;
}

.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  height: 100%;
  min-height: 0;
}

.sidebar,
.main {
  background: rgba(38, 53, 64, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
  overflow: hidden;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.section:last-child {
  border-bottom: 0;
}

.clients-section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  font-weight: 700;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 14px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #777;
  flex: 0 0 auto;
}

.dot.ok {
  background: var(--success);
}

.dot.warn {
  background: var(--accent);
}

.dot.err {
  background: var(--danger);
}

.stack {
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  gap: 10px;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(248, 240, 0, 0.18);
}

button {
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.15s ease;
  min-height: 40px;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateY(-1px);
}

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

.primary {
  background: var(--accent);
  color: #202b33;
  border-color: #d9d100;
  font-weight: 700;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(248, 240, 0, 0.14);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clients {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
  display: grid;
  gap: 10px;
  align-content: start;
  grid-auto-rows: min-content;
}

.client-card {
  border: 1px solid var(--border);
  background: rgba(45, 61, 73, 0.9);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: 0.15s ease;
  height: 96px;
  min-height: 96px;
  max-height: 96px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.client-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.client-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(248, 240, 0, 0.3) inset;
}

.client-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1em;
  height: 1em;
  min-height: 1em;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--accent);
}

.client-meta {
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 2px;
  align-content: start;
}

.client-meta div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2em;
  min-height: 1.2em;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  overflow: hidden;
}

.main-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.toolbar button {
  flex: 0 0 auto;
  min-width: auto;
  white-space: nowrap;
}

.viewer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.output-panel,
.logs-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.output-panel {
  border-right: 1px solid var(--border);
  min-width: 0;
}

.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(23, 33, 41, 0.35);
  min-width: 0;
}

.panel-header .muted {
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.header-row {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.log-filter {
  width: auto;
  min-width: 140px;
  max-width: 180px;
  padding: 6px 10px;
  font-size: 12px;
  min-height: 34px;
}

.output-wrap {
  min-height: 0;
  padding: 16px;
  overflow: auto;
  flex: 1 1 auto;
  min-width: 0;
}

.output {
  background: var(--panel3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  min-height: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: auto;
  color: var(--text);
}

.output pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  background: transparent !important;
}

.output code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: transparent !important;
  padding: 0 !important;
}

.output-grid {
  display: grid;
  gap: 10px;
  margin: 0 0 12px;
}

.output-grid:last-child {
  margin-bottom: 0;
}

.output-card {
  background: rgba(45, 61, 73, 0.9);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.output-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.output-value {
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  overflow-wrap: anywhere;
}

.output-inline-meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

.output-inline-time {
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.output-inline-secondary {
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.output-model {
  margin-top: 10px;
}

.raw-details {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(23, 33, 41, 0.45);
}

.raw-details summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
}

.raw-details summary::-webkit-details-marker {
  display: none;
}

.raw-details summary::before {
  content: ">";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.15s ease;
}

.raw-details[open] summary::before {
  transform: rotate(90deg);
}

.raw-details-body {
  padding: 0 10px 10px;
}

.output-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}

.output-table th,
.output-table td {
  border: 1px solid var(--border);
  text-align: left;
  padding: 6px 8px;
  font-size: 12px;
  vertical-align: top;
}

.output-table th {
  background: rgba(38, 53, 64, 0.9);
  color: var(--muted);
  font-weight: 600;
}

.output-table td {
  background: rgba(23, 33, 41, 0.55);
  overflow-wrap: anywhere;
}

.output-table tr.device-row-disabled td {
  text-decoration: line-through;
  opacity: 0.65;
}

.plain-text {
  color: var(--cyan);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
  background: rgba(38, 53, 64, 0.7);
}

.pill-emphasis {
  color: var(--accent);
  border-color: rgba(248, 240, 0, 0.45);
}

.logs {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  display: grid;
  gap: 8px;
  align-content: start;
  grid-auto-rows: min-content;
  background: rgba(23, 33, 41, 0.15);
  flex: 1 1 auto;
}

.log-line {
  border: 1px solid var(--border);
  background: rgba(23, 33, 41, 0.85);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: 0.15s ease;
  height: 86px;
  min-height: 86px;
  max-height: 86px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.log-line:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.log-line.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(248, 240, 0, 0.3) inset;
  background: rgba(45, 61, 73, 0.95);
}

.log-line.command-log {
  border-style: dashed;
}

.log-meta {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
  line-height: 1em;
  min-height: 1em;
  align-items: center;
}

.log-meta-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.log-preview {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.2em;
}

.floating-menu {
  position: fixed;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 20px));
  background: rgba(38, 53, 64, 0.98);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: none;
  z-index: var(--menu-z);
  gap: 6px;
}

.floating-menu.open {
  display: grid;
}

.floating-menu button {
  width: 100%;
  text-align: left;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.mobile-topbar,
.mobile-tabs,
.mobile-sheet-backdrop,
.mobile-sheet {
  display: none;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 10px;
  }

  .app {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .sidebar {
    position: fixed;
    top: 10px;
    left: 10px;
    bottom: 10px;
    width: min(360px, calc(100vw - 20px));
    z-index: 40;
    transform: translateX(-110%);
    transition: transform 0.22s ease;
    border-radius: 16px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 30;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }

  .mobile-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .main {
    grid-template-rows: var(--topbar-h) 1fr;
    min-height: 0;
    border-radius: 16px;
  }

  .main-scroll {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-rows: auto 1fr auto;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(23, 33, 41, 0.35);
  }

  .mobile-topbar-title {
    min-width: 0;
  }

  .mobile-topbar-title .title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
  }

  .mobile-topbar-title .subtitle {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-menu-btn {
    flex: 0 0 auto;
    min-width: 44px;
    height: 40px;
    padding: 0 12px;
  }

  .main-scroll > .section:first-of-type {
    padding: 12px;
  }

  .viewer-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    min-height: 0;
  }

  .output-panel {
    border-right: 0;
  }

  .logs-panel {
    display: none;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--border);
    background: rgba(23, 33, 41, 0.3);
  }

  .mobile-tab {
    min-height: 42px;
  }

  .mobile-tab.active {
    background: var(--accent);
    color: #202b33;
    border-color: #d9d100;
    font-weight: 700;
  }

  .panel-header {
    padding: 12px;
  }

  .output-wrap {
    padding: 12px;
  }

  .output {
    min-height: 280px;
    height: auto;
  }

  .mobile-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: 25%;
    z-index: 45;
    background: rgba(38, 53, 64, 0.98);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transform: translateY(110%);
    transition: transform 0.22s ease;
  }

  .mobile-sheet.open {
    transform: translateY(0);
  }

  .mobile-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(23, 33, 41, 0.35);
  }

  .mobile-sheet-title {
    font-size: 14px;
    font-weight: 700;
  }

  .mobile-sheet-body {
    min-height: 0;
    flex: 1 1 auto;
    overflow: auto;
    padding: 12px;
    background: rgba(23, 33, 41, 0.15);
  }

  .mobile-sheet .logs {
    padding: 0;
    background: transparent;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 0;
  }

  .main {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-top: 0;
  }

  .sidebar {
    top: 0;
    left: 0;
    bottom: 0;
    width: min(360px, 100vw);
    border-radius: 0 16px 16px 0;
    border-left: 0;
  }

  .mobile-sheet {
    left: 0;
    right: 0;
    bottom: 0;
    top: 18%;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .client-card {
    height: 104px;
    min-height: 104px;
    max-height: 104px;
  }

  .log-line {
    height: 90px;
    min-height: 90px;
    max-height: 90px;
  }
}
