@import url('https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap');

/* ---- Niadi CRM Design Tokens (Light Default & Dark Class/System) ---- */
:root {
  color-scheme: light;
  --brand: #2878f0;
  --brand-hover: #1d68d8;
  --brand-foreground: #ffffff;
  --brand-light: #e8f1fd;
  --brand-muted: rgba(40, 120, 240, 0.12);

  --background: #fafafa;
  --foreground: #171717;
  --card: #ffffff;
  --card-foreground: #171717;
  --popover: #ffffff;
  --popover-foreground: #171717;
  --muted: #f5f5f5;
  --muted-foreground: #737373;
  --accent-surface: #f5f5f5;
  --accent-foreground: #262626;
  --destructive: #dc2626;
  --destructive-bg: rgba(220, 38, 38, 0.1);
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --input: #e5e5e5;
  --ring: #2878f0;

  --sidebar: #f7f7f7;
  --sidebar-foreground: #171717;
  --sidebar-accent: #efefef;
  --sidebar-accent-foreground: #262626;
  --sidebar-border: #e5e5e5;

  --success: #16a34a;
  --success-bg: rgba(22, 163, 74, 0.12);
  --warning: #d97706;
  --warning-bg: rgba(217, 119, 6, 0.12);

  --radius: 0.625rem;
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
  --topbar-bg: rgba(250, 250, 250, 0.85);

  /* Compatibility aliases */
  --bg: var(--background);
  --surface: var(--card);
  --surface-2: var(--muted);
  --border-2: var(--border-strong);
  --text: var(--foreground);
  --accent: var(--brand);
  --accent-hover: var(--brand-hover);
  --accent-soft: var(--brand-muted);
  --ok: var(--success);
  --ok-bg: var(--success-bg);
  --danger: var(--destructive);
  --danger-bg: var(--destructive-bg);
  --warn: var(--warning);
  --warn-bg: var(--warning-bg);
}

html.dark {
  color-scheme: dark;
  --brand: #3288ff;
  --brand-hover: #4d9aff;
  --brand-foreground: #ffffff;
  --brand-light: #172554;
  --brand-muted: rgba(50, 136, 255, 0.15);

  --background: #141414;
  --foreground: #fafafa;
  --card: #1f1f1f;
  --card-foreground: #fafafa;
  --popover: #262626;
  --popover-foreground: #fafafa;
  --muted: #262626;
  --muted-foreground: #a3a3a3;
  --accent-surface: #2e2e2e;
  --accent-foreground: #fafafa;
  --destructive: #ef4444;
  --destructive-bg: rgba(239, 68, 68, 0.15);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.18);
  --input: rgba(255, 255, 255, 0.14);
  --ring: #3288ff;

  --sidebar: #1a1a1a;
  --sidebar-foreground: #fafafa;
  --sidebar-accent: #292929;
  --sidebar-accent-foreground: #fafafa;
  --sidebar-border: rgba(255, 255, 255, 0.1);

  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.15);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
  --topbar-bg: rgba(20, 20, 20, 0.85);
}

@media (prefers-color-scheme: dark) {
  html:not(.light) {
    color-scheme: dark;
    --brand: #3288ff;
    --brand-hover: #4d9aff;
    --brand-foreground: #ffffff;
    --brand-light: #172554;
    --brand-muted: rgba(50, 136, 255, 0.15);

    --background: #141414;
    --foreground: #fafafa;
    --card: #1f1f1f;
    --card-foreground: #fafafa;
    --popover: #262626;
    --popover-foreground: #fafafa;
    --muted: #262626;
    --muted-foreground: #a3a3a3;
    --accent-surface: #2e2e2e;
    --accent-foreground: #fafafa;
    --destructive: #ef4444;
    --destructive-bg: rgba(239, 68, 68, 0.15);
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --input: rgba(255, 255, 255, 0.14);
    --ring: #3288ff;

    --sidebar: #1a1a1a;
    --sidebar-foreground: #fafafa;
    --sidebar-accent: #292929;
    --sidebar-accent-foreground: #fafafa;
    --sidebar-border: rgba(255, 255, 255, 0.1);

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.15);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.15);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.25);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
    --topbar-bg: rgba(20, 20, 20, 0.85);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code, pre, .mono {
  font-family: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.tabular, td, .kpi-value, .bar-val, .meter-text {
  font-variant-numeric: tabular-nums;
}

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

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.5rem;
  background: var(--brand);
  color: var(--brand-foreground);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  z-index: 1000;
}
.skip-link:focus {
  left: 0.5rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- View-as-Business Impersonation Banner ---- */
.impersonate-banner {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1.25rem;
  background: var(--warning-bg);
  border-bottom: 1px solid var(--warning);
  color: var(--foreground);
  font-size: 0.82rem;
}
.impersonate-banner-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.impersonate-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---- App Shell (2-Column CRM Layout) ---- */
.shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.18s ease;
}

