/* ============================================================
   GLM Cockpit — styles.css
   Dark, mobile-first, thumb-friendly, installable-app feel.
   Owner: ui
   ============================================================ */

:root {
  --bg:            #0b0e14;
  --bg-elev:       #131824;
  --bg-elev-2:     #1a2130;
  --bg-input:      #0f141e;
  --border:        #242c3a;
  --border-soft:   #1c2431;

  --text:          #e6e9ef;
  --text-dim:      #9aa4b6;
  --text-faint:    #6b7688;

  --accent:        #4c8dff;
  --accent-press:  #3a74d9;

  --working:       #f5a623;   /* amber */
  --done:          #37d67a;   /* green */
  --idle:          #6b7688;   /* grey  */
  --danger:        #ff5c5c;
  --permission:    #c07bff;   /* violet */

  --unseen:        #4c8dff;

  --radius:        14px;
  --radius-sm:     10px;
  --topbar-h:      54px;
  --compose-h:     72px;

  --safe-top:      env(safe-area-inset-top, 0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
  --safe-left:     env(safe-area-inset-left, 0px);
  --safe-right:    env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
          Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

.muted { color: var(--text-faint); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--text);
  background: var(--bg-elev-2);
  cursor: pointer;
  min-height: 44px;
  transition: background .12s ease, opacity .12s ease, transform .06s ease;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-press); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-block { width: 100%; }

.iconbtn {
  font: inherit;
  font-size: 20px;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0;
}
.iconbtn:active { background: var(--bg-elev-2); }

/* ============================================================
   Login
   ============================================================ */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(120% 60% at 50% 0%, #16203a 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo {
  font-size: 44px;
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--accent);
}
.login-title {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.login-sub {
  margin: 0 0 28px;
  color: var(--text-dim);
  font-size: 15px;
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-input {
  font: inherit;
  font-size: 17px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  width: 100%;
  min-height: 50px;
}
.login-input::placeholder { color: var(--text-faint); }
.login-input:focus {
  outline: none;
  border-color: var(--accent);
}
.login-error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 2px;
  min-height: 18px;
}

/* ============================================================
   App shell
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: calc(8px + var(--safe-left));
  padding-right: calc(8px + var(--safe-right));
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(11, 14, 20, 0.86);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar-back { font-size: 30px; font-weight: 300; margin-left: -4px; }
.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
}
.topbar-brand {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  padding-left: 8px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Live / Reconnecting indicator */
.link-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.link-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--idle);
  flex: 0 0 auto;
}
.link-indicator.link-live {
  color: var(--done);
  border-color: rgba(55, 214, 122, 0.35);
}
.link-indicator.link-live .link-dot {
  background: var(--done);
  box-shadow: 0 0 0 0 rgba(55, 214, 122, 0.6);
  animation: pulse-live 2s infinite;
}
.link-indicator.link-reconnecting,
.link-indicator.link-boot {
  color: var(--working);
  border-color: rgba(245, 166, 35, 0.35);
}
.link-indicator.link-reconnecting .link-dot,
.link-indicator.link-boot .link-dot {
  background: var(--working);
  animation: blink 1s steps(2, start) infinite;
}

@keyframes pulse-live {
  0%   { box-shadow: 0 0 0 0 rgba(55, 214, 122, 0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(55, 214, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(55, 214, 122, 0); }
}
@keyframes blink { 50% { opacity: .35; } }

/* Notification hint bar */
.notif-hint {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.4;
  padding: 10px calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
}

/* ============================================================
   Views
   ============================================================ */
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---- List view ---- */
.view-list {
  padding-bottom: calc(24px + var(--safe-bottom));
}
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px calc(16px + var(--safe-right)) 8px calc(16px + var(--safe-left));
}
.list-heading {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.btn-new { padding: 8px 14px; min-height: 40px; font-size: 14px; }

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
}

/* Session row (rendered by render.js — style by class contract) */
.session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px 14px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  color: inherit;
  font: inherit;
  cursor: pointer;
  min-height: 64px;
  transition: background .12s ease, transform .06s ease;
}
.session-row:active { transform: scale(.99); background: var(--bg-elev-2); }

