/* ═══════════════════════════════════════════════════════════════════════════
   SoulForge Monitor — Style Sheet
   Dark OLED theme, mobile-first, large touch targets
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reset & Base ────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:           #09090b;
  --card-bg:      #18181b;
  --card-bg-2:    #1f1f23;
  --border:       #27272a;
  --text:         #fafafa;
  --text-muted:   #71717a;
  --text-dim:     #52525b;

  --green:        #4ade80;
  --green-glow:   rgba(74, 222, 128, 0.35);
  --yellow:       #fbbf24;
  --yellow-glow:  rgba(251, 191, 36, 0.35);
  --red:          #ef4444;
  --red-glow:     rgba(239, 68, 68, 0.35);
  --gray:         #52525b;

  --purple:       #8b5cf6;
  --purple-dim:   rgba(139, 92, 246, 0.15);
  --purple-glow:  rgba(139, 92, 246, 0.4);

  --font-ui:      -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:    'SF Mono', 'Fira Code', 'Fira Mono', 'Consolas', monospace;

  --radius:       12px;
  --radius-sm:    8px;
  --touch:        44px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */

.hidden { display: none !important; }

.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

/* ── App Layout ──────────────────────────────────────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 600px;
  margin: 0 auto;
}

/* ── Auth Overlay ────────────────────────────────────────────────────────── */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.auth-logo {
  font-size: 48px;
  line-height: 1;
}

.auth-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.auth-input {
  width: 100%;
  height: var(--touch);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 0 14px;
  outline: none;
  transition: border-color 0.15s;
}

.auth-input:focus {
  border-color: var(--purple);
}

.auth-button {
  width: 100%;
  height: var(--touch);
  background: var(--purple);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.auth-button:active {
  opacity: 0.8;
}

.auth-error {
  font-size: 13px;
  color: var(--red);
  text-align: center;
}

/* ── Tab Bar ─────────────────────────────────────────────────────────────── */

.tab-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  padding-top: env(safe-area-inset-top, 0px);
}

.tab-btn {
  flex: 1;
  height: var(--touch);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tab-btn.active {
  color: var(--purple);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 2px;
  background: var(--purple);
  border-radius: 2px 2px 0 0;
}

/* ── Views ───────────────────────────────────────────────────────────────── */

.view {
  flex: 1;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

.view.hidden { display: none; }
.view.active { display: block; }

/* ── Status Bar ──────────────────────────────────────────────────────────── */

.status-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-bottom: 1px solid var(--border);
}

.status-bar::-webkit-scrollbar { display: none; }

.status-chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  min-width: 64px;
}

.status-chip-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.status-chip-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chip-green  { color: var(--green); }
.chip-yellow { color: var(--yellow); }
.chip-red    { color: var(--red); }
.chip-gray   { color: var(--text-muted); }

/* ── Card List ───────────────────────────────────────────────────────────── */

.card-list {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.loading-placeholder {
  color: var(--text-muted);
  font-size: 14px;
  padding: 24px 0;
  text-align: center;
}

/* ── Companion Card ──────────────────────────────────────────────────────── */

.companion-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.companion-card:active {
  background: var(--card-bg-2);
}

.companion-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.companion-mood-emoji {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.companion-info {
  flex: 1;
  min-width: 0;
}

.companion-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.companion-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 2px;
}

.companion-status-dot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.companion-err-badge {
  background: var(--red);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 7px;
  line-height: 1.4;
}

/* ── Status Dot ──────────────────────────────────────────────────────────── */

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-green  { background: var(--green);  box-shadow: 0 0 6px var(--green-glow); }
.dot-yellow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow-glow); }
.dot-red    { background: var(--red);    box-shadow: 0 0 6px var(--red-glow); }
.dot-gray   { background: var(--gray); }

/* Larger dot for loop status */
.dot-lg {
  width: 12px;
  height: 12px;
}

/* ── Pressure Bar ────────────────────────────────────────────────────────── */

.pressure-bar-wrap {
  margin-top: 10px;
}

.pressure-bar-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.pressure-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease, background 0.3s ease;
}