.shell.is-collapsed {
  grid-template-columns: 64px minmax(0, 1fr);
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 0.85rem 0.65rem;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 40;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.4rem;
  min-height: 36px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--sidebar-foreground);
  text-decoration: none;
  min-width: 0;
}
.brand-link:hover {
  text-decoration: none;
}

.brand-badge {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: var(--brand-foreground);
  font-weight: 700;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.brand-text {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
}

.brand-title {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  color: var(--sidebar-foreground);
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted-foreground);
  background: var(--sidebar-accent);
  padding: 0.08rem 0.38rem;
  border-radius: 999px;
}

.sidebar-collapse-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted-foreground);
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-foreground);
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-foreground);
  padding: 0.35rem 0.6rem 0.2rem;
  white-space: nowrap;
}

.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.48rem 0.65rem;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  font-weight: 500;
  font-size: 0.85rem;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s ease, color 0.12s ease;
}
.nav-link svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  stroke-width: 1.85;
}
.nav-link:hover {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  text-decoration: none;
}
.nav-link[aria-current="page"],
.nav-link.is-active {
  background: var(--brand-muted);
  color: var(--brand);
  font-weight: 500;
}

.sidebar-foot {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.25rem 0.4rem;
  min-width: 0;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--brand-muted);
  color: var(--brand);
  font-weight: 600;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}
.user-meta {
  min-width: 0;
  flex: 1;
}
.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--sidebar-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-email {
  font-size: 0.74rem;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0 0.25rem;
}

/* Theme switcher segmented control */
.theme-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--sidebar-accent);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}
.theme-btn {
  background: transparent;
  border: none;
  color: var(--muted-foreground);
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.22rem 0.45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  line-height: 1.2;
}
.theme-btn:hover {
  color: var(--sidebar-foreground);
}
.theme-btn[aria-pressed="true"] {
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-xs);
}

/* Collapsed sidebar overrides */
.shell.is-collapsed .brand-text,
.shell.is-collapsed .nav-section-label,
.shell.is-collapsed .nav-label,
.shell.is-collapsed .user-meta,
.shell.is-collapsed .theme-switcher {
  display: none;
}
.shell.is-collapsed .brand-row {
  justify-content: center;
  padding: 0.25rem 0;
}
.shell.is-collapsed .nav-link {
  justify-content: center;
  padding: 0.55rem;
}
.shell.is-collapsed .user-pill {
  justify-content: center;
  padding: 0.2rem 0;
}
.shell.is-collapsed .sidebar-foot-controls {
  justify-content: center;
}

/* ---- Main Column & Sticky Topbar ---- */
.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--topbar-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--foreground);
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.breadcrumbs-sep {
  color: var(--border-strong);
}
.breadcrumbs-current {
  color: var(--foreground);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 35;
}

/* ---- Main Content Container ---- */
.content {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

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

.page-header-copy {
  min-width: 0;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin: 0 0 0.25rem;
  color: var(--foreground);
}

.page-intro {
  color: var(--muted-foreground);
  margin: 0 0 1.25rem;
  max-width: 68ch;
  font-size: 0.875rem;
}
.page-header .page-intro {
  margin-bottom: 0;
}

h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 0.35rem;
  color: var(--foreground);
}

h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
  color: var(--foreground);
}

/* ---- Flash / Alert Banners ---- */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.1rem;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.flash-ok {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(22, 163, 74, 0.3);
}
.flash-error {
  background: var(--destructive-bg);
  color: var(--destructive);
  border-color: rgba(220, 38, 38, 0.35);
}

