/* Will's World Browser — palette mirrors voice-webapp so this lifts cleanly into the PWA later. */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f3f1ee;
  --surface: #ffffff;
  --border: #b0b0b0;
  --border-soft: #d0d0d0;
  --text: #333333;
  --text-soft: #666666;
  --text-faint: #999999;
  --accent: #F0686C;
  --accent-dark: #d8585c;
  --cyan: #a7e2e3;
  --cyan-border: #79b0b2;
  --green: #ddebc6;
  --green-border: #acb996;
  --warn: #fde68a;
  --warn-bg: #fef3c7;
  --error: #c0392b;
  --success: #16a34a;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

.header {
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 10;
}

/* In the tablet cockpit, match the voice pane's header height (60px) so the
   bottom borders of both headers line up. Top padding stays 12px to keep the
   title at the same Y as the voice title; extra goes to bottom padding. */
html.tablet-embed .header {
  padding: 12px 16px 26px;
}
html.tablet-embed .header h1 {
  font-size: 19px;
  transform: translateY(6px);
}
html.tablet-embed .header-btn {
  height: 23px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  transform: translateY(6px);
}
html.tablet-embed .header-btn.icon-btn {
  height: 23px;
  width: 23px;
  padding: 0;
  transform: translateY(6px);
}
html.tablet-embed .header-btn.icon-btn svg {
  width: 14px;
  height: 14px;
}
html.tablet-embed .ticker-spacer {
  display: block;
  height: 22px;
  background: #fcfcfc;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: inset 0 3px 5px rgba(0,0,0,0.075), 0 2px 4px rgba(0,0,0,0.08);
  position: relative;
  z-index: 5;
}
.ticker-spacer { display: none; }

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header h1 { font-size: 17px; font-weight: 600; color: var(--accent); }

.header-btn {
  background: transparent;
  border: 1px solid var(--border-soft);
  color: var(--text-soft);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.header-btn:hover { color: var(--accent); border-color: var(--accent); }
.header-btn.hidden { display: none; }
.header-btn.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  color: var(--accent);
  border-color: var(--accent);
}
.header-btn.icon-btn.hidden { display: none; }
.header-btn.icon-btn:focus { outline: none; }
@media (hover: hover) {
  .header-btn.icon-btn:hover { color: var(--accent-dark); border-color: var(--accent-dark); }
}
.header-btn.icon-btn svg { width: 16px; height: 16px; display: block; }
.header-btn.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status { font-size: 12px; color: var(--text-faint); }
.status.error { color: var(--error); }
.status.ok { color: var(--success); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 2fr 1fr;
  min-height: 0;
}

.graph-pane {
  background: var(--bg);
  border-right: 1px solid var(--border);
  position: relative;
  min-height: 0;
}

.data-pane {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.data-empty {
  padding: 32px;
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  margin: auto;
}

.data-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}
.data-header .source-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  font-weight: 600;
}
.data-header .source-target {
  font-size: 13px;
  color: var(--text-soft);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  word-break: break-all;
}

.data-body {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
  min-height: 0;
}

.data-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 500;
}
.btn:hover { background: var(--accent-dark); }
.btn:disabled { background: var(--border-soft); cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--text-soft); border: 1px solid var(--border-soft); }
.btn.secondary:hover { color: var(--accent); border-color: var(--accent); }

.value-textarea {
  width: 100%;
  min-height: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  resize: none;
  outline: none;
}
.value-textarea:focus { border-color: var(--accent); }