/* ── Detail View ─────────────────────────────────────────────────────────── */

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.back-btn {
  background: transparent;
  border: none;
  color: var(--purple);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  min-width: var(--touch);
  min-height: var(--touch);
  display: flex;
  align-items: center;
  padding: 0 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.detail-identity {
  flex: 1;
  min-width: 0;
}

.detail-name {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.detail-uptime {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.detail-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Status Badge ────────────────────────────────────────────────────────── */

.status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 6px;
  padding: 3px 8px;
}

.badge-active   { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.badge-sleeping { background: rgba(82, 82, 91, 0.25);   color: var(--gray); }
.badge-degraded { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }
.badge-error    { background: rgba(239, 68, 68, 0.15);  color: var(--red); }

/* ── Section Block ───────────────────────────────────────────────────────── */

.section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

/* ── Gauge Bar ───────────────────────────────────────────────────────────── */

.gauge-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.gauge-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gauge-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gauge-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.gauge-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
}

.gauge-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--purple);
  transition: width 0.3s ease;
}

/* ── Subsystem Grid ──────────────────────────────────────────────────────── */

.subsystem-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.subsystem-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.subsystem-card:active {
  background: var(--card-bg-2);
}

.subsystem-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.subsystem-name {
  font-size: 12px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subsystem-detail {
  margin-top: 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
}

.subsystem-detail.expanded {
  display: flex;
}

.subsystem-detail-row {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.subsystem-detail-row span:last-child {
  font-family: var(--font-mono);
  color: var(--text);
  text-align: right;
}

/* ── Error List ──────────────────────────────────────────────────────────── */

.error-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.error-item {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--red);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.error-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  word-break: break-all;
}

.error-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.error-sentry-link {
  color: var(--purple);
  text-decoration: none;
  font-size: 11px;
}

.error-sentry-link:hover {
  text-decoration: underline;
}

.error-empty {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  padding: 16px 0;
}

/* ── Gracie View ─────────────────────────────────────────────────────────── */

.gracie-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 32px;
}

.gracie-header-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gracie-brain-ver {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--purple);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.gracie-mood-line {
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.gracie-obsession {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Loop Status Grid ────────────────────────────────────────────────────── */

.loop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.loop-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loop-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.loop-name {
  font-size: 13px;
  font-weight: 600;
  text-transform: capitalize;
}

.loop-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Mind Panel ──────────────────────────────────────────────────────────── */

.mind-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mind-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Thought thread */
.thought-item {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.thought-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.thought-ts {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
}

/* Temporal desires */
.desire-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.desire-text {
  font-size: 13px;
}

.desire-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.desire-urgency-track {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.desire-urgency-fill {
  height: 100%;
  border-radius: 2px;
}

.desire-urgency-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 28px;
  text-align: right;
}

/* Interest graph */
.interest-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.interest-item:last-child {
  border-bottom: none;
}

.interest-topic {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.interest-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.interest-depth {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--purple-dim);
  color: var(--purple);
  font-weight: 600;
}

.interest-fresh {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ── Diary / Action Log ──────────────────────────────────────────────────── */

.diary-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.diary-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.diary-ts {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  margin-bottom: 4px;
}

.diary-text {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
}

.action-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.action-item:last-child {
  border-bottom: none;
}

.action-ts {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
  padding-top: 1px;
}

.action-text {
  font-size: 13px;
  flex: 1;
}

/* ── Control Panel ───────────────────────────────────────────────────────── */

.control-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--touch);
}

.toggle-label {
  font-size: 14px;
  flex: 1;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 13px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--purple);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-btn {
  height: var(--touch);
  border: 1px solid var(--border);
  background: var(--card-bg-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  padding: 0 8px;
}

.action-btn:active {
  background: var(--purple-dim);
  border-color: var(--purple);
}

.action-btn-danger {
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--red);
}

.action-btn-danger:active {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--red);
}

/* ── Confirmation Modal ──────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.modal-backdrop:not(.hidden) {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-message {
  font-size: 15px;
  line-height: 1.6;
  text-align: center;
  color: var(--text);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-btn {
  height: var(--touch);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.12s;
}

.modal-btn:active {
  opacity: 0.8;
}

.modal-btn-cancel {
  background: var(--border);
  color: var(--text-muted);
}

.modal-btn-confirm {
  background: var(--purple);
  color: #fff;
}

/* ── Responsive: center on desktop ──────────────────────────────────────── */

@media (min-width: 600px) {
  .app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
