/* ============================================================================
   Jarvis Chat — design system (extends the Kitchen App palette, does not fight it)
   ========================================================================== */

/* Light mode */
:root {
  --bg-app:            #F7F4EF;
  --bg-surface:        #FFFFFF;
  --bg-sidebar-hover:  #EDE9E0;
  --bg-sidebar-active: #E4DFD3;
  --bg-user-bubble:    #E8F2EC;
  --bg-input:          #EEEAE1;
  --accent-green:      #1D9E75;
  --accent-blue:       #2B6CB0;
  --text-primary:      #111827;
  --text-secondary:    #6B7280;
  --text-sidebar:      #374151;
  --border:            #E8E3DA;
  --recording-red:     #DC2626;
  --proactive-amber:   #D97706;
  --pin-yellow:        #CA8A04;
  --shadow-sm:         0 1px 3px rgba(0,0,0,0.07);
  --radius-bubble-user:   18px;
  --radius-bubble-jarvis: 4px 18px 18px 18px;
  --radius-input:         14px;
}

/* Dark mode — device-driven, not a manual toggle */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-app:            #141414;
    --bg-surface:        #1F1F1F;
    --bg-sidebar-hover:  #262626;
    --bg-sidebar-active: #2E2E2E;
    --bg-user-bubble:    #1A3028;
    --bg-input:          #2A2A2A;
    --border:            #333333;
    --accent-green:      #25C990;
    --accent-blue:       #60A5FA;
    --text-primary:      #F3F4F6;
    --text-secondary:    #9CA3AF;
    --text-sidebar:      #D1D5DB;
    --shadow-sm:         0 1px 4px rgba(0,0,0,0.4);
  }
}

/* MANDATORY MOBILE — never remove these */
html, body {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}

* { touch-action: manipulation; box-sizing: border-box; }

input, textarea, select { font-size: 16px !important; } /* prevents iOS auto-zoom */

.scroll-container { -webkit-overflow-scrolling: touch; overflow-y: auto; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ============================================================================
   LOGIN SCREEN
   ========================================================================== */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-app);
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
}
.login-card {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
}
.brand { text-align: center; margin-bottom: 8px; }
.leaf { color: var(--accent-green); display: inline-flex; }
.brand h1 { margin: 8px 0 2px; font-size: 28px; letter-spacing: -0.02em; }
.subhead { margin: 0; color: var(--text-secondary); font-size: 15px; }

#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input[type="text"],
#login-form input[type="password"] {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: var(--radius-input);
  background: var(--bg-surface); color: var(--text-primary);
}
.password-row { position: relative; }
.password-row input { padding-right: 64px !important; }
.ghost-icon {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  height: 44px; min-width: 44px; padding: 0 10px; border: none; background: transparent;
  color: var(--accent-blue); cursor: pointer; font-size: 14px;
}
.remember {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--text-secondary); cursor: pointer;
  min-height: 44px;
}
.remember input { width: 18px; height: 18px; }

.btn-primary {
  width: 100%; min-height: 48px; border: none; border-radius: var(--radius-input);
  background: var(--accent-green); color: #fff; font-size: 16px; font-weight: 600;
  cursor: pointer; transition: filter .12s ease, transform .06s ease;
}
.btn-primary:hover { filter: brightness(0.92); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

.login-error {
  color: var(--recording-red); font-size: 14px; text-align: center;
  min-height: 18px;
}

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-secondary); font-size: 13px; margin: 4px 0;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.btn-ghost {
  width: 100%; min-height: 48px; border: 1px solid var(--border);
  border-radius: var(--radius-input); background: var(--bg-surface);
  color: var(--text-primary); font-size: 15px; cursor: pointer;
  transition: background .12s ease, transform .06s ease;
}
.btn-ghost:hover { background: var(--bg-sidebar-hover); }
.btn-ghost:active { transform: scale(0.97); }

/* ============================================================================
   APP LAYOUT
   ========================================================================== */
#app { display: flex; position: fixed; inset: 0; }

/* SIDEBAR */
.sidebar {
  width: 260px; flex: 0 0 260px; height: 100%;
  background: var(--bg-surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 14px 8px;
}
.leaf-sm { color: var(--accent-green); }
.sidebar-title { font-weight: 700; font-size: 18px; flex: 1; }
.icon-btn {
  min-width: 44px; min-height: 44px; border: none; background: transparent;
  color: var(--text-sidebar); font-size: 18px; cursor: pointer;
  border-radius: 10px; transition: background .12s ease, transform .06s ease;
}
.icon-btn:hover { background: var(--bg-sidebar-hover); }
.icon-btn:active { transform: scale(0.97); }

.search-wrap { padding: 4px 12px 8px; }
#thread-search {
  width: 100%; height: 44px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-app); color: var(--text-primary);
}

/* min-height:0 lets this flex child actually scroll instead of growing to fit
   its content (Failure Log Build 44 — the canonical flex-scroll bug). */
.thread-list { flex: 1; min-height: 0; padding: 4px 8px; }

.group-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-secondary);
  padding: 12px 8px 4px;
}

/* Thread rows — full-row interactive control */
.thread-row {
  display: flex; align-items: center; gap: 8px;
  padding: 0 8px; min-height: 44px; border-radius: 10px;
  cursor: pointer; color: var(--text-sidebar);
  transition: background .1s ease;
}
.thread-row:hover { background: var(--bg-sidebar-hover); }
.thread-row.active { background: var(--bg-sidebar-active); position: relative; }
.thread-row.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 2px; background: var(--accent-green);
}
.pin-icon { color: var(--pin-yellow); font-size: 12px; }
.thread-name {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px;
}
.thread-name.shared { color: var(--accent-blue); }
.thread-time { font-size: 11px; color: var(--text-secondary); }
.thread-menu-btn {
  min-width: 44px; min-height: 44px; border: none; background: transparent;
  color: var(--text-secondary); cursor: pointer; border-radius: 8px;
  font-size: 16px; opacity: 0; transition: opacity .1s ease, background .1s ease;
}
.thread-row:hover .thread-menu-btn { opacity: 1; }
.thread-menu-btn:hover { background: var(--bg-sidebar-active); }
@media (max-width: 767px) { .thread-menu-btn { opacity: 1; } }