/* ---- Cards & Surfaces ---- */
.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow-xs);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.card-head h2 {
  margin: 0;
}

.card-sub {
  color: var(--muted-foreground);
  font-size: 0.84rem;
  margin: 0 0 1rem;
}

/* ---- KPI Stat Grid ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

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

.kpi-sub {
  font-size: 0.76rem;
  color: var(--muted-foreground);
}

/* ---- Two-Column Overview Layout ---- */
.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 1.1rem;
  margin-bottom: 1.1rem;
}

/* ---- 14-Day CSS Bar Chart ---- */
.bar-chart {
  display: grid;
  grid-template-columns: repeat(14, minmax(0, 1fr));
  gap: 0.4rem;
  align-items: end;
  height: 170px;
  padding-top: 1.25rem;
}

.bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  height: 100%;
  justify-content: flex-end;
  min-width: 0;
}

.bar-val {
  font-size: 0.68rem;
  color: var(--muted-foreground);
  line-height: 1;
}

.bar-track {
  width: 100%;
  max-width: 26px;
  flex: 1;
  background: var(--muted);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  background: var(--brand);
  border-radius: var(--radius-sm);
  min-height: 3px;
  transition: height 0.2s ease;
}

.bar-label {
  font-size: 0.66rem;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ---- Status Badges (Semantic Dot + Pill) ---- */
.status-badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.16rem 0.55rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 500;
  background: var(--muted);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  white-space: nowrap;
  line-height: 1.35;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}

.status-active,
.pill-ok {
  background: var(--success-bg);
  color: var(--success);
  border-color: rgba(22, 163, 74, 0.25);
}

.status-paused {
  background: var(--muted);
  color: var(--muted-foreground);
  border-color: var(--border);
}

.status-warning,
.pill-warn {
  background: var(--warning-bg);
  color: var(--warning);
  border-color: rgba(217, 119, 6, 0.28);
}

.status-error,
.pill-danger {
  background: var(--destructive-bg);
  color: var(--destructive);
  border-color: rgba(220, 38, 38, 0.28);
}

.status-brand {
  background: var(--brand-muted);
  color: var(--brand);
  border-color: rgba(40, 120, 240, 0.25);
}

/* ---- Forms & Controls ---- */
.field {
  margin-bottom: 0.95rem;
}
.field:last-child {
  margin-bottom: 0;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.95rem;
}

label,
.field-label {
  display: block;
  font-weight: 500;
  font-size: 0.82rem;
  margin-bottom: 0.32rem;
  color: var(--foreground);
}

.hint {
  display: block;
  color: var(--muted-foreground);
  font-size: 0.78rem;
  font-weight: 400;
  margin-top: 0.22rem;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="number"],
input[type="time"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 0.85rem;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--ring);
  outline: none;
  box-shadow: 0 0 0 2px var(--brand-muted);
}

textarea {
  resize: vertical;
  min-height: 4.5rem;
}

input[type="file"] {
  color: var(--muted-foreground);
  font-size: 0.84rem;
}

/* ---- Toggle Switch ---- */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  font-size: 0.85rem;
}
.toggle input {
  appearance: none;
  width: 2.35rem;
  height: 1.35rem;
  background: var(--border-strong);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background-color 0.15s ease;
  margin: 0;
  flex-shrink: 0;
}
.toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 0.98rem;
  height: 0.98rem;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.toggle input:checked {
  background: var(--brand);
  border-color: var(--brand);
}
.toggle input:checked::after {
  transform: translateX(1rem);
}

/* ---- Buttons ---- */
button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  padding: 0.48rem 0.88rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--foreground);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  box-shadow: var(--shadow-xs);
}
button:hover:not(:disabled),
.btn:hover:not(:disabled) {
  background: var(--accent-surface);
  border-color: var(--border-strong);
  text-decoration: none;
}
button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-foreground);
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: var(--brand-foreground);
}

.btn-danger {
  background: transparent;
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--destructive);
}
.btn-danger:hover:not(:disabled) {
  background: var(--destructive-bg);
  border-color: var(--destructive);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted-foreground);
  box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--accent-surface);
  border-color: transparent;
  color: var(--foreground);
}

.btn-sm {
  padding: 0.3rem 0.62rem;
  font-size: 0.78rem;
}

