/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────────────────────────────────── */
:root {
  --bg-deep:   #0A0F1E;
  --bg-main:   #0F172A;
  --surface1:  #1E293B;
  --surface2:  #243347;
  --border:    #2D3F55;
  --indigo:    #6366F1;
  --indigo-d:  #4338CA;
  --indigo-l:  #818CF8;
  --emerald:   #10B981;
  --text-pri:  #E2E8F0;
  --text-sub:  #94A3B8;
  --text-muted:#475569;
  --error:     #F87171;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 20px;
  font-size: 15px;
}

/* ── Base ──────────────────────────────────────────────────────────────── */
html, body { height: 100%; background: var(--bg-main); color: var(--text-pri);
             font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

/* ── Layout ────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: 260px; min-width: 260px;
  display: flex; flex-direction: column;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  transition: transform .25s;
}
.sidebar-header {
  padding: 18px 16px 14px;
  background: linear-gradient(to bottom, var(--surface2), var(--bg-deep));
  border-bottom: 1px solid var(--border);
}
.sidebar-logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--indigo), #8B5CF6);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.logo-title { font-weight: 700; font-size: 16px; }
.logo-sub   { font-size: 11px; color: var(--text-muted); }

.agent-list { flex: 1; overflow-y: auto; padding: 8px 6px; }

.agent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 12px; cursor: pointer;
  transition: background .15s; position: relative;
}
.agent-item:hover         { background: rgba(99,102,241,.08); }
.agent-item.selected      { background: linear-gradient(to right, rgba(99,102,241,.22), transparent); }
.agent-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), #8B5CF6);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.agent-info { flex: 1; min-width: 0; }
.agent-name {
  font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-pri);
}
.agent-item.selected .agent-name { color: var(--indigo-l); font-weight: 600; }
.agent-msgs { font-size: 11px; color: var(--text-muted); }
.agent-del {
  opacity: 0; background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 14px; padding: 2px 4px; border-radius: 4px;
  transition: opacity .15s;
}
.agent-item:hover .agent-del { opacity: 1; }
.agent-del:hover { color: var(--error); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 4px 6px;
}
.btn-add-agent {
  width: 100%; padding: 10px 14px; border-radius: 12px;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  color: var(--text-sub); font-size: 14px;
  transition: background .15s;
}
.btn-add-agent:hover { background: rgba(99,102,241,.1); }
.btn-add-agent span  { font-size: 18px; line-height: 1; }

/* ── Chat area ─────────────────────────────────────────────────────────── */
#chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: var(--surface1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.menu-toggle { display: none; background: none; border: none; color: var(--text-sub);
               font-size: 20px; cursor: pointer; padding: 4px 8px; }
.topbar-agent { display: flex; align-items: center; gap: 10px; flex: 1; }
.topbar-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--indigo), #8B5CF6);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
}
.topbar-name   { font-weight: 600; font-size: 14px; }
.topbar-status { font-size: 11px; color: var(--emerald); display: flex; align-items: center; gap: 4px; }
.status-dot    { width: 6px; height: 6px; border-radius: 50%; background: var(--emerald);
                 animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%,100%{opacity:.5} 50%{opacity:1} }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-sub);
            font-size: 18px; padding: 4px 6px; border-radius: 6px; transition: color .15s; }
.btn-icon:hover { color: var(--text-pri); }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 6px; }

.date-sep {
  display: flex; align-items: center; gap: 10px; margin: 10px 0;
  color: var(--text-muted); font-size: 11px;
}
.date-sep::before, .date-sep::after { content: ''; flex: 1; height: 0.5px; background: var(--border); }
.date-sep span { background: var(--surface2); padding: 3px 10px; border-radius: 8px; }

.msg-row { display: flex; }
.msg-row.user  { justify-content: flex-end; }
.msg-row.ai    { justify-content: flex-start; }

