/* ==========================================================================
   turnstone server UI — page-specific styles
   Design tokens, reset, shared components live in /shared/base.css
   ========================================================================== */

/* ==========================================================================
   Header — server-specific elements
   ========================================================================== */
#model-name {
  font-size: 11px;
  color: var(--fg-dim);
  font-family: var(--font-display);
  letter-spacing: 0.02em;
}
#health-indicator {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 8px;
  margin-left: 8px;
  font-family: var(--font-mono);
  transition: opacity 0.3s ease, background 0.3s ease;
}
#health-indicator.health-ok {
  opacity: 0;
  pointer-events: none;
}
#health-indicator.health-degraded {
  background: var(--accent);
  color: var(--bg);
  opacity: 1;
}
.skip-permissions-warning {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--yellow);
  padding: 2px 8px;
  border: 1px solid var(--yellow);
  border-radius: var(--radius-sm);
  letter-spacing: 0.02em;
}

/* ==========================================================================
   Hamburger menu
   ========================================================================== */
#hamburger-wrap { position: relative; }
#hamburger-btn {
  background: none;
  border: 1px solid var(--border-strong);
  color: var(--fg);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
#hamburger-btn:hover { background: var(--bg-highlight); border-color: var(--accent-dim); }
#hamburger-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#hamburger-btn span { display: block; width: 14px; height: 2px; background: var(--fg); border-radius: 1px; }
#hamburger-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 40;
  overflow: hidden;
}
[data-theme="light"] #hamburger-menu { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); }
#hamburger-menu.open { display: block; }
.hmenu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--fg);
  font: inherit;
  font-family: var(--font-display);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background 0.1s;
}
.hmenu-item:hover { background: var(--bg-highlight); }
.hmenu-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.hmenu-item .hmenu-icon { width: 16px; text-align: center; font-size: 14px; opacity: 0.8; }
.hmenu-sep { height: 1px; background: var(--border-strong); margin: 4px 0; }
@media (max-width: 600px) {
  #hamburger-btn { width: 40px; height: 40px; }
  .hmenu-item { padding: 12px 14px; }
  .ws-tab .tab-close { opacity: 1; padding: 4px 6px; font-size: 16px; }
}

/* ==========================================================================
   Tab bar
   ========================================================================== */
#tab-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}
#tab-bar::-webkit-scrollbar { height: 3px; }
#tab-bar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.ws-tab {
  padding: 6px 10px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: none;
  color: var(--fg-dim);
  white-space: nowrap;
  user-select: none;
  position: relative;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.ws-tab:hover { background: var(--bg-highlight); color: var(--fg-bright); }
.ws-tab.active {
  background: var(--bg-highlight);
  color: var(--fg-bright);
  border-bottom: 2px solid var(--accent);
}

/* Tab state indicators — LED glow */
.ws-tab .tab-indicator { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ws-tab .tab-indicator[data-state="idle"] { background: var(--fg-dim); opacity: 0.3; }
.ws-tab .tab-indicator[data-state="thinking"] { background: var(--cyan); box-shadow: 0 0 6px var(--cyan-glow); animation: pulse 1.5s ease-in-out infinite; will-change: opacity; }
.ws-tab .tab-indicator[data-state="running"] { background: var(--green); border-radius: 2px; box-shadow: 0 0 6px var(--green-glow); animation: pulse 1s ease-in-out infinite; will-change: opacity; }
.ws-tab .tab-indicator[data-state="attention"] { background: var(--yellow); border-radius: 1px; transform: rotate(45deg); box-shadow: 0 0 6px var(--yellow-glow); animation: pulse 1s ease-in-out infinite; will-change: opacity; }
.ws-tab .tab-indicator[data-state="error"] { background: var(--red); box-shadow: 0 0 4px var(--red-glow); }

.ws-tab .tab-close {
  background: none;
  border: none;
  color: var(--fg-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.1s;
}
.ws-tab:hover .tab-close, .ws-tab:focus-within .tab-close, .ws-tab .tab-close:focus-visible { opacity: 1; }
.ws-tab .tab-close:hover { color: var(--red); }

#new-tab-btn {
  background: none;
  border: 1px dashed var(--border-strong);
  color: var(--fg-dim);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#new-tab-btn:hover { background: var(--bg-highlight); color: var(--accent); border-color: var(--accent); }

/* ==========================================================================
   Messages
   ========================================================================== */
#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg {
  padding: 10px 14px;
  border-radius: var(--radius);
  max-width: 95%;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg-user {
  background: var(--bg-highlight);
  border: 1px solid var(--border-strong);
  align-self: flex-end;
  color: var(--fg-bright);
}
.msg-assistant { align-self: flex-start; }
.msg-info { color: var(--cyan); font-size: 12px; padding: 4px 14px; white-space: pre-wrap; font-family: inherit; }
.msg-error { color: var(--red); font-size: 12px; padding: 4px 14px; }
.msg-tool {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  font-size: 12px;
  padding: 8px 12px;
  align-self: flex-start;
  max-width: 95%;
}
.msg-tool .tool-header { color: var(--yellow); font-weight: 600; margin-bottom: 4px; font-size: 11px; }
.msg-tool .tool-preview { color: var(--fg-dim); white-space: pre-wrap; font-size: 12px; max-height: 300px; overflow-y: auto; }

/* Streaming content */
.reasoning { color: var(--fg-dim); font-style: italic; }
.thinking-indicator { color: var(--fg-dim); font-size: 12px; padding: 6px 14px; }
.thinking-indicator::after { content: '...'; animation: dots 1.5s steps(3, end) infinite; }
@keyframes dots { 0% { content: '.'; } 33% { content: '..'; } 66% { content: '...'; } }

/* ==========================================================================
   Markdown styling
   ========================================================================== */
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 { color: var(--accent); margin: 8px 0 4px; font-family: var(--font-display); }
.msg-assistant h1 { font-size: 18px; }
.msg-assistant h2 { font-size: 16px; }
.msg-assistant h3 { font-size: 14px; }
.msg-assistant strong { color: var(--fg-bright); }
.msg-assistant em { color: var(--magenta); }
.msg-assistant code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  border: 1px solid var(--border);
}
.msg-assistant pre {
  background: var(--code-bg);
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
  border: 1px solid var(--border);
}
.msg-assistant pre code { background: none; padding: 0; border: none; }
.msg-assistant ul, .msg-assistant ol { margin: 4px 0 4px 20px; }
.msg-assistant li { margin: 2px 0; }
.msg-assistant a { color: var(--accent); text-decoration: underline; }
.msg-assistant blockquote { border-left: 3px solid var(--accent-dim); padding-left: 12px; color: var(--fg-dim); margin: 6px 0; }
.msg-assistant hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.msg-assistant p { margin: 4px 0; }

/* ==========================================================================
   Input area
   ========================================================================== */
#input-area {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-strong);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
#input-area textarea {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 200px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#input-area textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
#input-area button {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-family: var(--font-display);
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: filter 0.15s;
}
#input-area button:hover { filter: brightness(1.1); }
#input-area button:disabled { opacity: 0.35; cursor: not-allowed; filter: none; }

