/*
  Organaizer UI (CSS puro)
  - Tokens (CSS variables)
  - Componentes (buttons, inputs, cards)
  - Layout (landing/auth/dashboard)
*/

:root {
  color-scheme: light;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);

  --bg0: #07070c;
  --bg1: #0b0b12;
  --card: rgba(255, 255, 255, 0.06);
  --card2: rgba(255, 255, 255, 0.09);
  --stroke: rgba(255, 255, 255, 0.14);
  --stroke2: rgba(255, 255, 255, 0.22);

  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.68);
  --faint: rgba(255, 255, 255, 0.48);

  --accent: #7c3aed;
  --accent2: #22d3ee;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;

  --shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  --shadow2: 0 10px 30px rgba(0, 0, 0, 0.35);

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --space-6: 34px;
  --space-7: 48px;
  --space-8: 72px;

  --container: 1120px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 18% 10%, rgba(124, 58, 237, 0.26), transparent 55%),
    radial-gradient(900px 600px at 85% 20%, rgba(34, 211, 238, 0.20), transparent 60%),
    radial-gradient(900px 700px at 60% 85%, rgba(239, 68, 68, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg0), var(--bg1));
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.stack > * + * { margin-top: var(--space-4); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow2);
  font-weight: 600;
  letter-spacing: 0.2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.2px;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  user-select: none;
  cursor: pointer;
}
.btn:hover { transform: translateY(-1px); border-color: var(--stroke2); background: rgba(255, 255, 255, 0.10); box-shadow: var(--shadow2); }
.btn:active { transform: translateY(0px) scale(0.99); }

.btn-primary {
  border-color: rgba(124, 58, 237, 0.45);
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.95), rgba(34, 211, 238, 0.80));
  color: #0b0b12;
}
.btn-primary:hover { border-color: rgba(34, 211, 238, 0.55); }

.btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.22);
}

.card {
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.04));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.card-inner { padding: clamp(18px, 3vw, 28px); }

.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: var(--space-6);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(14px + var(--safe-area-top)) 0 14px;
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
  background: rgba(7, 7, 12, 0.55);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(14px);
}

.nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 900;
  letter-spacing: 0.3px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 0 0 6px rgba(124, 58, 237, 0.16), 0 0 48px rgba(34, 211, 238, 0.22);
}

.nav-links { display: flex; gap: 10px; align-items: center; }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.hero {
  padding: clamp(36px, 6vw, 76px) 0 clamp(26px, 5vw, 62px);
}

.hero h1 {
  margin: 0;
  font-size: clamp(38px, 5.2vw, 64px);
  line-height: 1.02;
  letter-spacing: -0.8px;
}

.hero p {
  margin: 14px 0 0;
  font-size: clamp(16px, 1.6vw, 20px);
  line-height: 1.5;
  color: var(--muted);
  max-width: 64ch;
}

.hero-cta { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

.panel {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  padding: 14px;
}

.form {
  display: grid;
  gap: 14px;
}

.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

.input, .field input, .field textarea, .field select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(7, 7, 12, 0.55);
  color: var(--text);
  padding: 12px 12px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.input:focus, .field input:focus, .field textarea:focus, .field select:focus {
  border-color: rgba(34, 211, 238, 0.45);
  box-shadow: 0 0 0 6px rgba(34, 211, 238, 0.12);
}

.hint { color: var(--faint); font-size: 13px; line-height: 1.35; }

.flash {
  margin: var(--space-4) 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
}
.flash.notice { border-color: rgba(34, 211, 238, 0.28); }
.flash.alert { border-color: rgba(239, 68, 68, 0.32); }

.reveal {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 520ms ease, transform 520ms ease;
}
.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 920px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}

/* ==============================
   Dashboard Layout
   ============================== */

.dashboard-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: var(--space-5) 0;
  padding-top: calc(var(--space-5) + var(--safe-area-top));
  padding-left: var(--safe-area-left);
  border-right: 1px solid var(--stroke);
  background: rgba(7, 7, 12, 0.70);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--space-5);
  margin-bottom: var(--space-6);
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.3px;
}

.sidebar-section {
  padding: 0 var(--space-3);
  margin-bottom: var(--space-3);
}

