:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #23263a;
  --border: #2e3148;
  --accent: #6c63ff;
  --accent-hover: #5a52e0;
  --text: #e8e9f0;
  --text-dim: #8b8fa8;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --radius: 10px;
  --font: system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Nav ─────────────────────────────────────────────────── */
nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 52px;
  gap: 1.5rem;
}
nav .logo { font-weight: 700; font-size: 1.05rem; color: var(--text); margin-right: auto; }
nav a { color: var(--text-dim); font-size: 0.9rem; }
nav a.active, nav a:hover { color: var(--text); }
nav .logout-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 0.9rem;
}
nav .logout-btn:hover { color: var(--red); }

/* ── Page wrapper ─────────────────────────────────────────── */
.page { flex: 1; display: flex; flex-direction: column; max-width: 900px;
        width: 100%; margin: 0 auto; padding: 1.5rem; }

/* ── Auth page ────────────────────────────────────────────── */
.auth-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem; width: 360px;
}
.auth-card h1 { font-size: 1.3rem; margin-bottom: 1.5rem; }
.auth-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
.auth-tab {
  flex: 1; padding: 0.5rem; border: 1px solid var(--border);
  border-radius: 6px; background: none; color: var(--text-dim);
  cursor: pointer; font-size: 0.9rem;
}
.auth-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Form elements ────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: 0.82rem; color: var(--text-dim); margin-bottom: 0.35rem; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 0.6rem 0.75rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 0.9rem;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.55rem 1.1rem; border-radius: 6px;
  font-size: 0.9rem; cursor: pointer; border: none; font-weight: 500;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: none; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: none; border: 1px solid var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

.error-msg { color: var(--red); font-size: 0.82rem; margin-top: 0.75rem; }

/* ── Chat ─────────────────────────────────────────────────── */
#chat-page { display: flex; flex-direction: column; height: calc(100vh - 52px); }

.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem 0;
  display: flex; flex-direction: column; gap: 0.75rem;
}

.bubble {
  max-width: 75%; padding: 0.7rem 1rem;
  border-radius: var(--radius); line-height: 1.55;
  font-size: 0.9rem; white-space: pre-wrap; word-break: break-word;
}
.bubble.user {
  background: var(--accent); color: #fff; align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.bubble.agent {
  background: var(--surface); border: 1px solid var(--border);
  align-self: flex-start; border-bottom-left-radius: 3px;
}
.bubble.agent.streaming { opacity: 0.85; }

/* Tool call / result disclosure */
.tool-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 6px; font-size: 0.78rem; overflow: hidden;
  align-self: flex-start; max-width: 80%;
}
.tool-card-header {
  padding: 0.4rem 0.75rem; display: flex; align-items: center;
  gap: 0.5rem; cursor: pointer; user-select: none; color: var(--text-dim);
}
.tool-card-header .tool-name { color: var(--yellow); font-weight: 600; }
.tool-card-body { padding: 0.5rem 0.75rem; display: none; }
.tool-card-body pre {
  font-size: 0.75rem; color: var(--text-dim); overflow-x: auto;
  white-space: pre-wrap; word-break: break-word;
}
.tool-card.open .tool-card-body { display: block; }

/* Approval widget */
.approval-card {
  background: var(--surface); border: 1px solid var(--yellow);
  border-radius: var(--radius); padding: 1rem; align-self: flex-start;
  max-width: 80%; font-size: 0.87rem;
}
.approval-card h4 { color: var(--yellow); margin-bottom: 0.5rem; }
.approval-card pre {
  white-space: pre-wrap; font-size: 0.8rem; color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.approval-btns { display: flex; gap: 0.5rem; }

/* Chat input */
.chat-input-row {
  display: flex; gap: 0.5rem; padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}
.chat-input-row textarea {
  flex: 1; resize: none; height: 44px; line-height: 1.4;
  padding: 0.6rem 0.75rem; font-family: var(--font);
}
.chat-input-row .send-btn { align-self: flex-end; height: 44px; padding: 0 1.1rem; }

/* ── Settings ─────────────────────────────────────────────── */
.settings-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem;
}
.settings-section h3 { font-size: 0.95rem; margin-bottom: 1rem; color: var(--text-dim); }
.location-detected { font-size: 0.88rem; color: var(--green); margin: 0.5rem 0; }

/* ── Reports ──────────────────────────────────────────────── */
.period-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.25rem; }
.period-tab {
  padding: 0.4rem 0.85rem; border-radius: 20px; font-size: 0.82rem;
  border: 1px solid var(--border); background: none; color: var(--text-dim); cursor: pointer;
}
.period-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.report-summary {
  display: flex; gap: 1.5rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.stat-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.75rem 1rem; min-width: 140px;
}
.stat-box .stat-label { font-size: 0.75rem; color: var(--text-dim); margin-bottom: 0.25rem; }
.stat-box .stat-value { font-size: 1.2rem; font-weight: 600; }

/* ── Table ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; color: var(--text-dim); font-weight: 500;
     padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.empty-msg { color: var(--text-dim); font-size: 0.88rem; text-align: center;
             padding: 2rem 0; }

/* ── Status dot ───────────────────────────────────────────── */
.dot { display: inline-block; width: 8px; height: 8px;
       border-radius: 50%; margin-right: 0.4rem; }
.dot.connected { background: var(--green); }
.dot.disconnected { background: var(--red); }