/* ==========================================================================
   Inline approval blocks
   ========================================================================== */
.approval-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  border-radius: var(--radius);
  padding: 0;
  align-self: flex-start;
  max-width: 95%;
  font-size: 12px;
}
.approval-block.approved { border-left-color: var(--green); }
.approval-block.denied { border-left-color: var(--red); }
.approval-tool { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.approval-tool:last-of-type { border-bottom: none; }
.approval-tool .tool-name { color: var(--yellow); font-weight: 600; font-size: 11px; margin-bottom: 3px; }
.approval-tool .tool-cmd { color: var(--fg-bright); white-space: pre-wrap; word-break: break-all; }
.approval-tool .tool-cmd .dollar { color: var(--green); }
.approval-tool .tool-diff { white-space: pre-wrap; font-size: 12px; margin-top: 4px; }
.approval-tool .tool-diff .diff-del { color: var(--red); }
.approval-tool .tool-diff .diff-add { color: var(--green); }
.approval-tool .tool-diff .diff-warn { color: var(--yellow); }
.approval-prompt { padding: 8px 12px; font-size: 12px; border-top: 1px solid var(--border); background: var(--bg-highlight); }
.approval-actions { display: flex; gap: 6px; margin-bottom: 6px; }
.approval-btn {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  color: var(--fg-bright);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.approval-btn:hover { background: var(--bg-highlight); }
.approval-btn .key {
  display: inline-block;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 4px;
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}
.btn-approve:hover { border-color: var(--green); color: var(--green); }
.btn-deny:hover { border-color: var(--red); color: var(--red); }
.btn-always:hover { border-color: var(--accent); color: var(--accent); }
.approval-feedback-input {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
}
.approval-feedback-input:focus { border-color: var(--accent); }
.approval-feedback-input::placeholder { color: var(--fg-dim); }
.approval-badge { padding: 6px 12px; font-size: 12px; font-weight: 600; border-top: 1px solid var(--border); }
.approval-badge.badge-approved { color: var(--green); }
.approval-badge.badge-denied { color: var(--red); }
.tool-output {
  padding: 8px 12px;
  background: var(--code-bg);
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--fg-dim);
  max-height: 300px;
  overflow-y: auto;
}
.tool-output-stream {
  border-left: 2px solid var(--accent);
  max-height: 400px;
  animation: stream-pulse 2s ease-in-out infinite;
}
@keyframes stream-pulse {
  0%, 100% { border-left-color: var(--accent); }
  50% { border-left-color: var(--accent-dim); }
}
.tool-output.collapsed { max-height: 150px; position: relative; }
.tool-output.collapsed::after {
  content: 'click to expand';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 6px;
  background: linear-gradient(transparent, var(--code-bg) 60%);
  color: var(--fg-dim);
  font-size: 10px;
  font-family: var(--font-display);
  cursor: pointer;
  letter-spacing: 0.03em;
}

/* ==========================================================================
   Plan review dialog
   ========================================================================== */
#plan-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
#plan-overlay.active { display: flex; }
#plan-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.5);
  position: relative;
}
#plan-dialog::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 20%;
  right: 20%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  border-radius: 1px;
}
#plan-dialog h3 {
  font-family: var(--font-display);
  color: var(--accent);
  margin-bottom: 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