.sidebar-label {
  padding: 0 var(--space-3);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: var(--space-2);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  transition: background 120ms ease, color 120ms ease;
  text-decoration: none;
}
.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  text-decoration: none;
}
.sidebar-link--active {
  background: rgba(124, 58, 237, 0.18);
  color: var(--text);
  border: 1px solid rgba(124, 58, 237, 0.25);
}
.sidebar-link--active:hover {
  background: rgba(124, 58, 237, 0.24);
}

.sidebar-link--loading {
  opacity: 0.75;
  cursor: wait;
  pointer-events: none;
}

.sidebar-link--loading .sidebar-icon::after {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 4px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: sidebar-spin 0.6s linear infinite;
  vertical-align: middle;
}

@keyframes sidebar-spin {
  to { transform: rotate(360deg); }
}

.sidebar-icon {
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  font-size: 15px;
}

.sidebar-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--faint);
}

.sidebar-faces {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.sidebar-face-switcher {
  display: flex;
  gap: 2px;
  padding: 0 var(--space-3);
  margin-bottom: var(--space-3);
  flex-shrink: 0;
}

.sidebar-face-btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--faint);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.sidebar-face-btn:hover {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-face-btn--active {
  color: var(--text);
  background: rgba(124, 58, 237, 0.2);
  border-color: rgba(124, 58, 237, 0.35);
}

.sidebar-faces-panels {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  touch-action: pan-y;
}

.sidebar-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  animation: sidebar-panel-fade-in 0.2s ease;
  transition: opacity 0.15s ease;
}

.sidebar-panel--active {
  display: flex;
}

@keyframes sidebar-panel-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.sidebar-advanced {
  margin-top: var(--space-2);
  border-top: 1px solid var(--stroke);
  padding-top: var(--space-2);
}

.sidebar-advanced-summary {
  list-style: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--faint);
  padding: var(--space-2) 0;
  user-select: none;
}

.sidebar-advanced-summary::-webkit-details-marker { display: none; }

.sidebar-advanced-summary:hover {
  color: var(--muted);
}

.sidebar-advanced .sidebar-section {
  padding-top: 0;
}

.sidebar-advanced .sidebar-link {
  padding-left: var(--space-4);
}

.sidebar-frame {
  display: block;
  min-height: 40px;
  transition: background 0.25s ease;
}

.sidebar-frame--updated {
  animation: sidebar-frame-highlight 0.8s ease;
}

@keyframes sidebar-frame-highlight {
  0%, 100% { background: transparent; }
  30% { background: rgba(124, 58, 237, 0.12); }
}

.sidebar-frame-placeholder {
  padding: var(--space-3);
  font-size: 13px;
  color: var(--faint);
}

.sidebar-empty {
  padding: var(--space-3);
  font-size: 13px;
  color: var(--faint);
  margin: 0;
}

.sidebar-spacer { flex: 1; }

.sidebar-footer {
  padding: var(--space-3);
  border-top: 1px solid var(--stroke);
  margin-top: var(--space-3);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: calc(14px + var(--safe-area-top));
  left: calc(14px + var(--safe-area-left));
  z-index: 100;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(7, 7, 12, 0.85);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  backdrop-filter: blur(10px);
}

.main-content {
  padding: var(--space-6) var(--space-6);
  min-height: 100vh;
  max-width: 1100px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-title {
  font-size: 26px;
  font-weight: 950;
  letter-spacing: -0.4px;
  margin: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--faint);
  margin-bottom: var(--space-3);
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb-sep::before { content: "/"; }

/* ==============================
   Data Tables
   ============================== */

.data-table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  min-width: 500px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
}

.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--faint);
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--stroke);
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 14px;
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tr:hover td { background: rgba(255, 255, 255, 0.03); }

