/* shadcn/ui — light minimal */
:root {
  --background: hsl(0 0% 99%);
  --foreground: hsl(240 10% 10%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(240 10% 10%);
  --primary: hsl(240 6% 10%);
  --primary-foreground: hsl(0 0% 100%);
  --secondary: hsl(240 5% 96%);
  --secondary-foreground: hsl(240 6% 10%);
  --muted: hsl(240 5% 96%);
  --muted-foreground: hsl(240 4% 46%);
  --accent: hsl(240 5% 96%);
  --accent-foreground: hsl(240 6% 10%);
  --destructive: hsl(0 72% 51%);
  --destructive-foreground: hsl(0 0% 100%);
  --border: hsl(240 6% 90%);
  --input: hsl(240 6% 90%);
  --ring: hsl(240 5% 65%);
  --warning: hsl(32 95% 44%);
  --radius: 0.375rem;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 8px 30px rgb(0 0 0 / 0.08);
}

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

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.text-muted { color: var(--muted-foreground); }

/* Brand */
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 600;
  font-size: 0.8125rem;
}

.brand-mark-sm {
  width: 26px;
  height: 26px;
  font-size: 0.625rem;
}

/* Card */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
}

.card-header { padding: 1.25rem 1.25rem 0; }

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.card-description {
  margin: 0.25rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
}

.card-content { padding: 1.25rem; }

.stack { display: flex; flex-direction: column; gap: 0.875rem; }
.stack-lg { display: flex; flex-direction: column; gap: 1rem; }

.separator {
  height: 1px;
  background: var(--border);
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--background);
}

.login-card { width: min(380px, 100%); }
.login-card .brand-mark { margin-bottom: 0.875rem; }
.login-card .card-header { padding-top: 0; }
.login-card h1 {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  white-space: nowrap;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  height: 2rem;
  padding: 0 0.875rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  border: 1px solid transparent;
}

.btn:disabled { opacity: 0.45; pointer-events: none; }

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

.btn-primary:hover { background: hsl(240 6% 20%); }

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

.btn-outline:hover { background: var(--muted); }

.btn-secondary, .btn-default {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border-color: var(--border);
}

.btn-secondary:hover, .btn-default:hover { background: hsl(240 5% 92%); }

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

.btn-ghost:hover {
  background: var(--muted);
  color: var(--foreground);
}

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

.btn-destructive:hover { background: hsl(0 72% 45%); }

.btn-link {
  background: none;
  border: none;
  color: var(--muted-foreground);
  text-decoration: underline;
  text-underline-offset: 3px;
  height: auto;
  padding: 0;
  font-size: 0.75rem;
}

.btn-sm { height: 1.75rem; padding: 0 0.625rem; font-size: 0.75rem; }
.btn-block { width: 100%; }
.btn-icon { width: 1.75rem; height: 1.75rem; padding: 0; }

.icon { width: 0.875rem; height: 0.875rem; flex-shrink: 0; }

/* Forms */
.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--foreground);
}

.input, .select {
  width: 100%;
  height: 2rem;
  border-radius: var(--radius);
  border: 1px solid var(--input);
  background: var(--card);
  padding: 0 0.625rem;
  font-size: 0.8125rem;
  color: var(--foreground);
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.input::placeholder { color: var(--muted-foreground); }

.input:focus, .select:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 2px hsl(240 5% 65% / 0.2);
}

.select { cursor: pointer; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 400;
  cursor: pointer;
  min-height: 2rem;
  color: var(--foreground);
}

.checkbox-label input {
  width: 0.9375rem;
  height: 0.9375rem;
  accent-color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.875rem;
}

@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* Alert */
.alert {
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
}

.alert-destructive {
  border: 1px solid hsl(0 72% 51% / 0.25);
  background: hsl(0 72% 51% / 0.08);
  color: hsl(0 72% 40%);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  padding: 0.0625rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}

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

.badge.new, .badge-new { background: hsl(214 95% 93%); color: hsl(214 80% 35%); border-color: hsl(214 60% 85%); }
.badge.contacted, .badge-contacted { background: hsl(38 92% 92%); color: hsl(32 80% 32%); border-color: hsl(38 70% 85%); }
.badge.callback, .badge-callback { background: hsl(142 60% 92%); color: hsl(142 50% 28%); border-color: hsl(142 45% 85%); }
.badge.proposal_sent, .badge-proposal_sent { background: hsl(263 60% 94%); color: hsl(263 50% 38%); border-color: hsl(263 45% 88%); }
.badge.won, .badge-won { background: hsl(142 55% 88%); color: hsl(142 45% 25%); border-color: hsl(142 40% 80%); }
.badge.lost, .badge-lost { background: hsl(0 70% 94%); color: hsl(0 60% 38%); border-color: hsl(0 50% 88%); }

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius);
  padding: 0.0625rem 0.4375rem;
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--muted);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

/* App shell */
.app-wrap { min-height: 100vh; }

.app-header {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
  padding: 0.4375rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex: 1;
  min-width: 180px;
}

.app-header h1 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.app-header .meta {
  margin: 0.0625rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.6875rem;
}

.header-actions {
  display: flex;
  gap: 0.375rem;
  flex-shrink: 0;
}

