/* shadcn-style theme tokens + dashboard shell layout.
 *
 * Keeps Tailwind CDN as the utility engine, but layers shadcn-flavoured
 * design tokens (CSS vars) and a sidebar+header chrome on top. Each
 * dashboard page links this file once.
 */

:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --ring: 240 5.9% 10%;
  --destructive: 0 72% 51%;
  --destructive-foreground: 0 0% 98%;
  --brand: 158 64% 40%;          /* emerald-600 — TalkHQ accent */
  --brand-foreground: 0 0% 100%;
  --brand-soft: 152 76% 96%;     /* emerald-50 */
  --warning: 38 92% 50%;         /* amber-500 */
  --warning-soft: 48 96% 89%;    /* amber-100 */
  --radius: 0.625rem;
  --sidebar-w: 16rem;
}

html, body {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- shell layout ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 3.5rem 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}

@media (max-width: 768px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .shell > .sidebar { display: none; }
  .shell.sidebar-open > .sidebar {
    display: flex;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: 16rem;
    background: hsl(var(--card));
    border-right: 1px solid hsl(var(--border));
  }
  .shell.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 30;
  }
}

.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  background: hsl(var(--card));
  border-right: 1px solid hsl(var(--border));
  padding: 1rem 0.75rem;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem 1rem 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  color: hsl(var(--foreground));
  text-decoration: none;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: 0.5rem;
}

.sidebar-brand-mark {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.375rem;
  background: hsl(var(--brand));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: hsl(var(--brand-foreground));
  font-weight: 700;
  font-size: 0.75rem;
}

.sidebar-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
  padding: 0.75rem 0.5rem 0.25rem 0.5rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  text-decoration: none;
  border-radius: 0.5rem;
  line-height: 1.25rem;
}

.sidebar-link:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.sidebar-link.is-active {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
  font-weight: 500;
}

.sidebar-link svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: hsl(var(--muted-foreground));
}

.sidebar-link.is-active svg {
  color: hsl(var(--foreground));
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.5rem;
  border-top: 1px solid hsl(var(--border));
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.sidebar-footer .email {
  display: block;
  word-break: break-all;
  color: hsl(var(--foreground));
  font-weight: 500;
  margin-bottom: 0.5rem;
}

/* ---------- top bar ---------- */

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: hsl(var(--background));
  border-bottom: 1px solid hsl(var(--border));
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-toggle {
  display: none;
  background: transparent;
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  padding: 0.375rem;
  color: hsl(var(--foreground));
  cursor: pointer;
}

.topbar-toggle svg { width: 1rem; height: 1rem; }

@media (max-width: 768px) {
  .topbar-toggle { display: inline-flex; }
}

.topbar-breadcrumb {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-breadcrumb .current {
  color: hsl(var(--foreground));
  font-weight: 500;
}

.topbar-breadcrumb a {
  color: hsl(var(--muted-foreground));
  text-decoration: none;
}

.topbar-breadcrumb a:hover { color: hsl(var(--foreground)); }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---------- main content area ---------- */

.main {
  grid-area: main;
  padding: 1.5rem;
  background: hsl(var(--muted) / 0.4);
  min-width: 0; /* allow tables to shrink */
}

@media (min-width: 1024px) {
  .main { padding: 2rem 2.5rem; }
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: hsl(var(--foreground));
  line-height: 1.2;
}

.page-subtitle {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

/* ---------- card primitives ---------- */

.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card + .card { margin-top: 1rem; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  letter-spacing: -0.01em;
}

.card-description {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.125rem;
}

.card-eyebrow {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: hsl(var(--muted-foreground));
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1;
  height: 2.25rem;
  padding: 0 0.875rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.btn-primary:hover:not(:disabled) {
  background: hsl(var(--primary) / 0.9);
}

.btn-brand {
  background: hsl(var(--brand));
  color: hsl(var(--brand-foreground));
}

.btn-brand:hover:not(:disabled) {
  background: hsl(var(--brand) / 0.9);
}

.btn-outline {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}

.btn-outline:hover:not(:disabled) {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
}

.btn-ghost:hover:not(:disabled) {
  background: hsl(var(--accent));
}

.btn-destructive {
  background: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}

.btn-sm {
  height: 1.875rem;
  padding: 0 0.625rem;
  font-size: 0.75rem;
  border-radius: 0.375rem;
}

/* ---------- input ---------- */

.input {
  display: block;
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  font-size: 0.875rem;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--input));
  border-radius: 0.5rem;
  line-height: 1.25rem;
}

.input:focus {
  outline: 2px solid hsl(var(--ring));
  outline-offset: -1px;
  border-color: hsl(var(--ring));
}

.label {
  font-size: 0.75rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  display: block;
  margin-bottom: 0.375rem;
}

.field-help {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.375rem;
}

/* ---------- badge ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 500;
  border-radius: 9999px;
  border: 1px solid transparent;
  line-height: 1.25;
}

.badge-secondary {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.badge-success {
  background: hsl(var(--brand) / 0.12);
  color: hsl(var(--brand));
  border-color: hsl(var(--brand) / 0.25);
}

.badge-warning {
  background: hsl(var(--warning) / 0.12);
  color: hsl(38 92% 35%);
  border-color: hsl(var(--warning) / 0.3);
}

.badge-destructive {
  background: hsl(var(--destructive) / 0.12);
  color: hsl(var(--destructive));
  border-color: hsl(var(--destructive) / 0.3);
}

.badge-outline {
  background: hsl(var(--background));
  color: hsl(var(--muted-foreground));
  border-color: hsl(var(--border));
}

/* ---------- table ---------- */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table thead th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: hsl(var(--muted-foreground));
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
}

.table tbody td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
  vertical-align: top;
}

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

.table-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  overflow: hidden;
}

/* ---------- KPI ---------- */

.kpi {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}

.kpi-label {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  font-weight: 500;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: hsl(var(--foreground));
  line-height: 1.1;
}

.kpi-hint {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.kpi-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 768px) {
  .kpi-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- list-row (clickable list item) ---------- */

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid hsl(var(--border));
  border-radius: 0.5rem;
  background: hsl(var(--card));
  text-decoration: none;
  color: hsl(var(--foreground));
}

.list-row + .list-row { margin-top: 0.5rem; }

.list-row:hover {
  background: hsl(var(--accent));
  border-color: hsl(var(--ring) / 0.2);
}

/* ---------- alerts / toasts ---------- */

.alert {
  border-radius: 0.5rem;
  border: 1px solid hsl(var(--border));
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  background: hsl(var(--card));
}

.alert-success {
  background: hsl(var(--brand) / 0.08);
  border-color: hsl(var(--brand) / 0.3);
  color: hsl(var(--brand));
}

.alert-warning {
  background: hsl(var(--warning) / 0.1);
  border-color: hsl(var(--warning) / 0.35);
  color: hsl(38 92% 30%);
}

.alert-destructive {
  background: hsl(var(--destructive) / 0.08);
  border-color: hsl(var(--destructive) / 0.3);
  color: hsl(var(--destructive));
}

/* ---------- empty state ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1rem;
  border: 1px dashed hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--muted) / 0.4);
  color: hsl(var(--muted-foreground));
  gap: 0.25rem;
}

.empty-title {
  color: hsl(var(--foreground));
  font-weight: 500;
  font-size: 0.875rem;
}

.empty-hint { font-size: 0.75rem; }

/* ---------- utility ---------- */

.muted { color: hsl(var(--muted-foreground)); }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; }
.brand-text { color: hsl(var(--brand)); }

/* Hide elements until shell hydrates */
[hidden] { display: none !important; }