.data-table .actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ==============================
   Tags / Status
   ============================== */

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.tag-get { background: rgba(34, 211, 238, 0.15); color: #22d3ee; border: 1px solid rgba(34, 211, 238, 0.25); }
.tag-post { background: rgba(34, 197, 94, 0.15); color: #22c55e; border: 1px solid rgba(34, 197, 94, 0.25); }
.tag-put { background: rgba(245, 158, 11, 0.15); color: #f59e0b; border: 1px solid rgba(245, 158, 11, 0.25); }
.tag-patch { background: rgba(168, 85, 247, 0.15); color: #a855f7; border: 1px solid rgba(168, 85, 247, 0.25); }
.tag-delete { background: rgba(239, 68, 68, 0.15); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.25); }

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  margin-right: 6px;
}
.status-dot--active { background: var(--ok); box-shadow: 0 0 8px rgba(34, 197, 94, 0.4); }
.status-dot--inactive { background: var(--faint); }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
}

/* ==============================
   Modals
   ============================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg1);
  border: 1px solid var(--stroke2);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  max-width: 520px;
  width: 90%;
  box-shadow: var(--shadow);
}

.modal-title {
  font-size: 20px;
  font-weight: 900;
  margin: 0 0 var(--space-4);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: var(--space-5);
}

/* ==============================
   Chat Interface
   ============================== */

/* Chat page: allow full width so the 3-column layout has room (no 1100px cap) */
.main-content:has(.chat-page) {
  max-width: none;
}

.chat-page {
  width: 100%;
  max-width: 100%;
}

.chat-layout {
  display: grid;
  grid-template-columns: 200px 1fr 320px;
  gap: var(--space-4);
  min-height: 0;
  height: calc(100vh - 140px);
  width: 100%;
}

.chat-layout > * {
  min-width: 0;
}

.chat-sidebar-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.02);
  padding: var(--space-3);
  overflow-y: auto;
}

.chat-sidebar-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chat-sidebar-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0;
}

.chat-sidebar-agents {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-sidebar-agent {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--text);
}

.chat-sidebar-agent:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chat-sidebar-agent--active {
  background: rgba(124, 58, 237, 0.2);
  color: var(--accent2);
}

.chat-sidebar-agent .tag--system {
  font-size: 0.7rem;
  padding: 2px 6px;
  background: rgba(124, 58, 237, 0.15);
  color: var(--accent);
  border-radius: 4px;
}

.chat-sidebar-agent .tag--own {
  font-size: 0.7rem;
  padding: 2px 6px;
  background: rgba(34, 197, 94, 0.15);
  color: var(--ok);
  border-radius: 4px;
}

.chat-sidebar-new {
  font-size: 0.85rem;
  color: var(--accent2);
  padding: var(--space-2) 0;
}

.chat-sidebar-conversations {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow-y: auto;
}

.chat-sidebar-conv {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text);
}

.chat-sidebar-conv:hover {
  background: rgba(255, 255, 255, 0.06);
}

.chat-sidebar-conv--active {
  background: rgba(124, 58, 237, 0.2);
  color: var(--accent2);
}

.chat-sidebar-conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.chat-container {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}

.chat-activity-column {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.chat-activity-panel-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--faint);
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--stroke);
  flex-shrink: 0;
}

.chat-activity-panel {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chat-activity-empty {
  font-size: 0.85rem;
  color: var(--faint);
  margin: 0;
  padding: var(--space-2);
}

/* Activity feed widgets: reasoning block */
.chat-activity-reasoning {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
}

.chat-activity-reasoning-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 6px;
}

.chat-activity-reasoning-content {
  font-size: 0.85rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.85);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Activity feed widgets: tool call card */
.chat-activity-tool-card {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chat-activity-tool-card:hover {
  border-color: rgba(124, 58, 237, 0.3);
  background: rgba(255, 255, 255, 0.06);
}

.chat-activity-tool-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.chat-activity-tool-icon {
  font-size: 1rem;
  opacity: 0.9;
}

.chat-activity-tool-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
}

.chat-activity-tool-args {
  font-size: 0.75rem;
  margin-bottom: 8px;
}

.chat-activity-tool-args summary {
  cursor: pointer;
  color: var(--faint);
  user-select: none;
  padding: 4px 0;
  font-weight: 500;
  transition: color 0.15s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-activity-tool-args summary:hover {
  color: rgba(255, 255, 255, 0.6);
}

.chat-activity-tool-args summary::marker {
  content: "";
}

.chat-activity-tool-args summary::before {
  content: "▶";
  display: inline-block;
  font-size: 0.65rem;
  transition: transform 0.2s ease;
  color: var(--faint);
}

.chat-activity-tool-args[open] summary::before {
  transform: rotate(90deg);
}

.chat-activity-tool-args-body {
  margin: 6px 0 0 0;
  padding: 8px;
  font-size: 0.7rem;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(255, 255, 255, 0.8);
}

.chat-activity-tool-status {
  font-size: 0.75rem;
  font-weight: 600;
}

.chat-activity-tool-status--pending {
  color: var(--faint);
}

.chat-activity-tool-status--success {
  color: #86efac;
}

.chat-activity-tool-status--error {
  color: #fca5a5;
}

.chat-activity-tool-result {
  margin: 6px 0 0 0;
  padding: 8px;
  font-size: 0.72rem;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: rgba(255, 255, 255, 0.85);
  max-height: 200px;
  overflow-y: auto;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chat-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-bubble--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.35), rgba(34, 211, 238, 0.20));
  border: 1px solid rgba(124, 58, 237, 0.30);
}

