/* === Jongstra Design Tokens === */
:root {
  --accent: #f97316;
  --accent-hover: #ea580c;
  --accent-light: #fff7ed;
  --accent-subtle: #fed7aa;

  /* Light theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --bg-hover: #f3f4f6;
  --bg-active: #fff7ed;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-inverse: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);

  /* Semantic */
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #2563eb;
  --info-bg: #dbeafe;

  /* Urgency */
  --urgency-high: #dc2626;
  --urgency-medium: #d97706;
  --urgency-low: #16a34a;

  /* Messages */
  --msg-operator-bg: var(--accent);
  --msg-operator-text: #ffffff;

  /* Layout */
  --sidebar-width: 340px;
  --info-panel-width: 280px;
  --nav-height: 48px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
}

/* === Dark theme === */
.dark {
  --bg-primary: #111827;
  --bg-secondary: #1f2937;
  --bg-tertiary: #374151;
  --bg-hover: #374151;
  --bg-active: #431407;
  --border: #374151;
  --border-strong: #4b5563;
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5);
  --success-bg: #052e16;
  --warning-bg: #451a03;
  --danger-bg: #450a0a;
  --info-bg: #172554;
  --accent-light: #431407;
  --msg-operator-bg: #3d3029;
  --msg-operator-text: #e8ddd2;
}

/* === Reset / Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body, input, textarea, select, button {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-secondary);
}

[x-cloak] { display: none !important; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; }
.btn-full { width: 100%; justify-content: center; }

/* === Form elements === */
input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  transition: border-color 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.15);
}
textarea { resize: vertical; }
label { font-size: 13px; font-weight: 500; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.form-group { margin-bottom: 16px; }

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-accent { background: var(--accent); color: #fff; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: var(--bg-tertiary); color: var(--text-secondary); }

/* === Spinner === */
.spinner-sm {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Login page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-secondary);
}
.login-container { text-align: center; }
.login-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 32px;
}
.login-logo h1 { font-size: 22px; color: var(--text-primary); }
.login-form { text-align: left; }
.login-footer { margin-top: 24px; font-size: 12px; color: var(--text-muted); }
.error-message { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* === App layout === */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Navbar */
.navbar {
  display: flex;
  align-items: center;
  height: var(--nav-height);
  padding: 0 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 16px;
  z-index: 100;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.navbar-nav {
  display: flex;
  gap: 4px;
  list-style: none;
}
.navbar-nav .nav-link {
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.navbar-nav .nav-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.navbar-nav .nav-link.active { background: var(--accent-light); color: var(--accent); }
.navbar-spacer { flex: 1; }
.navbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Main content */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border);
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.filter-btn {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
}
.sidebar-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
}
.pagination-label {
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Conversation items */
.conv-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.1s ease;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-active); border-left: 3px solid var(--accent); }
.conv-item.resolved { opacity: 0.6; }
.conv-item.resolved:hover, .conv-item.resolved.active { opacity: 1; }
.conv-item-resolved { flex-shrink: 0; }
.conv-item-header { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 2px; }
.conv-item-name { font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.unread .conv-item-name { font-weight: 700; color: var(--text-primary); }
.conv-item-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; white-space: nowrap; }
.conv-item.unread .conv-item-time { color: var(--accent); font-weight: 600; }
.conv-item-body { display: flex; align-items: center; gap: 8px; }
.conv-item-preview { font-size: 12px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-item.unread .conv-item-preview { color: var(--text-primary); font-weight: 500; }
.conv-item-indicators { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.conv-item-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; }
.conv-item-badges { display: flex; gap: 4px; flex-shrink: 0; }
.conv-item-operator { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.conv-item-icon { font-size: 12px; }
.conv-item-icon.tool-call { color: var(--accent); display: flex; align-items: center; }
.conv-unread-badge {
  min-width: 18px; height: 18px;
  background: var(--accent); color: #fff;
  border-radius: var(--radius-full);
  font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}
.autonomous-badge {
  display: flex; align-items: center; gap: 2px;
  color: var(--info); font-size: 11px; font-weight: 600;
}

/* Content panel */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-secondary);
}
.content-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.content-empty-inner { text-align: center; }
.content-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }

/* Conversation header */
.conv-header {
  padding: 12px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
}
.conv-header-row { display: flex; justify-content: space-between; align-items: center; }
.conv-header-name { font-size: 16px; font-weight: 600; }
.conv-header-actions { display: flex; gap: 6px; }

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

/* x-for wraps items in a div — make it transparent to flex layout */
.messages > div { display: flex; flex-direction: column; gap: 8px; }

.msg-row { display: flex; gap: 8px; max-width: 75%; }
.msg-row.from-user { align-self: flex-start; }
.msg-row.from-operator { align-self: flex-end; flex-direction: row-reverse; }

.msg {
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}
.msg-content { white-space: pre-wrap; }
.msg.from-user { background: var(--bg-tertiary); }
.msg.from-operator { background: var(--msg-operator-bg); color: var(--msg-operator-text); }
.msg.note { background: var(--warning-bg); color: var(--warning); border: 1px dashed var(--warning); }
.msg-sender { font-size: 11px; font-weight: 600; margin-bottom: 2px; opacity: 0.8; }
.msg-time { font-size: 10px; opacity: 0.6; margin-top: 4px; text-align: right; }

