:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #1b2523;
  --muted: #65736f;
  --line: #dbe3e0;
  --primary: #2168d4;
  --primary-dark: #174ea1;
  --green: #138a5b;
  --amber: #b46613;
  --red: #c2413b;
  --teal: #187f89;
  --ink: #10201c;
  --shadow: 0 18px 45px rgba(27, 37, 35, 0.08);
}

body.dark {
  color-scheme: dark;
  --bg: #101614;
  --surface: #17211e;
  --surface-2: #1f2d29;
  --text: #eef7f3;
  --muted: #a4b5b0;
  --line: #2b3b36;
  --primary: #75a7ff;
  --primary-dark: #a9c8ff;
  --green: #52c58f;
  --amber: #f0b35c;
  --red: #ff817a;
  --teal: #66cbd4;
  --ink: #effaf6;
  --shadow: 0 22px 55px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: #12211d;
  color: #f4fbf8;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f5c44f;
  color: #15211d;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #a9beb7;
  font-size: 13px;
  margin-top: 3px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  text-align: left;
  color: #d8e6e1;
  background: transparent;
  padding: 10px 12px;
}

.nav-item:hover,
.nav-item.active {
  background: #263a35;
  color: #ffffff;
}

.plan-box {
  margin-top: auto;
  border: 1px solid #354a44;
  border-radius: 8px;
  padding: 14px;
  background: #192d28;
}

.plan-box span,
.plan-box small {
  color: #aac2ba;
}

.plan-box strong {
  display: block;
  margin: 4px 0;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}

.menu-button {
  display: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 12px;
}

.topbar-title {
  flex: 1;
  min-width: 180px;
}

.topbar-title span,
.eyebrow {
  color: var(--teal);
  display: block;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
  line-height: 1.25;
}

h3 {
  font-size: 15px;
}

.topbar-actions,
.toolbar,
.module-head,
.panel-head,
.modal-head,
.modal-actions,
.data-tools {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button,
.file-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.button.primary {
  background: var(--primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary,
.file-button,
.button.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.button.ghost {
  background: transparent;
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.field.compact {
  gap: 3px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  min-height: 40px;
  padding: 9px 11px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33, 104, 212, 0.15);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.insight-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric-card,
.panel,
.customer-card,
.pipeline-column,
.finance-card,
.report-card,
.automation-card,
.ticket-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 15px;
  min-height: 112px;
  display: grid;
  align-content: space-between;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric-card strong {
  font-size: 28px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 18px;
}

.span-2 {
  grid-column: span 2;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-head,
.module-head {
  justify-content: space-between;
  margin-bottom: 16px;
}

.module-head {
  min-height: 52px;
}

.chart-area {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 145px 1fr 48px;
  align-items: center;
  gap: 12px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.stack-list,
.leaderboard,
.source-list {
  display: grid;
  gap: 10px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--surface);
}

.list-item .meta,
.card-meta,
.row-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}

.item-top,
.customer-top,
.ticket-top,
.finance-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  min-height: 24px;
  padding: 0 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.pill.hot,
.pill.high,
.pill.overdue {
  background: rgba(194, 65, 59, 0.12);
  color: var(--red);
}

.pill.medium,
.pill.pending {
  background: rgba(180, 102, 19, 0.14);
  color: var(--amber);
}

.pill.converted,
.pill.paid,
.pill.completed {
  background: rgba(19, 138, 91, 0.13);
  color: var(--green);
}

.toolbar {
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search-wrap {
  flex: 1;
  min-width: 260px;
}

.data-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--surface-2);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.small-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0 9px;
}

.pipeline-board,
.ticket-lanes {
  display: grid;
  grid-template-columns: repeat(5, minmax(240px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.pipeline-column {
  padding: 12px;
  min-height: 520px;
}

.pipeline-column h3 {
  margin-bottom: 10px;
}

.pipeline-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  margin-bottom: 10px;
  background: var(--surface);
}

.pipeline-card strong {
  display: block;
  margin-bottom: 5px;
}

.card-actions {
  display: flex;
  gap: 7px;
  margin-top: 10px;
}

.customer-grid,
.finance-grid,
.report-grid,
.automation-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.customer-card,
.finance-card,
.report-card,
.automation-card,
.ticket-card {
  padding: 15px;
}

.customer-card p,
.finance-card p,
.report-card p,
.automation-card p,
.ticket-card p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 7px;
}

.automation-card {
  display: grid;
  gap: 10px;
}

.switch-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.switch {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  padding: 3px;
  border: 0;
}

.switch::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s ease;
}

.switch.on {
  background: var(--green);
}

.switch.on::before {
  transform: translateX(20px);
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.lead-form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field.wide {
  grid-column: 1 / -1;
}

.data-tools {
  align-items: stretch;
  flex-wrap: wrap;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.permissions {
  overflow: auto;
}

.permission-row {
  display: grid;
  grid-template-columns: 150px repeat(5, minmax(80px, 1fr));
  gap: 8px;
  align-items: center;
  min-width: 620px;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}

.permission-row strong {
  font-size: 13px;
}

.checkmark {
  color: var(--green);
  font-weight: 900;
}

.modal {
  border: 0;
  background: transparent;
  width: min(980px, calc(100vw - 24px));
  padding: 0;
}

.modal::backdrop {
  background: rgba(12, 18, 16, 0.58);
}

.modal-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.compact-modal {
  width: min(520px, calc(100vw - 24px));
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

.modal-head {
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.toast-area {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 10px;
  z-index: 20;
}

.toast {
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 260px;
  box-shadow: var(--shadow);
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 230px 1fr;
  }

  .insight-strip {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .dashboard-grid,
  .customer-grid,
  .finance-grid,
  .report-grid,
  .automation-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .menu-button {
    display: inline-flex;
    align-items: center;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .span-2 {
    grid-column: auto;
  }

  .dashboard-grid,
  .split-grid,
  .settings-grid,
  .customer-grid,
  .finance-grid,
  .report-grid,
  .automation-grid {
    grid-template-columns: 1fr;
  }

  .lead-form-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .insight-strip {
    grid-template-columns: 1fr 1fr;
  }

  h1 {
    font-size: 25px;
  }

  .button,
  .file-button {
    width: 100%;
  }

  .topbar-actions .field {
    width: 100%;
  }
}