.btn-test-call {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-foreground);
  font-weight: 500;
  padding: 0.42rem 0.85rem;
}
.btn-test-call:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}
.btn-test-call .pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.28);
}

/* ---- Save Bar ---- */
.save-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.5rem;
}

/* ---- Filter / Search Toolbar ---- */
.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.search-input-wrap {
  position: relative;
  min-width: 240px;
  flex: 1;
  max-width: 360px;
}
.search-input-wrap input {
  padding-left: 2rem;
}
.search-input-wrap svg {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--muted-foreground);
  pointer-events: none;
}

/* ---- Tables (CRM Style: No All-Caps Headers, No Wrapping) ---- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
}

.card > .table-wrap {
  border: none;
  border-radius: 0;
}

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

th,
td {
  text-align: left;
  padding: 0.68rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  text-transform: none;
  letter-spacing: 0;
  background: var(--muted);
}

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

tbody tr:hover {
  background: var(--accent-surface);
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
  align-items: center;
  white-space: nowrap;
}

.empty {
  color: var(--muted-foreground);
  padding: 1.5rem 0.75rem;
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
}

/* ---- Action Dropdown Menu (<details class="action-menu">) ---- */
details.action-menu {
  position: relative;
  display: inline-block;
}
details.action-menu > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted-foreground);
  font-size: 0.78rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  user-select: none;
}
details.action-menu > summary::-webkit-details-marker {
  display: none;
}
details.action-menu > summary:hover {
  background: var(--accent-surface);
  color: var(--foreground);
}
.action-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 175px;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.3rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.action-menu-panel form {
  margin: 0;
  display: block;
}
.action-menu-item {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: 0.42rem 0.6rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--popover-foreground);
  font-size: 0.8rem;
  font-weight: 400;
  box-shadow: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.action-menu-item:hover {
  background: var(--accent-surface);
  text-decoration: none;
}
.action-menu-item.is-danger {
  color: var(--destructive);
}
.action-menu-item.is-danger:hover {
  background: var(--destructive-bg);
}
.action-menu-sep {
  height: 1px;
  background: var(--border);
  margin: 0.22rem 0;
}

/* ---- Horizontal Tabs Bar (Admin Business Workspace) ---- */
.tabs-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
  padding-bottom: 0;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 0.55rem 0.85rem;
  color: var(--muted-foreground);
  font-size: 0.83rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
  margin-bottom: -1px;
}
.tab-btn:hover:not(:disabled) {
  background: var(--accent-surface);
  color: var(--foreground);
  border-bottom-color: var(--border-strong);
}
.tab-btn[aria-selected="true"],
.tab-btn.is-active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

/* ---- Kanban Board (Change Requests) ---- */
.kanban-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.kanban-col {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 220px;
}

.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--foreground);
  padding: 0.15rem 0.25rem;
}

.kanban-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.kanban-card-title {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--foreground);
}

.kanban-card-desc {
  font-size: 0.8rem;
  color: var(--muted-foreground);
  margin: 0;
}

.kanban-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

/* ---- Opening Hours Grid ---- */
.hours-grid {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
}
.hours-row {
  display: grid;
  grid-template-columns: 8.5rem 5.5rem 1fr auto 1fr;
  align-items: center;
  gap: 0.6rem;
  padding: 0.42rem 0.65rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.hours-day {
  font-weight: 500;
  font-size: 0.84rem;
}
.hours-sep {
  color: var(--muted-foreground);
  font-size: 0.8rem;
}
.hours-row.is-closed input[type="time"] {
  opacity: 0.4;
}

/* ---- Voice Picker ---- */
.voice-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.65rem;
}
.voice-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.voice-option.is-selected {
  border-color: var(--brand);
  background: var(--brand-muted);
}
.voice-radio {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  cursor: pointer;
  margin: 0;
  flex: 1;
  min-width: 0;
}
.voice-radio input[type="radio"] {
  margin-top: 0.2rem;
  accent-color: var(--brand);
}
.voice-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.voice-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--foreground);
}
.voice-desc {
  color: var(--muted-foreground);
  font-size: 0.76rem;
}
.voice-preview-btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.76rem;
  flex-shrink: 0;
}

