:root {
  color-scheme: light;
  --bg: #f6f6f5;
  --surface: #ffffff;
  --surface-2: #f0f1f1;
  --text: #181a1d;
  --muted: #68717b;
  --line: #dfe2e4;
  --primary: #e31b23;
  --primary-strong: #b91219;
  --accent: #9b6a2f;
  --danger: #b91219;
  --good: #15803d;
  --sidebar: #101113;
  --sidebar-2: #191b1f;
  --gold-soft: #f4ead9;
  --shadow: 0 16px 45px rgba(16, 17, 19, 0.1);
}

* {
  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 {
  border: 0;
  cursor: pointer;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
  white-space: nowrap;
}

td {
  font-size: 14px;
}

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

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 42px;
  outline: 0;
  padding: 9px 11px;
  width: 100%;
}

.app input:not([type="number"]):not([type="password"]),
.app textarea,
dialog input:not([type="number"]),
dialog textarea {
  text-transform: uppercase;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(227, 27, 35, 0.14);
}

.hidden {
  display: none !important;
}

.login-shell {
  align-items: center;
  background:
    linear-gradient(135deg, rgba(246, 246, 245, 0.94), rgba(255, 255, 255, 0.86)),
    url("data:image/svg+xml,%3Csvg width='1400' height='900' viewBox='0 0 1400 900' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23101113' stroke-width='2' opacity='.08'%3E%3Cpath d='M0 690h1400M80 690l96-210h1048l96 210M210 480l66-160h848l66 160M314 320l54-128h664l54 128M435 192l34-82h462l34 82'/%3E%3Ccircle cx='318' cy='690' r='72'/%3E%3Ccircle cx='1082' cy='690' r='72'/%3E%3Cpath d='M430 560h540M502 438h396M580 292h240'/%3E%3C/g%3E%3Cg fill='%23e31b23' opacity='.08'%3E%3Crect x='-40' y='725' width='1480' height='16'/%3E%3Crect x='-40' y='758' width='1480' height='7'/%3E%3C/g%3E%3C/svg%3E");
  background-position: center;
  background-size: cover;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.login-panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: auto;
  max-width: 460px;
  padding: 30px;
  width: 100%;
}

.login-logo-wrap {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
  min-height: 140px;
  overflow: hidden;
}

.login-logo {
  display: block;
  height: 132px;
  object-fit: contain;
  width: 100%;
}

.login-panel h1 {
  font-size: 25px;
  letter-spacing: 0;
  line-height: 1.1;
  margin: 6px 0 24px;
}

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

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
}

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

.brand strong {
  display: block;
  letter-spacing: 0;
}

.brand small,
.session-box {
  color: #c5c8cc;
}

.mark {
  align-items: center;
  background: #fff;
  border-radius: 6px;
  color: #fff;
  display: inline-flex;
  font-weight: 900;
  height: 48px;
  justify-content: center;
  overflow: hidden;
  width: 82px;
}

.logo-mark img {
  display: block;
  height: 46px;
  object-fit: contain;
  width: 80px;
}

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

.nav button {
  background: transparent;
  border-radius: 6px;
  color: #cdd7dc;
  padding: 12px 13px;
  text-align: left;
}

.nav button.active,
.nav button:hover {
  background: rgba(227, 27, 35, 0.18);
  color: #fff;
}

.session-box {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 18px;
}

.content {
  min-width: 0;
  padding: 26px;
}

.topbar,
.tool-row,
.panel-head,
.dialog-head,
.dialog-actions {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.topbar {
  margin-bottom: 22px;
}

.topbar h2 {
  font-size: 28px;
  line-height: 1.1;
  margin: 5px 0 0;
}

.top-actions,
.tool-row {
  flex-wrap: wrap;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(24, 32, 38, 0.04);
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 18px;
}

.metric small,
.panel-head span,
.item small {
  color: var(--muted);
}

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

.metric.warning strong {
  color: var(--primary);
}

.split {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr);
}

.grid-form {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 0.9fr) minmax(340px, 0.6fr);
}

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

.panel-head {
  border-bottom: 1px solid var(--line);
  margin: -2px 0 14px;
  padding-bottom: 12px;
}

.panel-head.compact-head {
  margin-top: 0;
}

.panel-divider {
  border-top: 1px solid var(--line);
  margin: 20px 0;
}

