:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #f3f6f9;
  color: #1b2533;
  --surface: #ffffff;
  --surface-soft: #f3f6f9;
  --surface-strong: #e9f0f7;
  --line: #d6e0eb;
  --line-strong: #c4d0dd;
  --text-muted: #617387;
  --primary: #1467b3;
  --primary-soft: #e5f2fc;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --success: #147a40;
  --success-soft: #e3f5eb;
  --warning-soft: #fff5d8;
  --warning-text: #624500;
  --shadow: 0 20px 60px rgba(31, 41, 51, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 7px 12px;
  color: #24313d;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #66788a;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(20, 103, 179, 0.32);
  outline-offset: 1px;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.danger {
  color: var(--danger);
  border-color: #f0b4ad;
  background: var(--danger-soft);
}

.topbar {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand,
.topbar-actions,
.auth,
.filters,
.language-switch {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 220px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #13273f;
  color: #fff;
  font-weight: 700;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.topbar-actions {
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.auth {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.language-switch {
  gap: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.language-switch button {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  padding: 6px 10px;
}

.language-switch button.active {
  background: var(--primary);
  color: #fff;
}

input,
select,
textarea {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 10px;
  background: var(--surface);
  color: #24313d;
}

textarea {
  resize: vertical;
}

#tokenInput {
  width: 132px;
}

#actorInput {
  width: 130px;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: calc(100vh - 72px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 22px 16px;
}

.sidebar-title {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0 8px 10px;
  text-transform: uppercase;
}

#tableNav {
  display: grid;
  gap: 10px;
}

#tableNav button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  border-color: transparent;
  background: transparent;
  min-height: 34px;
  padding: 7px 14px;
}

#tableNav button:hover {
  background: var(--surface-soft);
  border-color: var(--line);
}

#tableNav button.active {
  border-color: #9dc2e6;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

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

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(560px, auto);
  align-items: end;
  gap: 14px;
  margin-bottom: 14px;
}

.table-heading {
  min-width: 0;
}

.toolbar h2 {
  margin: 0 0 5px;
  font-size: 24px;
  line-height: 1.15;
}

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

.filters {
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.filters button {
  min-width: 72px;
}

#newShipmentBtn {
  min-width: 136px;
}

#searchInput {
  width: 250px;
}

.filter-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 16px;
  color: var(--text-muted);
  font-size: 13px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 4px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

.message {
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--warning-soft);
  color: var(--warning-text);
  margin-bottom: 12px;
}

.message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  justify-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 12px;
  text-align: center;
  padding: 24px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.empty-state p {
  margin: 0;
  color: var(--text-muted);
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  max-height: calc(100vh - 250px);
}

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

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

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

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f8fbfe;
}

td.wrap {
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

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

.pager-controls label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  justify-content: flex-end;
  background: rgba(19, 39, 63, 0.28);
}

.drawer.open {
  display: flex;
}

.drawer-panel {
  width: min(620px, 100vw);
  height: 100%;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 28px;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.detail-body,
.form-sections {
  display: grid;
  gap: 14px;
}

.detail-section,
.form-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
}

.detail-section h4,
.form-section h4 {
  margin: 0 0 12px;
  font-size: 14px;
}

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

.detail-field,
.field {
  min-width: 0;
}

.detail-field dt,
.field label {
  display: block;
  color: #4b5b68;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 5px;
}

.detail-field dd {
  min-height: 28px;
  margin: 0;
  word-break: break-word;
}

.field.full,
.detail-field.full {
  grid-column: 1 / -1;
}

.field .help {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.field .error-text {
  margin-top: 4px;
  color: var(--danger);
  font-size: 12px;
}

.field.invalid input,
.field.invalid select,
.field.invalid textarea {
  border-color: #e18b82;
}

.json-block {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border-radius: 6px;
  background: #0f1720;
  color: #eef5ff;
  font-size: 12px;
  white-space: pre-wrap;
}

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

dialog::backdrop {
  background: rgba(22, 32, 43, 0.34);
}

.dialog-card {
  padding: 24px;
}

.dialog-card.compact {
  width: min(560px, calc(100vw - 32px));
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

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

.icon-btn {
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.diff-list {
  display: grid;
  gap: 8px;
  max-height: 60vh;
  overflow: auto;
}

.diff-row {
  display: grid;
  grid-template-columns: 130px 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.diff-row strong {
  font-size: 13px;
}

.diff-value {
  min-width: 0;
  padding: 8px;
  border-radius: 6px;
  background: var(--surface-soft);
  word-break: break-word;
  font-size: 12px;
}

@media (max-width: 980px) {
  .topbar,
  .toolbar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-direction: column;
  }

  .brand,
  .topbar-actions,
  .auth,
  .filters {
    justify-content: flex-start;
  }

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  #tableNav {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

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

@media (max-width: 700px) {
  .topbar,
  .content {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar-actions,
  .auth,
  .filters,
  .auth input,
  .filters input,
  .filters select,
  .filters button,
  .pagination,
  .pager-controls {
    width: 100%;
  }

  .language-switch {
    width: 100%;
  }

  .language-switch button,
  .pager-controls button,
  .pager-controls label {
    flex: 1;
  }

  .pagination {
    align-items: stretch;
    flex-direction: column;
  }

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

  .drawer-panel {
    padding: 16px;
  }
}