#plan-content {
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--fg-bright);
  margin-bottom: 16px;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--code-bg);
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
#plan-feedback {
  width: 100%;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13px;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 0.15s;
}
#plan-feedback:focus { border-color: var(--accent); }
#plan-buttons { display: flex; gap: 8px; justify-content: flex-end; }
#plan-buttons button {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: filter 0.15s;
}
#plan-buttons button:hover { filter: brightness(1.1); }
#btn-plan-approve { background: var(--green); color: var(--bg); }
#btn-plan-reject { background: var(--red); color: var(--bg); }

/* ==========================================================================
   Focus indicators — server-specific overrides
   ========================================================================== */
#input-area textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.approval-btn:focus-visible { outline-offset: 1px; }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty-state {
  color: var(--fg-dim);
  text-align: center;
  padding: 48px 16px;
  font-family: var(--font-display);
  font-size: 13px;
  font-style: italic;
  opacity: 0.7;
}

/* ==========================================================================
   Dashboard overlay
   ========================================================================== */
.dashboard-overlay { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 50; overflow-y: auto; }
.dashboard-overlay.active { display: flex; justify-content: center; align-items: flex-start; }
.dashboard-content { width: 100%; max-width: 960px; padding: 32px 20px 24px; }
.dashboard-input-row { display: flex; gap: 8px; margin-bottom: 24px; }
.dashboard-input {
  flex: 1;
  background: var(--bg-surface);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 12px 16px;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.dashboard-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.dashboard-input::placeholder { color: var(--fg-dim); }
.dashboard-new-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 12px 20px;
  font: inherit;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.02em;
  transition: filter 0.15s;
}
.dashboard-new-btn:hover { filter: brightness(1.1); }
.dashboard-new-btn:disabled { opacity: 0.35; cursor: not-allowed; filter: none; }
.dashboard-section { margin-bottom: 24px; }
.dashboard-section-title {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 12px;
}
.dashboard-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.dashboard-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dashboard-card:hover { border-color: var(--accent); background: var(--bg-highlight); }
.dashboard-card:active { background: var(--bg-highlight); border-color: var(--accent); }
.dashboard-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dashboard-card .card-title { font-size: 13px; color: var(--fg-bright); font-weight: 500; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dashboard-card .card-meta { font-size: 11px; color: var(--fg-dim); }

/* Server dashboard row — clickable */
.dash-row { cursor: pointer; }

/* Dashboard footer */
.dash-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--code-bg);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 11px;
  margin-bottom: 24px;
}
.dash-footer-nodes { color: var(--fg-dim); display: flex; align-items: center; gap: 6px; }
.dash-footer-node-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); display: inline-block; flex-shrink: 0; box-shadow: 0 0 4px var(--green-glow); }
.dash-footer-stats { color: var(--fg-dim); font-variant-numeric: tabular-nums; }

/* Dashboard responsive */
@media (max-width: 700px) {
  :root { --dash-grid: 68px 110px 1fr 56px 44px; }
  .dash-col-model, .dash-cell-model, .dash-col-node, .dash-cell-node { display: none; }
  .dash-row-sub { padding-left: 76px; }
}
@media (max-width: 600px) {
  .dashboard-input-row { flex-direction: column; }
  .dashboard-new-btn { width: 100%; }
}
@media (max-width: 480px) {
  .dashboard-content { padding: 24px 12px 16px; }
  .dashboard-cards { grid-template-columns: 1fr; }
  :root { --dash-grid: 50px 1fr 50px; }
  .dash-col-model, .dash-cell-model, .dash-col-node, .dash-cell-node, .dash-col-task, .dash-cell-task, .dash-col-ctx, .dash-cell-ctx { display: none; }
  .dash-row-sub { padding-left: 66px; }
  .tool-output, .tool-output-stream { max-height: 200px; }
}

/* ==========================================================================
   Reduced motion — page-specific
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .ws-tab .tab-indicator[data-state="thinking"],
  .ws-tab .tab-indicator[data-state="running"],
  .ws-tab .tab-indicator[data-state="attention"] { animation: none; opacity: 1; }
  .tool-output-stream { animation: none; border-left-color: var(--accent); }
  .thinking-indicator::after { animation: none; content: '...'; }
  .ws-tab, .ws-tab .tab-close, #new-tab-btn,
  .hmenu-item, .dashboard-card,
  .approval-btn, .approval-feedback-input,
  #plan-buttons button, #input-area button,
  .dashboard-new-btn, .dashboard-input,
  #health-indicator, #hamburger-btn { transition: none; }
}
