:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --sand: #F1EAE0;
  --border: #E5DCD0;
  --taupe: #7A6E63;
  --ink: #1C1917;
  --gold: #B68D40;
  --gold-soft: rgba(182, 141, 64, 0.14);
  --danger: #B91C1C;
  --ok: #15803D;
  --warn: #B45309;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(28, 25, 23, 0.05);
}

[data-theme="dark"] {
  --bg: #141210;
  --surface: #1E1B18;
  --sand: #28231F;
  --border: #352F29;
  --taupe: #A89B8E;
  --ink: #F5F0E8;
  --gold: #D4AF63;
  --gold-soft: rgba(212, 175, 99, 0.16);
  --danger: #EF4444;
  --ok: #22C55E;
  --warn: #F59E0B;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--taupe); font-size: 0.9rem; }
.error-text { color: var(--danger); font-size: 0.88rem; margin: 8px 0; }

/* Login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px; box-shadow: var(--shadow); text-align: center;
}
.brand-mark {
  width: 52px; height: 52px; border-radius: 14px; background: linear-gradient(135deg, var(--ink), var(--gold));
  color: #FAF7F2; font-weight: 700; font-size: 1.5rem; display: inline-flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.brand-mark.small { width: 36px; height: 36px; font-size: 1.05rem; margin-bottom: 0; }
.login-card form { text-align: left; margin-top: 20px; display: flex; flex-direction: column; gap: 14px; }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand-row { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-title { font-weight: 700; font-size: 1.05rem; }
.brand-sub { font-size: 0.78rem; color: var(--gold); font-weight: 600; }
.nav-list { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item {
  text-align: left; background: transparent; border: none; color: var(--taupe);
  padding: 10px 14px; border-radius: 11px; font-size: 0.94rem; font-weight: 500; cursor: pointer;
}
.nav-item:hover { background: var(--sand); color: var(--ink); }
.nav-item.active { background: var(--gold-soft); color: var(--ink); font-weight: 600; }
.sidebar-footer { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 28px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10;
}
.topbar h2 { margin: 0 12px 0 0; display: inline; font-size: 1.3rem; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.view-container { padding: 24px 28px 80px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* Cards & Grid */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 1.02rem; }
.stat-val { font-size: 1.65rem; font-weight: 700; margin: 4px 0; }

/* Inputs & Buttons */
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; font-weight: 500; }
input, textarea, select {
  background: var(--bg); color: var(--ink); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font: inherit; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn.gold { background: var(--gold); color: #fff; border-color: var(--gold); }
.btn.danger { background: rgba(185, 28, 28, 0.1); color: var(--danger); border-color: rgba(185, 28, 28, 0.3); }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Pills */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.76rem; font-weight: 600; }
.pill.ok { background: rgba(21, 128, 61, 0.14); color: var(--ok); }
.pill.warn { background: rgba(180, 83, 9, 0.15); color: var(--warn); }
.pill.danger { background: rgba(185, 28, 28, 0.15); color: var(--danger); }
.pill.muted-pill { background: var(--sand); color: var(--taupe); }

/* Chat & Browser */
.chat-box { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin: 12px 0; padding: 12px; background: var(--bg); border-radius: 12px; border: 1px solid var(--border); }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 85%; white-space: pre-wrap; font-size: 0.9rem; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--ink); color: var(--bg); }
.msg.agent { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }

.browser-stage {
  background: #000; border-radius: 14px; overflow: hidden; border: 1px solid var(--border);
  position: relative; min-height: 360px; display: flex; align-items: center; justify-content: center;
}
.browser-stage img { width: 100%; height: auto; display: block; cursor: crosshair; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--taupe); font-weight: 600; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: var(--bg);
  padding: 12px 18px; border-radius: 12px; font-size: 0.9rem; z-index: 999; box-shadow: var(--shadow);
}

/* Mobile */
.mobile-nav { display: none; }
@media (max-width: 860px) {
  .sidebar { display: none; }
  .topbar { padding: 14px 16px; }
  .view-container { padding: 16px 14px 86px; }
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--border); padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    justify-content: space-around; z-index: 50;
  }
  .mobile-nav button {
    background: none; border: none; color: var(--taupe); font-size: 0.78rem; font-weight: 600; padding: 6px 10px; border-radius: 8px;
  }
  .mobile-nav button.active { background: var(--gold-soft); color: var(--ink); }
}
