:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --surface-dark: #13202f;
  --border: #d8e0e8;
  --text: #1b2633;
  --muted: #627386;
  --accent: #1c6dd0;
  --accent-soft: #e7f0fb;
  --danger: #c54141;
  --warning: #bf7b10;
  --success: #1f8a54;
  --shadow: 0 12px 32px rgba(24, 37, 51, 0.08);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 24px;
  padding: 24px;
  background: var(--surface-dark);
  color: #f4f8fc;
}

.brand h1,
.topbar h2,
.panel h3,
.empty-state h4,
.card-title {
  margin: 0;
}

.brand-kicker,
.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  color: var(--muted);
}

.brand-kicker {
  color: #9db4cb;
}

.brand-copy {
  margin: 10px 0 0;
  color: #c4d2df;
  line-height: 1.5;
}

.nav-menu {
  display: grid;
  gap: 8px;
}

.nav-link {
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  text-align: left;
  background: transparent;
  color: #d6e2ed;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-box {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-box h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.server-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #808b98;
}

.status-dot.online {
  background: var(--success);
}

.status-dot.offline {
  background: var(--danger);
}

.content-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 24px 28px 0;
}

.topbar h2 {
  font-size: 1.9rem;
}

.topbar-actions,
.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.main-content {
  display: grid;
  gap: 20px;
  padding: 24px 28px 28px;
}

.view {
  display: none;
  gap: 20px;
}

.view.active {
  display: grid;
}

.stats-grid,
.split-grid {
  display: grid;
  gap: 20px;
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.split-grid {
  grid-template-columns: 1.15fr 1fr;
}

.panel,
.stat-card {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.stat-card span,
.stat-card small,
.helper-text,
.field span,
.meta-line,
.item-copy,
.eyebrow {
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin: 14px 0 6px;
  font-size: 2rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.button,
.badge,
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
}

.button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
}

.button.primary {
  color: #fff;
  background: var(--accent);
}

.button.subtle {
  color: var(--text);
  background: var(--surface-soft);
  border-color: var(--border);
}

.badge {
  min-height: 34px;
  padding: 0 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--muted);
}

.filters,
.form-grid {
  display: grid;
  gap: 14px;
}

.filters {
  grid-template-columns: 1.5fr 1fr 1fr auto;
  margin-bottom: 18px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
}

.field textarea {
  min-height: auto;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(28, 109, 208, 0.18);
  border-color: var(--accent);
}

.field-wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: var(--surface-soft);
}

tr:hover td {
  background: #fbfcfd;
}

.table-actions {
  display: flex;
  gap: 8px;
}

.mini-button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
}

.mini-button.danger {
  color: var(--danger);
}

.pill {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.pill.ok {
  background: rgba(31, 138, 84, 0.12);
  color: var(--success);
}

.pill.low {
  background: rgba(191, 123, 16, 0.12);
  color: var(--warning);
}

.pill.out {
  background: rgba(197, 65, 65, 0.12);
  color: var(--danger);
}

.pill.receipt {
  background: rgba(31, 138, 84, 0.12);
  color: var(--success);
}

.pill.sale {
  background: rgba(28, 109, 208, 0.12);
  color: var(--accent);
}

.pill.writeoff {
  background: rgba(197, 65, 65, 0.12);
  color: var(--danger);
}

.pill.return {
  background: rgba(191, 123, 16, 0.12);
  color: var(--warning);
}

.list-stack,
.chart-list {
  display: grid;
  gap: 12px;
}

.work-order-items {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.work-item {
  background: #fdfefe;
}

.inline-space {
  margin-top: 22px;
}

.checkbox-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  color: var(--muted);
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.hidden-field {
  display: none;
}

.chart-row,
.list-item {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.chart-head,
.item-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.chart-track {
  margin-top: 10px;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #dde7f1;
}

.chart-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2e7fe5, #7caef0);
}

.item-copy {
  margin: 8px 0 0;
  line-height: 1.5;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.meta-line {
  padding: 6px 10px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--border);
  font-size: 0.88rem;
}

.empty-state {
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.empty-state p {
  margin: 10px 0 0;
  color: var(--muted);
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 14px;
  color: #fff;
  background: #203040;
  box-shadow: var(--shadow);
  z-index: 20;
}

.toast.error {
  background: var(--danger);
}

.toast.success {
  background: var(--success);
}

@media (max-width: 1200px) {
  .layout,
  .stats-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    gap: 16px;
  }

  .filters,
  .compact-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .main-content,
  .sidebar {
    padding: 16px;
  }

  .form-grid,
  .filters,
  .compact-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
}

.sidebar-toggle {
  display: none;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.table-wrap {
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 760px) {
  .sidebar {
    position: static;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 14px;
    box-shadow: none;
  }

  .brand {
    min-width: 0;
  }

  .brand-kicker {
    display: block;
  }

  .brand-copy {
    display: none;
  }

  .brand h1 {
    font-size: 1.9rem;
  }

  .brand-user {
    margin: 0 0 6px;
  }

  .sidebar-toggle {
    display: none;
  }

  .nav-menu {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
    padding: 10px 8px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
  }

  .sidebar-box {
    display: none;
  }

  .topbar-actions,
  .actions-row {
    width: 100%;
    grid-template-columns: 1fr;
    display: grid;
  }

  .button,
  .mini-button {
    width: 100%;
  }

  #parts-table,
  #parts-table tbody,
  #parts-table tr,
  #parts-table td {
    display: block;
    width: 100%;
  }

  #parts-table tr {
    border-bottom: 1px solid var(--border);
    padding: 10px 0;
  }

  #parts-table td {
    border-bottom: 0;
    padding: 8px 12px;
  }

  #parts-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-size: 0.74rem;
    text-transform: uppercase;
    color: var(--muted);
  }

  #parts-table td:nth-child(2)::before {
    display: none;
  }

  .table-actions {
    flex-direction: column;
  }

  .work-order-items .form-grid {
    grid-template-columns: 1fr;
  }
}

.brand-user {
  margin: 0 0 6px;
  color: #9db4cb;
  font-size: 0.82rem;
}

.logout-form {
  margin-top: 8px;
}

.logout-button {
  width: 100%;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.login-shell {
  width: min(100%, 460px);
  padding: 24px;
}

.login-card {
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 12px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.login-form input {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.form-error {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(197, 65, 65, 0.12);
  color: var(--danger);
}

/* Warehouse workflow fixes: separate controls, readable forms and bounded dialogs. */
#part-form, #movement-form, #supplier-form, #work-order-form { display: grid; gap: 18px; align-content: start; }
.split-grid { align-items: start; }
.panel, .field { min-width: 0; }
.field textarea { display: block; line-height: 1.45; }
.field input[readonly] { background: var(--surface-soft); color: var(--muted); }
.helper-text { overflow-wrap: anywhere; }
button:disabled { opacity: .55; cursor: not-allowed; }
.pill.supplier_return { background: rgba(191, 123, 16, .12); color: var(--warning); text-align: center; }
.part-action-dialog { width: min(480px, calc(100% - 32px)); max-height: calc(100vh - 40px); overflow: auto; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text); background: var(--surface); }
.part-action-dialog::backdrop { background: rgba(15, 25, 40, .5); }
.part-dialog-actions { display: grid; gap: 12px; margin-top: 20px; }
.part-dialog-actions .danger { color: var(--danger); }
@media (max-width: 760px) { .topbar-actions { min-width: 0; } .topbar-actions .button { white-space: normal; } }