.thread-rename-input {
  flex: 1; height: 32px; padding: 0 8px;
  border: 1px solid var(--accent-green); border-radius: 8px;
  background: var(--bg-surface); color: var(--text-primary);
}

.thread-confirm {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; font-size: 13px; color: var(--text-primary);
}
.thread-confirm span { flex: 1; }

/* Artifacts stub */
.artifacts-section { border-top: 1px solid var(--border); }
.artifacts-header {
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px; min-height: 44px; cursor: pointer;
  color: var(--text-sidebar); font-size: 14px; font-weight: 600;
}
.artifacts-header:hover { background: var(--bg-sidebar-hover); }
.artifacts-header span:nth-child(2) { flex: 1; }
.count-badge {
  background: var(--accent-green); color: #fff; font-size: 11px;
  border-radius: 10px; padding: 1px 7px;
}
.chevron { transition: transform .15s ease; font-size: 12px; }
.artifacts-header:not(.collapsed) .chevron { transform: rotate(180deg); }
.artifacts-body { padding: 4px 14px 10px; }
.artifacts-empty { color: var(--text-secondary); font-size: 13px; padding: 6px 0; }

/* Sidebar footer */
.sidebar-footer {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-top: 1px solid var(--border);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent-green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
}
.footer-name { flex: 1; font-size: 14px; color: var(--text-sidebar); }
.btn-text {
  border: none; background: transparent; color: var(--accent-blue);
  cursor: pointer; font-size: 14px; min-height: 44px; padding: 0 6px;
}
.btn-text:hover { text-decoration: underline; }

/* ============================================================================
   CHAT AREA
   ========================================================================== */
.chat-area {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg-app);
}
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px; min-height: 52px;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--border); background: var(--bg-surface);
}
.chat-title {
  flex: 1; font-weight: 600; font-size: 16px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.private-badge { font-size: 12px; color: var(--text-secondary); }

.thread-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Empty state */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 24px; gap: 8px;
}
.empty-state .leaf { color: var(--accent-green); margin-bottom: 4px; }
.empty-greeting { font-size: 22px; font-weight: 600; }
.empty-sub { color: var(--text-secondary); font-size: 15px; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 420px; }
.chip {
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--bg-surface); color: var(--text-primary);
  padding: 10px 14px; font-size: 14px; cursor: pointer; min-height: 44px;
  transition: background .12s ease, transform .06s ease;
}
.chip:hover { background: var(--bg-sidebar-hover); }
.chip:active { transform: scale(0.97); }

/* Input bar — disabled in Phase 3A */
.input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px; background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.input-bar.disabled { opacity: 1; }
#composer {
  flex: 1; resize: none; max-height: 140px;
  border: 1px solid var(--border); border-radius: var(--radius-input);
  background: var(--bg-input); color: var(--text-primary);
  padding: 12px 14px; line-height: 1.3;
}
#composer:disabled { cursor: not-allowed; opacity: 0.6; }
.input-icon {
  min-width: 44px; min-height: 44px; border: none; border-radius: 12px;
  background: transparent; color: var(--text-secondary); font-size: 20px;
}
.input-icon:disabled { cursor: not-allowed; opacity: 0.5; }

/* ============================================================================
   PASSKEY BANNER, CONTEXT MENU, TOAST
   ========================================================================== */
.passkey-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent-green); color: #fff; font-size: 14px;
}
.passkey-banner span { flex: 1; }
.banner-actions { display: flex; gap: 8px; }
.btn-small {
  border: 1px solid rgba(255,255,255,0.6); background: rgba(255,255,255,0.15);
  color: #fff; border-radius: 8px; padding: 6px 12px; font-size: 13px;
  cursor: pointer; min-height: 44px;
}
.btn-small.btn-text { border: none; background: transparent; color: #fff; }

.menu-backdrop { position: fixed; inset: 0; z-index: 99; }
.context-menu {
  position: fixed; z-index: 100; min-width: 180px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-sm); padding: 6px;
}
.menu-item {
  display: block; width: 100%; text-align: left;
  border: none; background: transparent; color: var(--text-primary);
  padding: 10px 12px; border-radius: 8px; font-size: 14px; cursor: pointer;
  min-height: 44px;
}
.menu-item:hover { background: var(--bg-sidebar-hover); }
.menu-item.destructive { color: var(--recording-red); }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 300;
  background: var(--text-primary); color: var(--bg-surface);
  padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow-sm); max-width: 90%;
}

/* ============================================================================
   RESPONSIVE
   ========================================================================== */
/* Mobile: sidebar as drawer */
@media (max-width: 767px) {
  .sidebar {
    position: fixed; left: -280px; top: 0; bottom: 0;
    width: 260px; transition: left 0.2s ease; z-index: 100;
  }
  .sidebar.open { left: 0; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; z-index: 99;
    background: rgba(0,0,0,0.4);
  }
  .sidebar.open + .sidebar-backdrop { display: block; }
}

/* Desktop: sidebar always visible */
@media (min-width: 768px) {
  .sidebar { position: relative; left: 0; }
  .sidebar-backdrop { display: none !important; }
  .hamburger-btn { display: none; }
}