/* Tool call card */
.tool-call-card {
  align-self: center;
  background: var(--bg-primary);
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  max-width: 85%;
  box-shadow: var(--shadow-sm);
}
.tool-call-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  flex-wrap: wrap;
}
.tool-call-header .badge {
  font-size: 10px;
  padding: 1px 6px;
}
/* SendMessage tool call — chat-bubble style */
.tool-call-message {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 13px;
  white-space: pre-wrap;
  line-height: 1.5;
  margin-bottom: 8px;
  border-left: 3px solid var(--accent);
}

/* CreatePlannerTask tool call — task card style */
.tool-call-planner {
  border-color: var(--info);
}
.tool-call-planner .tool-call-header { color: var(--info); }
.tool-call-task-preview {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
  border-left: 3px solid var(--info);
}
.tool-call-task-type { margin-bottom: 6px; }
.tool-call-task-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.tool-call-task-desc { font-size: 12px; color: var(--text-secondary); white-space: pre-wrap; line-height: 1.4; }

.tool-call-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 10px;
  font-size: 13px;
  white-space: pre-wrap;
  margin-bottom: 8px;
}
.tool-call-actions { display: flex; gap: 6px; }
.tool-call-meta { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

/* Event messages */
.msg-event {
  align-self: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: var(--radius-full);
}

/* Generating indicator */
.generating-indicator {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--accent-light);
  border: 1px solid var(--accent-subtle);
  border-radius: var(--radius-full);
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

/* Generation failed */
.generation-failed {
  align-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius-lg);
  font-size: 12px;
  color: var(--danger);
  font-weight: 500;
}

/* Typing indicator */
.typing-indicator {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}

/* Message input */
.msg-input-area {
  padding: 12px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
}
.msg-input-row { display: flex; gap: 8px; }
.msg-input-row textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 8px 12px;
}

/* Info panel */
.info-panel {
  width: var(--info-panel-width);
  border-left: 1px solid var(--border);
  background: var(--bg-primary);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 12px;
}
.info-section { margin-bottom: 16px; }
.info-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px; letter-spacing: 0.5px; }
.info-row { display: flex; justify-content: space-between; align-items: center; font-size: 12px; margin-bottom: 4px; }
.info-label { color: var(--text-secondary); }
.info-value { color: var(--text-primary); font-weight: 500; }

/* Date separator */
.date-sep {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 2px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}

/* === Planner board === */
.planner {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 16px;
  overflow-x: auto;
}
.planner-col {
  flex: 1;
  min-width: 280px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
}
.planner-col-header {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.planner-col-count {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 1px 8px;
  border-radius: var(--radius-full);
}
.planner-col-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.planner-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  cursor: grab;
  transition: box-shadow 0.15s ease;
}
.planner-card:hover { box-shadow: var(--shadow-md); }
.planner-card-title { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.planner-card-desc { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.planner-card-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.planner-card-trace {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.trace-code {
  font-family: monospace;
  font-size: 11px;
  background: var(--bg-tertiary);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: text;
  user-select: all;
}
.planner-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}
.planner-card-badge { display: flex; gap: 4px; flex-wrap: wrap; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-body {
  padding: 16px 20px;
}

/* Sort select */
.sort-select {
  width: auto;
  padding: 3px 8px;
  font-size: 11px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
}

/* Tracking milestones */
.tracking-milestones {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 12px;
  padding: 8px 0;
  position: relative;
}
.tracking-milestones::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 8px;
  right: 8px;
  height: 2px;
  background: var(--border);
}
.milestone {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
}
.milestone-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg-primary);
  transition: all 0.2s ease;
}
.milestone.active .milestone-dot {
  background: var(--accent);
}
.milestone.current .milestone-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
  width: 12px;
  height: 12px;
}
.milestone-label {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
  line-height: 1.1;
}
.milestone.active .milestone-label { color: var(--accent); font-weight: 600; }
.milestone.current .milestone-label { color: var(--accent); font-weight: 700; }

.tracking-eta-block {
  background: var(--accent-light);
  border: 1px solid var(--accent-subtle);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  margin: 6px 0;
}
.tracking-items-section {
  margin-top: 8px;
}
.tracking-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tracking-item-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  line-height: 1.3;
}
.tracking-item-qty {
  font-weight: 700;
  color: var(--accent);
}
.tracking-service-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
  line-height: 1.3;
}

/* Settings panel */
.settings-panel {
  max-width: 600px;
  margin: 24px auto;
  padding: 24px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.settings-panel h2 { font-size: 18px; margin-bottom: 20px; }
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text-secondary); }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
}
.toast-card {
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.toast-card strong { font-weight: 600; }

/* Utility */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-4 { gap: 4px; }
.gap-8 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-8 { margin-top: 8px; }
.mb-4 { margin-bottom: 4px; }
.ml-auto { margin-left: auto; }