.chat-bubble--assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
}

.chat-bubble--tool {
  align-self: flex-start;
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.20);
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  font-size: 12px;
  max-width: 90%;
}

.chat-bubble--error {
  align-self: flex-start;
  background: rgba(239, 68, 68, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.30);
  color: #fca5a5;
}

.chat-bubble-role {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 4px;
}

.chat-bubble-content {
  line-height: 1.6;
}

.chat-bubble-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}
.chat-bubble-content .chat-bubble-image:last-child {
  margin-bottom: 0;
}

/* ---- Pending image preview (input area) ---- */
.chat-image-preview-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--stroke);
  margin-bottom: 8px;
}
.chat-image-preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
}
.chat-image-preview-remove {
  font-size: 13px;
  padding: 6px 12px;
}

/* ---- Markdown inside chat bubbles ---- */
.chat-bubble-content h1,
.chat-bubble-content h2,
.chat-bubble-content h3 {
  margin: 12px 0 6px 0;
  color: #fff;
  line-height: 1.3;
}
.chat-bubble-content h1 { font-size: 1.15em; }
.chat-bubble-content h2 { font-size: 1.05em; }
.chat-bubble-content h3 { font-size: 0.95em; }
.chat-bubble-content h1:first-child,
.chat-bubble-content h2:first-child,
.chat-bubble-content h3:first-child {
  margin-top: 0;
}

.chat-bubble-content p {
  margin: 0 0 8px 0;
}
.chat-bubble-content p:last-child {
  margin-bottom: 0;
}

.chat-bubble-content ul,
.chat-bubble-content ol {
  margin: 6px 0;
  padding-left: 20px;
}
.chat-bubble-content li {
  margin-bottom: 3px;
}

.chat-bubble-content strong {
  color: #fff;
  font-weight: 700;
}

.chat-bubble-content em {
  color: rgba(255, 255, 255, 0.85);
}

.chat-bubble-content code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  font-size: 0.88em;
  color: var(--accent2);
}

.chat-bubble-content pre {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.chat-bubble-content pre code {
  background: none;
  padding: 0;
  color: var(--accent2);
  font-size: 0.85em;
}

.chat-bubble-content blockquote {
  border-left: 3px solid rgba(124, 58, 237, 0.5);
  margin: 8px 0;
  padding: 4px 12px;
  color: rgba(255, 255, 255, 0.7);
}

.chat-bubble-content table {
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.9em;
  width: 100%;
}
.chat-bubble-content th,
.chat-bubble-content td {
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 5px 10px;
  text-align: left;
}
.chat-bubble-content th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 700;
  color: #fff;
}

.chat-bubble-content hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  margin: 10px 0;
}

.chat-flow-diagram {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--surface, #f5f5f5);
  border-radius: 8px;
  overflow: auto;
}
.chat-flow-diagram-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--muted, #666);
}
.chat-flow-diagram .mermaid {
  display: flex;
  justify-content: center;
}
.chat-flow-diagram .mermaid svg {
  max-width: 100%;
}
.flow-viewer-card .mermaid {
  display: flex;
  justify-content: center;
  min-height: 120px;
}
.flow-viewer-card .mermaid svg {
  max-width: 100%;
}

.chat-bubble-content a {
  color: var(--accent2);
  text-decoration: underline;
}

/* ---- Tool call indicator ---- */
.chat-tool-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--faint);
  padding: 3px 0;
}
.chat-tool-icon {
  font-size: 13px;
  color: var(--accent2);
}
.chat-tool-names {
  font-weight: 700;
  color: var(--accent2);
}