.prop-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.prop-table th, .prop-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.prop-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-soft);
  width: 30%;
  white-space: nowrap;
}
.prop-table td input {
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.prop-table td input:focus { border-color: var(--accent); }
.prop-table td input:read-only { background: var(--bg); color: var(--text-faint); }

.node-meta {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-soft);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
.node-meta-row { display: flex; gap: 6px; margin-bottom: 2px; }
.node-meta-key { color: var(--text-faint); }

.empty-data {
  padding: 24px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
  background: var(--bg);
  border: 1px dashed var(--border-soft);
  border-radius: 8px;
}

.tts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  color: var(--text-soft);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  margin-left: auto;
  transition: all 0.15s ease;
}
.tts-btn:hover { color: var(--accent); border-color: var(--accent); }
.tts-btn.loading { color: #d97706; border-color: #d97706; }
.tts-btn.playing { color: #ef4444; border-color: #ef4444; }
.tts-btn svg { width: 14px; height: 14px; }

.view-toggle {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  overflow: hidden;
}
.view-toggle button {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text-soft);
  cursor: pointer;
}
.view-toggle button.active {
  background: var(--accent);
  color: white;
}

.markdown-body {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  word-wrap: break-word;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  font-weight: 600;
  margin: 18px 0 8px;
  line-height: 1.25;
  color: var(--text);
}
.markdown-body h1 { font-size: 22px; border-bottom: 1px solid var(--border-soft); padding-bottom: 6px; }
.markdown-body h2 { font-size: 18px; border-bottom: 1px solid var(--border-soft); padding-bottom: 4px; }
.markdown-body h3 { font-size: 16px; }
.markdown-body h4 { font-size: 14px; }
.markdown-body p { margin: 8px 0; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body strong { font-weight: 600; }
.markdown-body code {
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.92em;
}
.markdown-body pre {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.markdown-body pre code {
  background: transparent;
  padding: 0;
  font-size: 12px;
  line-height: 1.4;
}
.markdown-body ul, .markdown-body ol { padding-left: 24px; margin: 6px 0; }
.markdown-body li { margin: 3px 0; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-soft);
  background: var(--bg);
  border-radius: 0 6px 6px 0;
}
.markdown-body hr { border: none; border-top: 1px solid var(--border-soft); margin: 16px 0; }
.markdown-body table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border-soft);
  padding: 5px 8px;
}
.markdown-body th { background: var(--bg); font-weight: 600; }
.markdown-body img { max-width: 100%; }

.mobile-close {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 26px;
  font-weight: 600;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 50;
  font-family: inherit;
  padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.mobile-close:hover, .mobile-close:active { background: var(--accent-dark); }

.mobile-back {
  display: none;
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  height: 48px;
  border-radius: 12px;
  background: var(--accent);
  border: none;
  color: white;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  z-index: 110;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}
.mobile-back:hover, .mobile-back:active { background: var(--accent-dark); }

.panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* --- Live-stats overlay (per-AI heartbeat card on identity graphs) ---- */
.livestats {
  position: absolute;
  top: 110px;
  left: 12px;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
  min-width: 220px;
  max-width: 280px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.livestats:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
}
.livestats.hidden { display: none; }

.livestats-name {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-soft);
}
.livestats-grid {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 2px 8px;
}
.livestats-grid dt {
  color: var(--text-faint);
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.livestats-grid dd {
  color: var(--text);
  font-size: 12px;
  text-align: left;
  word-break: break-all;
}

.livestats-cache.warm    { color: #16a34a; }
.livestats-cache.cooling { color: #d97706; }
.livestats-cache.cold    { color: var(--text-faint); }

.livestats-service.up    { color: #16a34a; }
.livestats-service.down  { color: #c0392b; }
.livestats-service.stuck { color: #d97706; }

@media (max-width: 1024px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .graph-pane {
    border-right: none;
  }
  .data-pane {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    border-left: none;
  }
  .layout.panel-open .data-pane {
    transform: translateX(0);
  }
  .panel-backdrop { display: none !important; }
  .mobile-close {
    display: flex;
  }
  .layout.panel-open .mobile-back {
    display: block;
  }
  /* Reserve space at the bottom of the panel content so the back button doesn't
     cover the last line of text or the footer's save/reload buttons. */
  .layout.panel-open .data-body {
    padding-bottom: 80px;
  }
  .layout.panel-open .data-footer {
    padding-bottom: 80px;
  }
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.create-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.create-form label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  font-weight: 600;
}
.create-form input,
.create-form select {
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.create-form input:focus,
.create-form select:focus { border-color: var(--accent); }
.create-form .form-hint { font-size: 11px; color: var(--text-faint); margin-top: -2px; }
.create-form .row-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(30,30,30,0.92);
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(192, 57, 43, 0.95); }
.toast.success { background: rgba(22, 163, 74, 0.95); }