.panel h3,
.dialog-head h3 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
}

.tool-row {
  margin-bottom: 14px;
}

.tool-row label,
.search {
  min-width: min(440px, 100%);
}

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

.table-wrap.flat {
  border: 0;
  border-radius: 0;
}

.right {
  text-align: right;
}

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

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

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

.primary,
.secondary,
.ghost,
.danger,
.icon-button {
  border-radius: 6px;
  font-weight: 800;
  min-height: 40px;
  padding: 10px 14px;
}

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

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

.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.ghost {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.danger {
  background: #fff1f0;
  color: var(--danger);
}

.icon-button {
  align-items: center;
  background: var(--surface-2);
  display: inline-flex;
  font-size: 24px;
  height: 38px;
  justify-content: center;
  padding: 0;
  width: 38px;
}

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

.item {
  align-items: center;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.item strong {
  display: block;
}

.compact .item {
  min-height: 58px;
}

.pill {
  background: var(--surface-2);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
  text-transform: uppercase;
}

.pill.good {
  background: #e8f7ee;
  color: var(--good);
}

.pill.warn {
  background: var(--gold-soft);
  color: var(--accent);
}

.pill.danger {
  background: #fff1f0;
  color: var(--danger);
}

.form-error,
.form-message {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
  margin: 0;
}

.form-message.ok {
  color: var(--good);
}

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 860px;
  padding: 0;
  width: calc(100vw - 32px);
}

dialog::backdrop {
  background: rgba(24, 32, 38, 0.55);
}

.dialog-body {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.dialog-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.dialog-actions {
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
  padding-top: 14px;
}

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

.matches-panel {
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.matches-panel h4 {
  margin: 0 0 10px;
}

.match-list {
  display: grid;
  gap: 8px;
}

.match-card {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px;
}

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

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

.credit-items,
.credit-lines {
  display: grid;
  gap: 10px;
}

.credit-item-row,
.credit-line {
  align-items: end;
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1fr) 130px 120px auto;
  padding: 10px;
}

.movement-item-row {
  grid-template-columns: minmax(220px, 1fr) 120px auto;
}

.sale-item-row {
  grid-template-columns: 160px minmax(220px, 1fr) 120px auto;
}

.credit-entry-row {
  grid-template-columns: 150px minmax(280px, 1fr) 120px 120px auto;
}

.intake-item-row {
  align-items: start;
  grid-template-columns: minmax(220px, 1fr) 130px minmax(280px, 1fr) auto auto;
}

.intake-quantity-group {
  color: var(--muted);
  display: grid;
  font-size: 0.8rem;
  font-weight: 800;
  gap: 6px;
  text-transform: uppercase;
}

.intake-quantities {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.intake-location-cell {
  color: var(--muted);
  display: grid;
  font-size: 0.68rem;
  font-weight: 800;
  gap: 4px;
  letter-spacing: 0;
  min-width: 0;
  text-transform: uppercase;
}

.intake-location-cell input {
  min-width: 0;
}

.new-part-fields {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding-top: 10px;
}

.credit-card {
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.credit-card-head,
.credit-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.credit-card small,
.credit-line small {
  color: var(--muted);
}

.credit-line {
  align-items: center;
  grid-template-columns: minmax(180px, 1fr) 96px;
}

.check-summary {
  align-items: flex-start;
  display: grid;
  gap: 4px;
}

.check-summary small {
  color: var(--muted);
  font-size: 0.72rem;
}

.stock-count-input {
  max-width: 88px;
  text-align: right;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.rule-row {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(160px, 1fr) 120px 120px;
}

.empty {
  color: var(--muted);
  padding: 16px;
  text-align: center;
}

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

  .sidebar {
    position: static;
  }

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

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

@media (max-width: 620px) {
  .content,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .tool-row,
  .panel-head,
  .dialog-head,
  .dialog-actions,
  .item {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .form-grid,
  .rule-row,
  .credit-item-row,
  .credit-line,
  .intake-quantities,
  .new-part-fields,
  .nav {
    grid-template-columns: 1fr;
  }

  .credit-items-head,
  .credit-card-head,
  .credit-actions {
    align-items: stretch;
    flex-direction: column;
  }

  th,
  td {
    padding: 10px;
  }
}