.chat-tool-calls {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-tool-call-name {
  font-size: 12px;
  font-weight: 800;
  color: var(--accent2);
}

.chat-input-area {
  display: flex;
  gap: 10px;
  padding: var(--space-4);
  border-top: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 0 var(--radius-md) 0;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.chat-input-area.chat-drop-over {
  background: rgba(34, 211, 238, 0.08);
  box-shadow: inset 0 0 0 2px rgba(34, 211, 238, 0.35);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.chat-attach-image-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: background 180ms ease;
}

.chat-attach-image-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.chat-attach-image-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.chat-input {
  flex: 1;
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(7, 7, 12, 0.55);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  font-size: 14px;
  resize: none;
}
.chat-input:focus {
  border-color: rgba(34, 211, 238, 0.45);
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.10);
}

.chat-record-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  position: relative;
  transition: all 180ms ease;
}

.chat-record-btn:hover {
  background: rgba(255, 255, 255, 0.08);
}

.chat-record-btn.is-recording {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  animation: recordingPulse 1.5s ease-in-out infinite;
}

.chat-record-btn.is-recording::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: inherit;
  background: rgba(239, 68, 68, 0.3);
  animation: recordingPulse 1.5s ease-in-out infinite;
  z-index: -1;
}

.chat-record-btn.is-processing {
  opacity: 0.6;
  cursor: wait;
  pointer-events: none;
}

.chat-record-btn .recording-timer {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

@keyframes recordingPulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(1.05);
  }
}

.chat-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--faint);
  font-size: 13px;
}

.chat-loading-text {
  white-space: pre-line;
}

.chat-loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent2);
  animation: chatPulse 1.2s ease-in-out infinite;
}
.chat-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatPulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ==============================
   Empty State
   ============================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-5);
  text-align: center;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 900;
  margin: 0 0 var(--space-2);
}

.empty-state-text {
  color: var(--muted);
  font-size: 14px;
  max-width: 400px;
  margin: 0 0 var(--space-5);
}

/* ==============================
   Metric Cards
   ============================== */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}

.metric-card {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  padding: var(--space-5);
  backdrop-filter: blur(8px);
}

.metric-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: var(--space-2);
}

.metric-value {
  font-size: 36px;
  font-weight: 950;
  letter-spacing: -0.5px;
  line-height: 1;
}

.metric-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: var(--space-1);
}

/* ==============================
   JSON Editor
   ============================== */

.json-editor {
  width: 100%;
  min-height: 180px;
  border-radius: var(--radius-md);
  border: 1px solid var(--stroke);
  background: rgba(7, 7, 12, 0.70);
  color: var(--accent2);
  padding: 14px;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  tab-size: 2;
}
.json-editor:focus {
  border-color: rgba(34, 211, 238, 0.40);
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.08);
}
.json-editor.is-invalid {
  border-color: rgba(239, 68, 68, 0.50);
}

.json-editor-hint {
  font-size: 12px;
  margin-top: 4px;
}
.json-editor-hint.is-valid { color: var(--ok); }
.json-editor-hint.is-invalid { color: var(--danger); }

/* ==============================
   Utility classes
   ============================== */

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.flex-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.font-mono { font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace; }
.font-bold { font-weight: 900; }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 999px;
}

.btn-danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(239, 68, 68, 0.50);
}

.btn-success {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.12);
  color: #22c55e;
}

.detail-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: var(--space-2) var(--space-4);
  font-size: 14px;
}

.detail-label {
  font-weight: 800;
  color: var(--faint);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-top: 2px;
}

.detail-value {
  color: var(--text);
  word-break: break-all;
}

.flash-inline {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: var(--space-4);
}
.flash-inline.success { border-color: rgba(34, 197, 94, 0.30); background: rgba(34, 197, 94, 0.08); color: var(--ok); }
.flash-inline.error { border-color: rgba(239, 68, 68, 0.30); background: rgba(239, 68, 68, 0.08); color: var(--danger); }

/* ==============================
   Organaizer Assistant Chat
   ============================== */

.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8) var(--space-5);
  gap: var(--space-3);
}

.chat-welcome-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(124, 58, 237, 0.12);
  border: 1px solid rgba(124, 58, 237, 0.25);
  margin-bottom: var(--space-2);
}

.chat-welcome-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.chat-welcome-text {
  font-size: 14px;
  color: var(--muted);
  max-width: 440px;
  line-height: 1.6;
}