/* ---- Knowledge Meter & Topic Cards ---- */
.meter-bar {
  height: 8px;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.5rem 0 0.35rem;
}
.meter-fill {
  height: 100%;
  background: var(--brand);
  transition: width 0.2s ease;
}
.meter-fill.is-warn {
  background: var(--warning);
}
.meter-fill.is-full {
  background: var(--destructive);
}
.meter-text {
  color: var(--muted-foreground);
  font-size: 0.8rem;
  margin: 0;
}

.import-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}
.import-form {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.95rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.65rem;
}
.import-status {
  margin: 0.75rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.84rem;
}
.import-status.is-error {
  color: var(--destructive);
}

.review-card,
.topic-card {
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.9rem;
  margin-top: 0.65rem;
}
.topic-list {
  display: flex;
  flex-direction: column;
}
.topic-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.topic-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
}
.topic-content {
  margin: 0.45rem 0 0;
  color: var(--muted-foreground);
  white-space: pre-wrap;
  font-size: 0.84rem;
}
.topic-edit {
  margin-top: 0.65rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.qa-list {
  margin: 0.5rem 0 0;
}
.qa-item {
  padding: 0.65rem 0;
  border-top: 1px solid var(--border);
}
.qa-item:first-child {
  border-top: none;
}
.qa-item dt {
  font-weight: 600;
  font-size: 0.85rem;
}
.qa-item dd {
  margin: 0.22rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.84rem;
}

.source-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}
.source-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
}
.source-item:first-child {
  border-top: none;
}
.source-meta {
  color: var(--muted-foreground);
  white-space: nowrap;
}

.card-danger {
  border-color: rgba(220, 38, 38, 0.35);
}

/* ---- Dialogs & Live Test Call HUD ---- */
dialog.app-dialog,
.call-modal {
  background: var(--card);
  color: var(--foreground);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  width: min(30rem, 92vw);
  box-shadow: var(--shadow-lg);
}
dialog.app-dialog::backdrop,
.call-modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.call-modal {
  text-align: center;
  width: min(24rem, 92vw);
}

.call-ring {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 50%;
  margin: 0.5rem auto 1rem;
  background: var(--brand-muted);
  border: 2px solid var(--brand);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.call-ring[data-state="listening"],
.call-ring[data-state="speaking"] {
  animation: call-pulse 1.4s ease-in-out infinite;
}
.call-ring[data-state="speaking"] {
  border-color: var(--success);
  background: var(--success-bg);
}
@keyframes call-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(40, 120, 240, 0.32);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 12px rgba(40, 120, 240, 0);
  }
}
.call-status {
  color: var(--muted-foreground);
  margin: 0.25rem 0 1.25rem;
  min-height: 1.5em;
  font-size: 0.85rem;
}
.call-actions {
  display: flex;
  gap: 0.65rem;
  justify-content: center;
}

/* ---- Login Screen ---- */
.login-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--background);
}
.login-card {
  width: min(25rem, 100%);
  margin-bottom: 0;
}
.login-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.15rem;
}
.login-card h1 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}
.login-submit {
  width: 100%;
  margin-top: 0.35rem;
}
.login-reset {
  margin-top: 1.15rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--muted-foreground);
}
.login-reset summary {
  cursor: pointer;
  color: var(--muted-foreground);
  font-weight: 500;
}
.login-reset summary:hover {
  color: var(--foreground);
}
.login-reset p {
  margin: 0.55rem 0 0;
}
.login-reset code {
  display: block;
  margin-top: 0.35rem;
  padding: 0.45rem 0.6rem;
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--foreground);
  font-size: 0.78rem;
  overflow-x: auto;
}

/* ---- Responsive Breakpoints ---- */
@media (max-width: 960px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .shell,
  .shell.is-collapsed {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 250px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-lg);
  }
  .shell.mobile-nav-open .sidebar {
    transform: translateX(0);
  }
  .shell.mobile-nav-open .sidebar-backdrop {
    display: block;
  }
  .sidebar-collapse-btn {
    display: none;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .content {
    padding: 1.25rem 1rem 2.5rem;
  }
  .topbar {
    padding: 0 1rem;
  }
  .hours-row {
    grid-template-columns: 1fr 1fr;
  }
}