.bubble-wrap { display: flex; flex-direction: column; max-width: 72%; gap: 3px; }
.msg-row.user .bubble-wrap { align-items: flex-end; }
.msg-row.ai   .bubble-wrap { align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-row.user .bubble {
  background: linear-gradient(135deg, var(--indigo), var(--indigo-d));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.ai .bubble {
  background: var(--surface1);
  color: var(--text-pri);
  border: 0.5px solid var(--border);
  border-bottom-left-radius: 4px;
  cursor: pointer;
}
.msg-row.ai .bubble:hover { border-color: var(--indigo-l); }
.bubble-hint { font-size: 10px; color: var(--indigo-l); margin-top: 1px; }

.bubble-meta {
  display: flex; align-items: center; gap: 4px;
  font-size: 10.5px; color: var(--text-muted);
}
.ticks { letter-spacing: -2px; }
.ticks.read      { color: var(--emerald); }
.ticks.delivered { color: var(--text-sub); }
.ticks.queued    { color: var(--text-muted); font-size: 10px; letter-spacing: 0; }

.bubble-retry {
  background: none; border: none; cursor: pointer; padding: 0;
  color: var(--error); font-size: 10.5px;
  display: flex; align-items: center; gap: 3px;
  opacity: 0.85; transition: opacity .15s;
}
.bubble-retry:hover { opacity: 1; text-decoration: underline; }

/* Typing animation */
.typing-bubble {
  padding: 10px 16px;
  background: var(--surface1); border: 0.5px solid var(--border);
  border-radius: 18px; border-bottom-left-radius: 4px;
  display: flex; flex-direction: column; gap: 4px;
}
.typing-dots { display: flex; align-items: center; gap: 5px; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-sub);
  animation: bounce .8s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .30s; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
.typing-status {
  font-size: 10.5px; color: var(--text-muted);
  min-height: 0; transition: opacity .2s;
}
.typing-status:empty { display: none; }
.typing-thinking {
  font-size: 11.5px; color: var(--text-muted); font-style: italic;
  line-height: 1.5; max-height: 120px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  border-top: 0.5px solid var(--border); padding-top: 6px; margin-top: 2px;
}
.typing-thinking:empty { display: none; }

/* ── Input area ────────────────────────────────────────────────────────── */
.input-area {
  padding: 10px 12px;
  background: var(--surface1);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-row { display: flex; align-items: flex-end; gap: 8px; }

#input {
  flex: 1; resize: none; min-height: 42px; max-height: 140px;
  padding: 10px 14px;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: 22px;
  color: var(--text-pri);
  font-size: 14.5px; font-family: inherit; line-height: 1.5;
  outline: none; overflow-y: auto;
  transition: border-color .15s;
  scrollbar-width: none;
}
#input:focus         { border-color: var(--indigo); }
#input::placeholder  { color: var(--text-muted); }

.input-buttons { display: flex; align-items: center; }
.btn-round {
  width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: transform .1s, opacity .12s;
}
.btn-round:active { transform: scale(.93); }
.btn-send { background: linear-gradient(135deg, var(--indigo), var(--indigo-d)); color: #fff; }
.btn-round.hidden { opacity: 0; pointer-events: none; position: absolute; }

/* ── Modals ────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface1); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; width: 360px; max-width: 95vw;
}
.modal-thinking-box { width: 480px; max-height: 80vh; display: flex; flex-direction: column; }
#thinking-content   { overflow-y: auto; flex: 1; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  font-size: 16px; padding: 4px; border-radius: 6px;
}
.modal-close:hover { color: var(--text-pri); }

.modal-box label {
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px;
  font-size: 13px; color: var(--text-sub);
}
.toggle-row { flex-direction: row !important; align-items: center; justify-content: space-between; }
.modal-box input[type="text"] {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px;
  color: var(--text-pri); font-size: 14px; outline: none;
  transition: border-color .15s;
}
.modal-box input[type="text"]:focus { border-color: var(--indigo); }
.modal-box input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--indigo); }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 8px; }
.btn-primary {
  background: linear-gradient(135deg, var(--indigo), var(--indigo-d));
  color: #fff; border: none; border-radius: 10px;
  padding: 9px 20px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .88; }

/* Thinking overlay content */
.thinking-section { margin-bottom: 18px; }
.thinking-section h4 {
  font-size: 12px; font-weight: 600; color: var(--indigo-l);
  letter-spacing: .4px; text-transform: uppercase; margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px;
}
.tool-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface2); border-radius: 8px;
  padding: 7px 10px; margin-bottom: 6px;
  font-size: 13px; font-family: monospace; color: var(--text-pri);
}
.tool-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--emerald); flex-shrink: 0; }
.thinking-text { font-size: 13.5px; color: var(--text-sub); line-height: 1.6; font-style: italic; white-space: pre-wrap; }

/* ── Memory modal ─────────────────────────────────────────────────────── */
.memory-box { width: 460px; max-height: 80vh; display: flex; flex-direction: column; }
.btn-mem-tab {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); font-size: 12px; padding: 3px 10px; cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-mem-tab.active { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.btn-mem-tab:hover:not(.active) { color: var(--text-pri); }

#memory-view-panel { overflow-y: auto; flex: 1; padding-bottom: 4px; }
#memory-edit-panel { display: flex; flex-direction: column; flex: 1; gap: 8px; }
#memory-json-editor {
  flex: 1; min-height: 260px; resize: none;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; color: var(--text-pri); font-size: 12.5px;
  font-family: 'SF Mono', 'Fira Code', monospace; line-height: 1.6;
  outline: none; tab-size: 2;
}
#memory-json-editor:focus { border-color: var(--indigo); }
.mem-edit-error { font-size: 12px; color: var(--error); }