.shift-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.app-main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.625rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Stats + filters panel */
.filter-panel { padding: 0; overflow: hidden; }

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.125rem 0.875rem;
  padding: 0.4375rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--muted);
}

.stat-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3125rem;
  white-space: nowrap;
}

.stat-label {
  color: var(--muted-foreground);
  font-size: 0.625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 0.8125rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.filter-panel-body { padding: 0.5rem 0.75rem; }

.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
}

.filter-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  flex-shrink: 0;
}

.filter-search {
  flex: 1 1 10rem;
  min-width: 8rem;
  max-width: 16rem;
}

.filter-toolbar .select {
  flex: 0 1 auto;
  width: auto;
  min-width: 6.5rem;
  max-width: 9rem;
}

.checkbox-compact {
  min-height: auto;
  gap: 0.3125rem;
  font-size: 0.75rem;
  white-space: nowrap;
}

.checkbox-compact input {
  width: 0.8125rem;
  height: 0.8125rem;
}

.filter-actions {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .filter-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }
}

.loading { opacity: 0.55; pointer-events: none; }

.filter-hint {
  margin: 0.25rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

/* Table */
.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.data-table thead tr { border-bottom: 1px solid var(--border); }

.data-table th {
  height: 2.25rem;
  padding: 0 0.875rem;
  text-align: left;
  font-weight: 500;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  white-space: nowrap;
  background: var(--muted);
}

.data-table td {
  padding: 0.625rem 0.875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.data-table tbody tr:hover { background: hsl(240 5% 98%); }

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

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--foreground); }
.sort-icon { opacity: 0.35; font-size: 0.625rem; margin-left: 0.125rem; }
th.sortable.active { color: var(--foreground); }
th.sortable.active .sort-icon { opacity: 0.8; }

.name-cell { font-weight: 500; max-width: 240px; }
.phone-cell { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted-cell { color: var(--muted-foreground); font-size: 0.75rem; }

.chain-tag {
  margin-left: 0.25rem;
  font-size: 0.625rem;
  font-weight: 500;
  color: var(--warning);
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.875rem;
  padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.pager-btns { display: flex; gap: 0.25rem; }

.link {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.link:hover { color: var(--muted-foreground); }

.phone-link {
  text-decoration: none;
  font-weight: 500;
  color: var(--foreground);
}

.phone-link:hover { text-decoration: underline; }

/* Contact */
.contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.contact-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.75rem;
  min-width: 1.75rem;
  padding: 0 0.5rem;
  border-radius: var(--radius);
  font-size: 0.625rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted-foreground);
  transition: background 0.12s;
}

.contact-btn:hover { background: var(--muted); color: var(--foreground); }
.contact-btn.wa { color: hsl(142 50% 32%); }
.contact-btn.tg { color: hsl(199 70% 38%); }

/* Dialog */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgb(0 0 0 / 0.35);
}

.dialog {
  width: min(540px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-lg);
}

.dialog-wide {
  width: min(920px, calc(100vw - 1.5rem));
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem 0.625rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-head-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.dialog-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.dialog-body { padding: 0.875rem 1.25rem; }

.lead-modal .dialog-body {
  padding: 0.625rem 1rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.modal-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
  height: 100%;
  min-height: 0;
}

.modal-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  overflow-y: auto;
}

.modal-col-left .detail-grid {
  flex: 1;
  min-height: 0;
}

.modal-crm {
  margin-top: auto;
  padding-top: 0.25rem;
}

@media (max-width: 760px) {
  .dialog-wide {
    width: min(540px, calc(100vw - 1rem));
    max-height: 92vh;
    overflow-y: auto;
  }

  .lead-modal .dialog-body { overflow: visible; }

  .modal-columns {
    grid-template-columns: 1fr;
    height: auto;
  }

  .modal-col { overflow: visible; max-height: none; }
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.375rem;
  padding: 0.625rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-utp, .call-utp {
  font-size: 0.8125rem;
  font-weight: 500;
  color: hsl(142 45% 32%);
}

.detail-grid {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.3125rem 0.625rem;
  font-size: 0.8125rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--muted);
  align-content: start;
}

.detail-grid div:nth-child(odd) {
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

/* Collapsible */
.collapsible {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.collapsible summary {
  padding: 0.625rem 0.875rem;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.8125rem;
  background: var(--muted);
  list-style: none;
}

.collapsible summary::-webkit-details-marker { display: none; }

.collapsible-content {
  padding: 0.625rem 0.875rem 0.875rem;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.context-block, .history-block {
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--muted);
}

.block-title {
  margin: 0 0 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-foreground);
}

.script-section { margin-top: 0.625rem; }
.script-section:first-child { margin-top: 0; }
.script-section strong { font-size: 0.75rem; }
.script-section p { margin: 0.125rem 0 0; color: var(--muted-foreground); font-size: 0.75rem; }

.history-item {
  font-size: 0.75rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
}

.history-item:last-child { border-bottom: 0; }

.empty-row td {
  text-align: center;
  color: var(--muted-foreground);
  padding: 2.5rem 1rem;
}

/* Call mode */
.call-mode {
  min-height: calc(100vh - 49px);
  background: var(--background);
}

.call-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.call-body {
  max-width: 600px;
  margin: 1.25rem auto;
}

.call-name {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.call-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding-top: 0.375rem;
}
