:root {
  --brand-teal: #14c8b3;
  --brand-teal-dark: #0faf9c;
  --brand-teal-deep: #0ea5a0;
  --graphite: #0f1720;
  --graphite-2: #162330;
  --graphite-3: #1f2d3a;
  --ink: #0f1720;
  --ink-2: #334155;
  --muted: #667085;
  --canvas: #f7f9fc;
  --card: #ffffff;
  --line: #e4e7ec;
  --line-2: #eef2f6;
  --teal-soft: rgba(20, 200, 179, 0.13);
  --green: #22c55e;
  --green-soft: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.12);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --rose: #d8b4a0;
  --shadow: 0 1px 2px rgba(15, 23, 32, 0.04), 0 10px 30px rgba(15, 23, 32, 0.08);
  --radius: 8px;
  --radius-sm: 8px;
  --font-ui: Inter, Manrope, Segoe UI, Arial, sans-serif;
  --font-display: Sora, Inter, Segoe UI, Arial, sans-serif;
  --font-mono: "JetBrains Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-ui);
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1.1fr) minmax(320px, 0.9fr);
}

.login-brand {
  min-height: 100vh;
  padding: 56px;
  color: white;
  background:
    linear-gradient(135deg, rgba(20, 200, 179, 0.28), rgba(20, 200, 179, 0) 36%),
    linear-gradient(160deg, var(--graphite), #101f2b 62%, #0b3f45);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.brand-mark,
.side-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark img,
.side-logo img {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  filter: drop-shadow(0 8px 18px rgba(20, 200, 179, 0.24));
}

.brand-mark strong,
.side-logo strong {
  color: white;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark strong span:last-child,
.side-logo strong span:last-child {
  color: var(--brand-teal);
}

.login-brand h1 {
  max-width: 12ch;
  margin: 12px 0 18px;
  font-family: var(--font-display);
  font-size: clamp(36px, 5vw, 58px);
  font-weight: 800;
  line-height: 1.02;
}

.brand-copy {
  max-width: 44ch;
  color: #b6c2ce;
  line-height: 1.7;
}

.eyebrow {
  margin: 0;
  color: var(--brand-teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.login-card {
  width: min(380px, calc(100vw - 48px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  align-self: center;
  justify-self: center;
}

.login-card h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
}

.login-card label {
  margin-bottom: 0;
}

.local-login-form {
  display: grid;
  gap: 14px;
}

.login-card .primary-btn {
  justify-self: start;
}

.login-card small {
  color: var(--muted);
  line-height: 1.5;
}

.clerk-login {
  width: 100%;
}

.clerk-login > div {
  width: 100%;
}

.clerk-login :is(.cl-rootBox, .cl-cardBox, .cl-card) {
  width: 100%;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--ink);
  background: white;
  outline: none;
}

textarea {
  min-height: 82px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.link-btn {
  min-height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 800;
}

.primary-btn {
  color: var(--graphite);
  background: var(--brand-teal);
}

.primary-btn:hover {
  background: var(--brand-teal-dark);
}

.secondary-btn {
  color: var(--ink);
  background: white;
  border-color: var(--line);
}

.ghost-btn {
  color: #c7d0d9;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.12);
}

.link-btn {
  color: var(--brand-teal-dark);
  background: var(--teal-soft);
}

.error-text {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  min-height: 100vh;
  padding: 22px 12px 16px;
  color: #c3ccd6;
  background: var(--graphite);
  display: flex;
  flex-direction: column;
}

.side-logo {
  padding: 0 10px 18px;
}

.side-logo img {
  width: 30px;
  height: 30px;
}

.side-logo strong {
  font-size: 20px;
}

.nav-group {
  margin-top: 18px;
}

.nav-label {
  padding: 0 12px 7px;
  color: #657688;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1.3px;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  padding: 8px 12px;
  color: #b7c0ca;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  color: white;
  background: var(--graphite-3);
}

.nav-item.active {
  box-shadow: inset 3px 0 0 var(--brand-teal);
}

.side-user {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--graphite-3);
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  color: white;
  background: var(--graphite-3);
  display: grid;
  place-items: center;
  font-weight: 900;
}

.side-user strong,
.side-user small {
  display: block;
}

.side-user small {
  color: #8090a0;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  min-height: 72px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 249, 252, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.crumb {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
}

.topbar h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.search {
  width: min(320px, 28vw);
}

.content {
  flex: 1;
  padding: 24px 28px 40px;
  overflow-y: auto;
  overflow-x: hidden;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h3 {
  margin: 0;
  font-size: 18px;
}

.page-head p {
  margin: 4px 0 0;
  color: var(--ink-2);
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.card,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card {
  padding: 16px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.kpi-value {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 900;
}

.kpi-hint,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.layout-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
  gap: 16px;
  min-width: 0;
}

.layout-sales {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.sales-form-panel {
  max-width: 100%;
}

.panel-head {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 16px;
}

.action-guide {
  margin-bottom: 16px;
}

.guide-grid {
  padding: 14px 16px 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.guide-action {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  color: var(--ink);
  background: white;
  text-align: left;
  display: grid;
  gap: 6px;
}

.guide-action:hover {
  border-color: var(--brand-teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

.guide-action strong {
  font-size: 13px;
}

.guide-action span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.report-toolbar {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: end;
}

.report-toolbar label {
  margin-bottom: 0;
}

.report-note {
  min-height: 42px;
  display: grid;
  gap: 4px;
}

.report-note span {
  color: var(--muted);
  font-size: 13px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  gap: 16px;
  min-width: 0;
}

.settings-subhead {
  padding-top: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.price-rules-editor {
  display: grid;
  gap: 10px;
}

.price-rule-row {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fbfcfc;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(110px, 150px) auto;
  gap: 10px;
  align-items: end;
}

.price-rule-row label {
  margin-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  align-items: end;
  min-width: 0;
}

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

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.bulk-bar {
  min-height: 48px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-2);
  color: var(--muted);
  background: #fbfcfc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bulk-bar.is-active {
  color: var(--ink);
  background: var(--teal-soft);
}

.bulk-bar strong {
  font-family: var(--font-mono);
}

.select-cell {
  width: 42px;
  text-align: center;
}

.row-check {
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand-teal);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.danger-link {
  color: var(--red);
  background: var(--red-soft);
}

.success-link {
  color: var(--green);
  background: var(--green-soft);
}

.danger-action {
  color: var(--red);
  border-color: rgba(209, 68, 56, 0.28);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-2);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: var(--font-mono);
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 900;
}

.badge.green {
  color: var(--green);
  background: var(--green-soft);
}

.badge.red {
  color: var(--red);
  background: var(--red-soft);
}

.badge.amber {
  color: #9a5b00;
  background: var(--warn-soft);
}

.badge.neutral {
  color: var(--ink-2);
  background: #eef1f3;
}

.stack {
  display: grid;
  gap: 12px;
}

.split-list {
  display: grid;
  gap: 10px;
}

.sales-items {
  display: grid;
  gap: 12px;
}

.sales-line {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fbfcfc;
}

.sales-line-head,
.order-detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.order-detail-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
  align-items: center;
}

.sales-line-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(88px, 120px) minmax(110px, 140px);
  gap: 10px;
  align-items: end;
  min-width: 0;
}

.line-sku {
  min-width: 0;
}

.line-metrics {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.metric-pill {
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--ink-2);
  background: #eef1f3;
  font-size: 11px;
  font-weight: 900;
}

.summary-strip {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--teal-soft);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.summary-strip span {
  display: grid;
  gap: 2px;
}

.summary-strip strong {
  font-family: var(--font-mono);
  font-size: 16px;
}

.summary-strip small {
  color: var(--ink-2);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.order-detail {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.order-detail strong,
.order-detail small {
  display: block;
}

.order-detail small {
  color: var(--muted);
}

.order-items {
  display: grid;
  gap: 7px;
}

.order-item-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 64px 86px 72px 82px;
  gap: 8px;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid var(--line-2);
  font-size: 12px;
  min-width: 0;
}

.list-row {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.list-row strong,
.list-row small {
  display: block;
}

.list-row small {
  color: var(--muted);
}

.mobile-card {
  max-width: 460px;
}

.mobile-card .primary-btn {
  width: 100%;
  min-height: 52px;
  font-size: 15px;
}

.stock-movements-panel {
  margin-top: 16px;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: flex-end;
  min-width: min(100%, 560px);
}

.head-select {
  min-width: min(360px, 100%);
  margin-bottom: 0;
}

.tech-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
}

.tech-summary span {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: white;
  box-shadow: var(--shadow);
  display: grid;
  gap: 5px;
}

.tech-summary small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.tech-summary strong {
  font-family: var(--font-mono);
  font-size: 20px;
}

.cost-summary {
  margin-bottom: 16px;
}

.layout-tech {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
}

.tech-table {
  table-layout: auto;
}

.materials-table {
  min-width: 760px;
}

.operations-table {
  min-width: 920px;
}

.tech-table th:last-child,
.tech-table td:last-child {
  width: 96px;
}

.table-input {
  min-height: 36px;
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 12px;
}

.table-input.short {
  max-width: 150px;
}

.table-input.mini {
  max-width: 82px;
}

.row-actions-cell {
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  padding: 22px;
  background: rgba(11, 22, 35, 0.48);
  display: grid;
  place-items: center;
}

.modal {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 44px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: 0 24px 70px rgba(11, 22, 35, 0.24);
  overflow: auto;
}

.modal-head,
.modal-actions {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

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

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

.modal-actions {
  border-top: 1px solid var(--line-2);
  border-bottom: 0;
  justify-content: flex-end;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  background: white;
  font-size: 20px;
  line-height: 1;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 360px;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: white;
  background: var(--graphite);
  box-shadow: var(--shadow);
  font-weight: 800;
  z-index: 20;
}

@media (max-width: 1040px) {
  .kpi-grid,
  .layout-2,
  .layout-sales,
  .layout-tech,
  .form-grid,
  .sales-line-grid,
  .report-toolbar,
  .settings-grid,
  .price-rule-row,
  .summary-strip,
  .tech-summary,
  .order-item-row {
    grid-template-columns: 1fr 1fr;
  }

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

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

  .login-view {
    grid-template-columns: 1fr;
  }

  .login-brand {
    min-height: 42vh;
    padding: 28px;
  }

  .login-brand h1 {
    font-size: 34px;
    max-width: 13ch;
  }

  .login-card {
    align-self: start;
    padding: 28px 0;
  }

  .login-card .primary-btn {
    width: 100%;
  }

  .sidebar {
    min-height: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .workspace {
    min-height: 100vh;
  }

  .side-logo {
    padding: 0;
  }

  .side-logo img {
    width: 24px;
    height: 24px;
  }

  #nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-group {
    margin-top: 0;
    display: contents;
  }

  .nav-label {
    display: none;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
    min-height: 34px;
    padding: 7px 11px;
  }

  .side-user {
    display: none;
  }

  .topbar,
  .page-head,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .content {
    padding: 18px;
  }

  .topbar {
    min-height: auto;
    padding: 14px 18px;
    gap: 12px;
  }

  .topbar h2 {
    font-size: 23px;
  }

  .top-actions .primary-btn {
    width: 100%;
  }

  .bulk-bar,
  .order-detail-head,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .order-detail-actions {
    justify-content: flex-start;
  }

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

  .search,
  .kpi-grid,
  .layout-2,
  .layout-sales,
  .layout-tech,
  .form-grid,
  .sales-line-grid,
  .report-toolbar,
  .settings-grid,
  .price-rule-row,
  .summary-strip,
  .tech-summary,
  .order-item-row {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  th,
  td {
    padding: 10px 12px;
  }

  .panel > table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .action-table th:last-child,
  .action-table td:last-child {
    position: sticky;
    right: 0;
    z-index: 1;
    background: white;
    box-shadow: -8px 0 14px rgba(16, 31, 49, 0.08);
  }

  .action-table th:last-child {
    background: #fbfcfc;
  }

  .mobile-card {
    max-width: none;
  }
}