.mem-section { margin-bottom: 14px; }
.mem-section-title {
  font-size: 10.5px; font-weight: 600; color: var(--indigo-l);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px;
}
.mem-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 8px; border-radius: 7px; background: var(--surface2);
  margin-bottom: 4px; min-width: 0;
}
.mem-key {
  font-size: 12px; color: var(--text-sub); font-family: monospace;
  flex-shrink: 0; white-space: nowrap;
}
.mem-val {
  font-size: 13px; color: var(--text-pri); flex: 1;
  word-break: break-word;
}
.mem-expires { font-size: 11px; color: var(--text-muted); margin-left: 6px; }
.mem-empty { font-size: 13px; color: var(--text-muted); text-align: center; padding: 24px 0; line-height: 1.6; }

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar         { width: 4px; }
::-webkit-scrollbar-track   { background: transparent; }
::-webkit-scrollbar-thumb   { background: var(--border); border-radius: 4px; }

/* ── Login screen ──────────────────────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg-main);
  display: flex; align-items: center; justify-content: center;
}
.login-screen.hidden { display: none; }
.login-card {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  background: var(--surface1); border: 1px solid var(--border);
  border-radius: 20px; padding: 40px 36px; width: 340px; max-width: 95vw;
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(135deg, var(--indigo), #8B5CF6);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
}
.login-title { font-size: 22px; font-weight: 700; color: var(--text-pri); }
.login-sub   { font-size: 13px; color: var(--text-muted); }
.login-error { font-size: 12px; color: var(--error); margin-top: 4px; }
.hidden      { display: none !important; }

/* ── Calendar strip ──────────────────────────────────────────────────────── */
.cal-strip {
  flex-shrink: 0;
  background: var(--surface1);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.cal-strip.hidden { display: none; }

.cal-strip-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cal-strip-title { font-size: 12px; font-weight: 600; color: var(--text-pri); }
.cal-updated { flex: 1; font-size: 10px; color: var(--text-muted); }
.cal-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 11px;
  padding: 2px 6px; border-radius: 4px; line-height: 1;
  transition: color .15s;
}
.cal-toggle:hover { color: var(--text-pri); }
.cal-arrow {
  background: none; border: none; cursor: pointer;
  color: var(--text-sub); font-size: 18px; font-weight: 300;
  padding: 0 3px; border-radius: 4px; line-height: 1;
  transition: color .15s; flex-shrink: 0;
}
.cal-arrow:hover:not(:disabled) { color: var(--text-pri); }
.cal-arrow:disabled { color: var(--text-muted); opacity: 0.3; cursor: default; }

.cal-body {
  overflow-y: auto;
  max-height: 220px;
  flex-shrink: 0;
  position: relative;
}
.cal-body.collapsed { display: none; }

/* List view columns */
.cal-grid { display: flex; min-height: 40px; }
.cal-list-col { overflow: visible;
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
}
.cal-list-col:last-child { border-right: none; }
.cal-list-day-header {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface1);
  padding: 5px 8px;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-list-day-header.today { color: var(--indigo-l); }
.cal-list-body { display: flex; flex-direction: column; gap: 3px; padding: 5px; }
.cal-list-event {
  display: flex; align-items: baseline; gap: 5px;
  padding: 5px 7px;
  border-left: 2px solid var(--indigo);
  border-radius: 3px;
  background: rgba(99,102,241,.1);
  min-width: 0; overflow: hidden;
}
.cal-list-event.all-day {
  border-left-color: var(--emerald);
  background: rgba(16,185,129,.1);
}
.cal-list-event-time {
  font-size: 10.5px; color: var(--text-muted);
  flex-shrink: 0; white-space: nowrap;
}
.cal-list-event-title {
  font-size: 12px; color: var(--text-pri);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.cal-list-empty {
  font-size: 11px; color: var(--text-muted);
  padding: 8px 5px; text-align: center;
}
/* Current-time indicator — between events */
.cal-time-indicator {
  display: flex; align-items: center; gap: 0; margin: 1px 0;
}
.cal-time-indicator::before {
  content: ''; display: block; width: 8px; height: 8px;
  border-radius: 50%; background: #ef4444; flex-shrink: 0;
}
.cal-time-indicator::after {
  content: ''; display: block; flex: 1; height: 1.5px; background: #ef4444;
}
/* Current-time indicator — through an active event */
.cal-list-event.cal-now-event {
  position: relative; overflow: visible;
}
.cal-list-event.cal-now-event::after {
  content: '';
  position: absolute;
  left: -8px; right: 0;
  top: calc(var(--now-frac) * 100%);
  height: 1.5px;
  background: #ef4444;
  pointer-events: none;
}
.cal-list-event.cal-now-event::before {
  content: '';
  position: absolute;
  left: -8px;
  top: calc(var(--now-frac) * 100% - 3.5px);
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #ef4444;
  pointer-events: none;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
             transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
}
