:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #dde4e8;
  --line-strong: #c7d3d9;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #43a9bd;
  --accent-dark: #24788b;
  --accent-soft: #e8f6f9;
  --danger: #bd3d36;
  --success: #2f8f66;
  --shadow: 0 22px 70px rgba(31, 41, 51, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

a {
  color: inherit;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 22px;
  min-height: 54px;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 18px;
  font-weight: 700;
  gap: 9px;
  text-decoration: none;
}

.brand-mark {
  align-items: center;
  background: var(--accent);
  border-radius: 6px;
  color: #ffffff;
  display: inline-flex;
  font-size: 13px;
  height: 26px;
  justify-content: center;
  width: 26px;
}

.nav {
  align-items: center;
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.nav a,
.nav button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: #354351;
  cursor: pointer;
  font: inherit;
  padding: 17px 10px 15px;
  text-decoration: none;
}

.nav a:hover,
.nav button:hover {
  border-bottom-color: var(--accent);
  color: var(--accent-dark);
}

.nav form {
  margin: 0;
}

.page {
  margin: 0 auto;
  max-width: 1680px;
  padding: 24px 28px 36px;
}

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

.page-header h1,
.auth-panel h1,
.modal-card h1 {
  font-size: 28px;
  line-height: 1.15;
  margin: 0 0 6px;
}

.page-header p,
.modal-card p {
  color: var(--muted);
  margin: 0;
}

.toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button,
.search button,
.form button {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 5px;
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  min-height: 38px;
  padding: 9px 16px;
  text-decoration: none;
}

.button:hover,
.search button:hover,
.form button:hover {
  background: var(--accent-dark);
}

.button.secondary {
  background: #eef3f5;
  color: var(--text);
}

.button.secondary:hover {
  background: #dfe8ec;
}

.icon-button {
  align-items: center;
  background: #eef3f5;
  border: 1px solid transparent;
  border-radius: 5px;
  color: #52616f;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 16px;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.icon-button:hover {
  border-color: var(--line-strong);
  color: var(--accent-dark);
}

.workspace-panel,
.section,
.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.workspace-panel {
  margin-bottom: 12px;
  padding: 12px;
}

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

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
}