.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  margin-top: var(--space-4);
  width: 100%;
  max-width: 500px;
}

.chat-suggestion-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 180ms ease;
  text-align: left;
  font-family: inherit;
}

.chat-suggestion-btn:hover {
  background: var(--card2);
  border-color: var(--stroke2);
  color: var(--text);
  transform: translateY(-1px);
}

.sidebar-link--organaizer {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.08), rgba(34, 211, 238, 0.06));
  border: 1px solid rgba(124, 58, 237, 0.15);
  border-radius: var(--radius-sm);
}

.sidebar-link--organaizer:hover {
  background: linear-gradient(135deg, rgba(124, 58, 237, 0.16), rgba(34, 211, 238, 0.10));
  border-color: rgba(124, 58, 237, 0.30);
}

.system-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent2);
  background: rgba(34, 211, 238, 0.10);
  border: 1px solid rgba(34, 211, 238, 0.25);
  border-radius: 999px;
}

/* ==============================
   Responsive
   ============================== */

@media (max-width: 920px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }

  .dashboard-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 270px;
    z-index: 50;
    transition: left 200ms ease;
  }
  .sidebar.is-open { left: 0; }
  .sidebar.is-open + .sidebar-overlay { display: block; }
  .sidebar-toggle { display: block; }
  .main-content {
    padding: var(--space-5) var(--space-4);
    padding-top: calc(60px + var(--safe-area-top));
    padding-left: calc(var(--space-4) + var(--safe-area-left));
    padding-right: calc(var(--space-4) + var(--safe-area-right));
  }
  .detail-grid { grid-template-columns: 1fr; }

  .sidebar-face-btn {
    min-height: 44px;
    padding: 10px 8px;
  }

  .btn {
    min-height: 44px;
    min-width: 44px;
  }
  .btn-sm {
    min-height: 44px;
    padding: 10px 14px;
  }
  .sidebar-link {
    min-height: 44px;
    padding: 12px var(--space-3);
  }
  .breadcrumb a {
    padding: 10px 4px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
  .data-table .actions {
    gap: 12px;
  }
  .data-table .actions a,
  .data-table .actions button {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .chat-input-area {
    padding-left: calc(var(--space-4) + var(--safe-area-left));
    padding-right: calc(var(--space-4) + var(--safe-area-right));
    padding-bottom: calc(var(--space-4) + var(--safe-area-bottom));
  }
  .chat-messages {
    padding-bottom: calc(var(--space-5) + var(--safe-area-bottom));
  }
  .chat-suggestion-btn {
    min-height: 44px;
  }
  .chat-record-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 140px);
  }
  .chat-sidebar-panel,
  .chat-container,
  .chat-activity-column {
    min-width: 0;
  }
  .chat-activity-column {
    min-height: 280px;
  }

  .field input,
  .field textarea,
  .field select,
  .input {
    font-size: 16px;
  }
  .card-inner {
    padding: clamp(14px, 2.5vw, 24px);
  }
  .form {
    gap: 18px;
  }
}

@media (max-width: 768px) {
  .main-content { padding-left: calc(var(--space-4) + var(--safe-area-left)); padding-right: calc(var(--space-4) + var(--safe-area-right)); }

  .nav-row { position: relative; }
  .nav-toggle { display: flex; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0;
    padding: var(--space-2);
    margin-top: var(--space-2);
    background: rgba(7, 7, 12, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
  }
  .nav.is-open .nav-links { display: flex; }
  .nav-links .btn, .nav-links .btn-ghost, .nav-links .btn-primary {
    justify-content: center;
    min-height: 44px;
    width: 100%;
  }
}

@media (max-width: 560px) {
  .grid-4 { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 400px) {
  .container { padding-left: var(--space-3); padding-right: var(--space-3); }
  .main-content { padding-left: calc(var(--space-3) + var(--safe-area-left)); padding-right: calc(var(--space-3) + var(--safe-area-right)); }

  .modal-content {
    width: calc(100% - var(--space-4));
    max-width: none;
    margin: var(--space-2);
    border-radius: var(--radius);
  }
  .modal-actions .btn,
  .modal-actions button {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn, .reveal, .input, .field input { transition: none !important; }
  .btn:hover { transform: none; }
  .sidebar { transition: none !important; }
  .chat-loading-dot { animation: none; opacity: 0.5; }
}
