:root {
  color-scheme: light;
  --paper: #f7f7f2;
  --surface: #ffffff;
  --ink: #202423;
  --muted: #69716e;
  --line: #dfe3dc;
  --line-strong: #c3cbc1;
  --green: #2e6b57;
  --green-soft: #e7f1ec;
  --amber: #9a641d;
  --amber-soft: #fff0d7;
  --red: #a43d36;
  --red-soft: #fde8e5;
  --blue: #315c8a;
  --blue-soft: #e6eff8;
  --plum: #65506f;
  --shadow: 0 10px 30px rgba(32, 36, 35, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

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

button,
.file-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: #8fa096;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  min-height: 36px;
  padding: 7px 9px;
}

textarea {
  min-height: 210px;
  resize: vertical;
  line-height: 1.45;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.dashboard-grid table {
  min-width: 0;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: #fafbf8;
  position: sticky;
  top: 0;
  z-index: 1;
}

td.numeric,
th.numeric {
  text-align: right;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #f1f3ec;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--green);
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3 {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
  line-height: 1.1;
}

.brand p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.role-switcher {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.role-switcher > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.role-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.role-button {
  min-height: 34px;
  padding: 0 8px;
  font-weight: 750;
}

.role-button.active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

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

.nav-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border-color: transparent;
  background: transparent;
  justify-content: flex-start;
  font-weight: 650;
}

.nav-button.active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.nav-button[hidden],
[hidden] {
  display: none !important;
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #e3e7df;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(247, 247, 242, 0.92), rgba(241, 243, 236, 0.92)),
    url("icon.svg") center 14% / 160px 160px no-repeat;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  padding: 0 0 6px;
}

.login-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.login-status.is-error {
  color: var(--red);
}

.account-panel {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.account-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.account-panel strong {
  font-size: 15px;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

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

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

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

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 750;
}

.topbar-actions,
.action-row,
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button {
  background: var(--green);
  border-color: var(--green);
  color: white;
  font-weight: 750;
}

.secondary-button {
  background: #f9faf6;
  font-weight: 700;
}

.ghost-button {
  background: transparent;
}

.file-button {
  display: inline-grid;
  place-items: center;
  font-weight: 700;
  color: var(--ink);
}

.file-button input {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

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

.metric-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 15px;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.metric-card small {
  display: block;
  color: var(--muted);
  margin-top: 5px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 14px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

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

.panel h3 {
  font-size: 16px;
}

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

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 250px);
}

.form-grid {
  display: grid;
  grid-template-columns: 1.5fr 160px 140px;
  gap: 12px;
  padding: 14px 15px;
}

.receiving-controls {
  grid-template-columns: minmax(250px, 1.4fr) repeat(3, minmax(130px, 0.75fr)) minmax(180px, 0.9fr);
}

#orderText {
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  padding: 14px 15px;
}

.action-row {
  justify-content: flex-end;
  padding: 12px 15px;
  border-top: 1px solid var(--line);
}

.filter-row {
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
}

.filter-row label {
  width: 260px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-weight: 750;
  font-size: 12px;
}

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

.status-warning {
  background: var(--amber-soft);
  color: var(--amber);
}

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

.status-info {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-muted {
  background: #ecefec;
  color: var(--muted);
}

.receiving-table {
  min-width: 1080px;
}

.receiving-table input,
.receiving-table select {
  min-width: 92px;
}

.receiving-table textarea {
  min-width: 150px;
  min-height: 36px;
  padding: 7px 9px;
}

.receiving-table-wrap {
  max-height: calc(100vh - 330px);
}

.photo-preview {
  display: none;
  padding: 0 15px 12px;
}

.ai-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 15px 12px;
  color: var(--muted);
  font-size: 12px;
}

.photo-preview.active {
  display: block;
}

.photo-preview img {
  max-width: 210px;
  max-height: 150px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.price-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 15px;
  border-bottom: 1px solid var(--line);
}

.summary-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcf8;
}

.summary-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-cell strong {
  display: block;
  font-size: 18px;
  margin-top: 5px;
}

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

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .nav-button {
    justify-content: center;
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .metric-grid,
  .dashboard-grid,
  .price-summary,
  .form-grid,
  .receiving-controls {
    grid-template-columns: 1fr;
  }

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

  .main-panel {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 13px;
  }

  .brand {
    padding-bottom: 2px;
  }

  .nav-list {
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  }

  .nav-icon {
    display: none;
  }

  .panel-heading,
  .ai-strip,
  .action-row,
  .filter-row {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-row label {
    width: 100%;
  }
}