.stat span,
.stat small {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.stat strong {
  display: block;
  font-size: 30px;
  line-height: 1;
  margin: 9px 0 6px;
}

.section {
  overflow: hidden;
}

.form-section {
  margin: 0 auto;
  max-width: 720px;
  padding: 22px;
}

.section-header {
  align-items: center;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 48px;
  padding: 12px 16px;
}

.section-header h2 {
  font-size: 17px;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  background: var(--surface-soft);
  color: #596674;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

tbody tr:hover {
  background: #fbfdfe;
}

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

.table-link {
  color: var(--text);
  font-weight: 650;
  text-decoration-color: #c5d4da;
  text-underline-offset: 3px;
}

.table-link:hover {
  color: var(--accent-dark);
}

.search {
  align-items: center;
  display: flex;
  gap: 10px;
  margin: 0;
}

.search-field {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  display: flex;
  gap: 8px;
  min-width: 360px;
  padding: 0 10px;
}

.search-field span {
  color: var(--muted);
  font-size: 20px;
}

.search input,
.form input,
.form select,
.form textarea,
.search select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 9px 11px;
  width: 100%;
}

.search-field input {
  border: 0;
  min-width: 0;
  outline: 0;
  padding-left: 0;
}

.search select {
  min-width: 210px;
  width: auto;
}

.inline-check {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  gap: 7px;
  min-height: 38px;
  white-space: nowrap;
}

.inline-check input,
.check-row input {
  accent-color: var(--accent);
  height: 16px;
  width: 16px;
}

.auth-panel {
  margin: 48px auto;
  max-width: 420px;
  padding: 28px;
}

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

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

.form label {
  color: #394655;
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.form label:has(textarea),
.form .form-actions,
.form .check-row,
.form > ul,
.form > .errorlist {
  grid-column: 1 / -1;
}

.check-row {
  align-items: center;
  display: flex !important;
  gap: 10px;
}

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

.form-actions {
  margin-top: 4px;
}

.actions {
  justify-content: flex-end;
  white-space: nowrap;
}

.actions a {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 650;
}

.status-pill {
  align-items: center;
  background: #e9f7f0;
  border: 1px solid #c7ead9;
  border-radius: 999px;
  color: var(--success);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  min-height: 24px;
  padding: 3px 9px;
  white-space: nowrap;
}

.status-pill.soft {
  background: var(--accent-soft);
  border-color: #c8e9ef;
  color: var(--accent-dark);
}

.status-pill.muted {
  background: #eef1f3;
  border-color: #d8dee2;
  color: #6e7a86;
}

.status-pill.warning {
  background: #fff5df;
  border-color: #f3d391;
  color: #9a6400;
}

.stat-text {
  font-size: 20px !important;
  line-height: 1.15 !important;
  overflow-wrap: anywhere;
}

.inventory-form {
  margin: 0;
}

.quantity-cell input {
  max-width: 160px;
}

.table-actions {
  align-items: center;
  background: var(--surface-soft);
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 16px;
}

.danger-link {
  color: var(--danger) !important;
}

.danger-button {
  background: var(--danger) !important;
}

.confirm-text,
.field-error,
.help-text {
  color: var(--muted);
}

.field-error {
  color: var(--danger);
  font-weight: 500;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.message {
  background: #edf8f5;
  border: 1px solid #bfe4d9;
  border-radius: 6px;
  color: #17654d;
  padding: 11px 13px;
}

.detail-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 0.75fr) minmax(0, 1.25fr);
}

.detail-panel {
  padding: 18px;
}

.detail-panel h2 {
  font-size: 17px;
  margin: 0 0 14px;
}

.detail-list {
  display: grid;
  gap: 10px 16px;
  grid-template-columns: 132px 1fr;
  margin: 0;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
}

.compact table {
  min-width: 560px;
}

.modal {
  background: transparent;
  border: 0;
  max-height: 100vh;
  max-width: 100vw;
  padding: 0;
  width: 100vw;
}

.modal::backdrop {
  background: rgba(28, 32, 35, 0.58);
}

.modal-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: relative;
}

.modal-body {
  width: min(100%, 760px);
}

.modal-close {
  background: transparent;
  border: 0;
  color: #74818d;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  padding: 0;
  position: fixed;
  right: max(28px, calc(50vw - 352px));
  top: max(28px, calc(50vh - 258px));
  z-index: 2;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  margin: 42px auto;
  max-width: 560px;
  padding: 34px 38px;
  width: min(100%, 560px);
}

.modal-card-wide {
  max-width: 760px;
  width: min(100%, 760px);
}

.modal-header {
  margin-bottom: 22px;
}

.modal-header h1 {
  font-size: 24px;
}

.modal-loading {
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  color: var(--muted);
  padding: 28px;
  text-align: center;
}

@media (max-width: 900px) {
  .topbar,
  .nav,
  .search,
  .page-header,
  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 14px 16px;
    position: static;
  }

  .nav {
    margin-left: 0;
  }

  .nav a,
  .nav button {
    padding: 10px 0;
  }

  .page {
    padding: 20px 14px;
  }

  .toolbar {
    justify-content: flex-start;
  }

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

  .search-field,
  .search select {
    min-width: 0;
    width: 100%;
  }

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

  .modal-shell {
    align-items: flex-end;
    padding: 12px;
  }

  .modal-card {
    margin: 0;
    max-height: calc(100vh - 24px);
    overflow: auto;
    padding: 28px 22px;
    width: 100%;
  }

  .modal-close {
    color: #53606d;
    right: 28px;
    top: 28px;
  }
}

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