:root {
  --bg: #f5f6f8; --card: #fff; --text: #1f2933; --muted: #6b7280;
  --border: #e5e7eb; --primary: #0f766e; --danger: #b91c1c;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
header.app-nav { display: flex; gap: 4px; align-items: center; padding: 12px 20px; background: #0f172a; color: #fff; flex-wrap: wrap; }
header.app-nav .brand { font-weight: 700; margin-right: 16px; }
header.app-nav a { color: #cbd5e1; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
header.app-nav a.active, header.app-nav a:hover { background: #1e293b; color: #fff; }
header.app-nav nav.links { display: flex; gap: 4px; flex-wrap: wrap; }
header.app-nav .nav-logout { margin-left: auto; background: #1e293b; color: #e2e8f0; padding: 7px 12px; }
header.app-nav .nav-logout:hover { background: #334155; }
main { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); margin-bottom: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
button { padding: 9px 14px; border: 0; border-radius: 8px; background: var(--primary); color: #fff; font: inherit; cursor: pointer; }
button.secondary { background: #e2e8f0; color: #0f172a; }
button.danger { background: var(--danger); }
button:disabled { opacity: .6; cursor: not-allowed; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #e2e8f0; }
.badge.in { background: #dcfce7; color: #166534; }
.badge.out { background: #fee2e2; color: #991b1b; }
.empty { color: var(--muted); padding: 12px 0; }
#toast { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; }
#toast div { background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 340px; }
#toast div.error { background: var(--danger); }
dialog { border: 0; border-radius: 12px; padding: 20px; width: min(520px, 92vw); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.hint { color: var(--muted); font-size: 13px; }

.log { display: grid; gap: 10px; margin-bottom: 16px; max-height: 58vh; overflow-y: auto; padding-right: 4px; min-width: 0; }
.msg { padding: 12px 14px; border-radius: 10px; font-size: 14px; min-width: 0; overflow-wrap: anywhere; }
.msg.user { background: #d1fae5; margin-left: auto; max-width: 85%; white-space: pre-wrap; }
.msg.ai { background: #f8fafc; border: 1px solid var(--border); }
.msg.pending { color: var(--muted); font-style: italic; background: #f8fafc; border: 1px dashed var(--border); }
.msg.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.msg .answer { white-space: normal; }
.msg .answer p { margin: 0 0 8px; }
.msg .answer ul { margin: 0 0 8px; padding-left: 20px; }
.msg .answer h3 { font-size: 15px; margin: 10px 0 6px; }
.msg .answer code { background: #e2e8f0; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg .meta { color: var(--muted); font-size: 12px; margin-top: 8px; }
.msg details { margin-top: 10px; }
.msg summary { cursor: pointer; color: var(--primary); font-size: 13px; }
.msg pre.sql { background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 8px; font-size: 12px;
  white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }
.tablewrap { overflow-x: auto; margin-top: 8px; max-width: 100%; }
.tablewrap table { min-width: 100%; }
#ask-form { margin-top: 12px; }
#ask-form label { margin-top: 4px; }
#mic.recording { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