.session-badge {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: var(--bg-elev-2);
}
.session-badge.badge-working { box-shadow: inset 0 0 0 1.5px var(--working); }
.session-badge.badge-done    { box-shadow: inset 0 0 0 1.5px var(--done); }
.session-badge.badge-idle    { box-shadow: inset 0 0 0 1.5px var(--border); }
.session-badge.badge-permission { box-shadow: inset 0 0 0 1.5px var(--permission); }

.session-body { flex: 1; min-width: 0; }
.session-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.session-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.session-snippet {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
}
.status-pill {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-faint);
}
.status-pill.pill-working { color: var(--working); background: rgba(245,166,35,.12); }
.status-pill.pill-done    { color: var(--done);    background: rgba(55,214,122,.12); }
.status-pill.pill-idle    { color: var(--idle);    background: rgba(107,118,136,.14); }
.status-pill.pill-permission { color: var(--permission); background: rgba(192,123,255,.14); }

.session-time { font-size: 11px; color: var(--text-faint); }

/* Unseen dot */
.session-unseen {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--unseen);
  box-shadow: 0 0 8px rgba(76,141,255,.7);
}

.working-spin {
  display: inline-block;
  animation: spin 1.4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 48px 24px;
}
.list-empty p { margin: 4px 0; }

/* ============================================================
   Thread view
   ============================================================ */
.view-thread {
  position: relative;
}
.thread-topline {
  padding: 12px calc(16px + var(--safe-right)) 8px calc(16px + var(--safe-left));
  border-bottom: 1px solid var(--border-soft);
}
.thread-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Banners */
.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  padding: 12px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  animation: banner-in .22s ease;
}
.banner-icon { font-size: 18px; flex: 0 0 auto; }
.banner-text { flex: 1; }
.banner-dismiss {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 22px;
  line-height: 1;
  opacity: .7;
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
}
.banner-done {
  background: rgba(55, 214, 122, 0.14);
  color: var(--done);
  border: 1px solid rgba(55, 214, 122, 0.35);
}
.banner-permission {
  background: rgba(192, 123, 255, 0.14);
  color: var(--permission);
  border: 1px solid rgba(192, 123, 255, 0.35);
}
@keyframes banner-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Messages scroll area */
.thread-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px calc(14px + var(--safe-right)) 20px calc(14px + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Message parts (rendered by render.js — class contract) */
.msg {
  max-width: 92%;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
}
.msg pre {
  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 13px;
  margin: 8px 0;
}
.msg code {
  font-family: var(--mono);
  font-size: 13px;
}
.msg p:first-child { margin-top: 0; }
.msg p:last-child { margin-bottom: 0; }

/* Reasoning (collapsible) */
.msg-reasoning {
  align-self: flex-start;
  max-width: 92%;
  font-size: 13px;
}
.msg-reasoning summary {
  cursor: pointer;
  color: var(--text-faint);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  list-style: none;
  user-select: none;
}
.msg-reasoning summary::-webkit-details-marker { display: none; }
.msg-reasoning[open] summary { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.msg-reasoning .reasoning-body {
  color: var(--text-dim);
  padding: 8px 12px;
  border: 1px dashed var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  white-space: pre-wrap;
}

/* Tool card */
.msg-tool {
  align-self: flex-start;
  max-width: 92%;
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13px;
}
.msg-tool .tool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--text-dim);
  font-weight: 600;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elev-2);
}
.msg-tool .tool-head::before { content: "🛠"; }
.msg-tool .tool-body {
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 240px;
}
.msg-file img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  display: block;
}

.thread-empty {
  color: var(--text-faint);
  text-align: center;
  padding: 40px 20px;
}

/* ============================================================
   Compose bar
   ============================================================ */
.compose {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px calc(12px + var(--safe-right))
           calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
  background: rgba(11, 14, 20, 0.9);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border-soft);
}
.compose-input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  line-height: 1.4;
}
.compose-input::placeholder { color: var(--text-faint); }
.compose-input:focus { outline: none; border-color: var(--accent); }
.compose-send {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   Larger screens — center the app like a phone frame
   ============================================================ */
@media (min-width: 720px) {
  .app {
    max-width: 560px;
    margin: 0 auto;
    border-left: 1px solid var(--border-soft);
    border-right: 1px solid var(--border-soft);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
