/* CallBuddy — modern minimal UI with dark & light themes.
   Theme is set via <html data-theme="dark|light">. */

:root {
  --radius: 12px;
  --radius-sm: 9px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #e5e8ed;
  --text: #16181d;
  --muted: #69707d;
  --accent: #5b5bd6;
  --accent-soft: rgba(91, 91, 214, .09);
  --accent-contrast: #ffffff;
  --green: #1a7f37;
  --green-soft: rgba(26, 127, 55, .1);
  --red: #d1242f;
  --red-soft: rgba(209, 36, 47, .08);
  --amber: #9a6700;
  --amber-soft: rgba(154, 103, 0, .1);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, .1);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1014;
  --panel: #15171d;
  --panel-2: #1c1f26;
  --border: #262a32;
  --text: #e8eaee;
  --muted: #969eab;
  --accent: #818cf8;
  --accent-soft: rgba(129, 140, 248, .12);
  --accent-contrast: #0e1014;
  --green: #4ace64;
  --green-soft: rgba(74, 206, 100, .12);
  --red: #f47067;
  --red-soft: rgba(244, 112, 103, .12);
  --amber: #d9a948;
  --amber-soft: rgba(217, 169, 72, .12);
  --shadow: none;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  -webkit-font-smoothing: antialiased;
  transition: background .15s ease, color .15s ease;
}
a { color: var(--accent); text-decoration: none; }

.layout { display: flex; min-height: 100vh; }
body.auth .sidebar { display: none; }
body.auth .main { max-width: none; padding: 0; }

.sidebar {
  width: 230px; flex-shrink: 0; border-right: 1px solid var(--border);
  padding: 20px 14px 16px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; background: var(--panel);
}
.logo { font-size: 16.5px; font-weight: 700; padding: 2px 10px 20px; letter-spacing: -.02em; }
.logo .dot { color: var(--accent); }
.nav-group { margin-bottom: 18px; }
.nav-label { font-size: 11px; color: var(--muted); padding: 0 10px 7px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7.5px 10px;
  border-radius: var(--radius-sm); color: var(--muted); margin-bottom: 1px; font-weight: 500;
}
.nav a svg { width: 15px; height: 15px; opacity: .75; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a.active svg { opacity: 1; }
.nav a:hover:not(.active) { background: var(--panel-2); color: var(--text); }
.sidebar .foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.balance-chip {
  display: flex; justify-content: space-between; align-items: center; cursor: pointer;
  background: var(--panel-2); border-radius: var(--radius-sm);
  padding: 8px 10px; margin-bottom: 10px; font-size: 12.5px;
}
.balance-chip strong { color: var(--accent); }
.foot-row { display: flex; gap: 8px; align-items: center; }
.foot-row .btn { flex: 1; }

.theme-toggle {
  width: 34px; height: 30px; flex: none; display: inline-flex; align-items: center;
  justify-content: center; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--text); border-color: var(--muted); }
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle.floating { position: fixed; top: 18px; right: 18px; background: var(--panel); z-index: 10; }

.main { flex: 1; padding: 28px 40px; max-width: 1080px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 12px; }
h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; font-weight: 650; }
h2 { font-size: 13px; margin: 26px 0 10px; color: var(--muted); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-weight: 550; cursor: pointer; font-size: 13px; font-family: inherit;
  box-shadow: var(--shadow);
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: default; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
th { color: var(--muted); font-size: 12px; font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card.flush { padding: 0; overflow: hidden; }
.empty { color: var(--muted); padding: 36px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat .value { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.stat .sub { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

.badge {
  display: inline-block; padding: 2.5px 9px; border-radius: 999px; font-size: 11.5px;
  font-weight: 550; background: var(--panel-2); color: var(--muted);
}
.badge.green { color: var(--green); background: var(--green-soft); }
.badge.red { color: var(--red); background: var(--red-soft); }
.badge.amber { color: var(--amber); background: var(--amber-soft); }
.badge.blue, .badge.accent { color: var(--accent); background: var(--accent-soft); }

label { display: block; margin: 12px 0 4px; font-size: 12px; color: var(--muted); font-weight: 550; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 13.5px; font-family: inherit;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; margin-right: 16px; color: var(--text); font-weight: 500; font-size: 13px; }
.checks input { width: auto; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; width: min(560px, 92vw); max-height: 88vh; overflow: auto;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(9, 11, 15, .55); backdrop-filter: blur(2px); }
dialog h1 { font-size: 16px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* tabs (assistant editor) */
.tabs {
  display: inline-flex; gap: 2px; background: var(--panel-2); border-radius: var(--radius-sm);
  padding: 3px; margin-bottom: 18px;
}
.tabs button {
  background: none; border: 0; color: var(--muted); font: inherit; font-weight: 550;
  padding: 6.5px 14px; cursor: pointer; border-radius: 7px; font-size: 13px;
}
.tabs button.active { color: var(--text); background: var(--panel); box-shadow: var(--shadow); }

/* estimate chips on assistant page */
.estimates { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.estimate-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel);
  font-size: 12.5px; color: var(--muted); box-shadow: var(--shadow);
}
.estimate-chip strong { color: var(--text); font-weight: 650; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv div:nth-child(odd) { color: var(--muted); }

.bubble { padding: 10px 14px; border-radius: 14px; margin: 6px 0; max-width: 78%; white-space: pre-wrap; }
.bubble.user { background: var(--panel-2); margin-right: auto; border-bottom-left-radius: 4px; }
.bubble.assistant { background: var(--accent-soft); color: var(--text); margin-left: auto; border-bottom-right-radius: 4px; }
.bubble.tool { background: var(--panel); border: 1px dashed var(--border); font-family: ui-monospace, monospace; font-size: 12.5px; }
.bubble .meta { font-size: 11px; opacity: .7; margin-top: 4px; }

.metric-good { color: var(--green); }
.metric-bad { color: var(--red); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12.5px; }
.error-bar { background: var(--red-soft); border: 1px solid var(--red); color: var(--red); padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.pulse { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-right: 7px; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* auth screens */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 24px; }
.auth-card {
  width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px; box-shadow: var(--shadow-lg);
}
.auth-logo { font-size: 21px; font-weight: 700; text-align: center; margin-bottom: 4px; letter-spacing: -.02em; }
.auth-sub { color: var(--muted); text-align: center; margin: 0 0 16px; font-size: 13px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0 4px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.oauth-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-weight: 550; cursor: pointer; font-size: 13.5px; font-family: inherit;
  box-shadow: var(--shadow);
}
.oauth-btn:hover { background: var(--panel-2); }
