:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #6b7280;
  --border: #d9e0e7;
  --primary: #2154d6;
  --primary-hover: #173da3;
  --danger: #c0392b;
  --danger-hover: #962d22;
  --ok-bg: #e8f7ef;
  --ok-text: #17643a;
  --warn-bg: #fff4d6;
  --warn-text: #7b5600;
  --err-bg: #ffe5e0;
  --err-text: #8d2416;
  --shadow: 0 10px 30px rgba(20, 33, 61, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  height: 72px;
  background: #101827;
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid #263244;
}

.brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.subtitle {
  color: #b8c2d6;
  font-size: 13px;
  margin-top: 4px;
}


.version-badge {
  font-size: 13px;
  border: 1px solid rgba(191, 219, 254, 0.45);
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.16);
  color: #bfdbfe;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.version-badge.warning {
  color: #fde68a;
  border-color: rgba(253, 230, 138, 0.45);
  background: rgba(180, 83, 9, 0.18);
}
.health {
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
}

.health.ok { color: #a7f3d0; border-color: rgba(167,243,208,0.4); }
.health.error { color: #fecaca; border-color: rgba(254,202,202,0.4); }

.layout {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 18px;
  padding: 18px;
  min-height: calc(100vh - 72px);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: 14px;
}

.sidebar {
  padding: 16px;
  overflow: auto;
}

.content {
  padding: 20px;
  overflow: auto;
}

.panel-header,
.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1, h2, h3 { margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

.form-block {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfe;
}

label {
  display: block;
  font-size: 13px;
  color: #374151;
  margin-bottom: 10px;
}

input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 10px 11px;
  font: inherit;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: white;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33, 84, 214, 0.12);
}

button {
  border: none;
  border-radius: 9px;
  padding: 10px 14px;
  font-weight: 700;
  color: white;
  background: var(--primary);
  cursor: pointer;
}

button:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
button.secondary { background: #e8eef9; color: #1f3b77; }
button.secondary:hover { background: #d9e3f7; }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-hover); }

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shipment-item {
  text-align: left;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition: 0.15s ease;
}

.shipment-item:hover,
.shipment-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(33, 84, 214, 0.08);
}

.shipment-number {
  font-weight: 700;
  margin-bottom: 4px;
}

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

.empty, .muted {
  color: var(--muted);
}

.empty-state {
  min-height: 430px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h1 { color: var(--text); margin-bottom: 8px; }
.hidden { display: none !important; }

.cards-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.mini-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  background: #fbfcfe;
}

.mini-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.mini-value {
  font-size: 18px;
  font-weight: 700;
  word-break: break-word;
}

.mini-value.small {
  font-size: 14px;
  font-weight: 500;
}

.upload-box {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  background: #fbfcfe;
  margin-bottom: 20px;
}

.upload-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.upload-actions { padding-bottom: 10px; }

.field-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}


.notice {
  margin-top: 12px;
  white-space: pre-line;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
}
.notice.ok { background: var(--ok-bg); color: var(--ok-text); border-color: #b9e4ca; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); border-color: #ead38a; }
.notice.error { background: var(--err-bg); color: var(--err-text); border-color: #f3b7ad; }

.docs-header { margin-bottom: 12px; }
.documents-list {
  display: grid;
  gap: 10px;
}

.document-card {
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 14px;
  background: white;
}

.document-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.document-name {
  font-weight: 700;
  font-size: 16px;
  word-break: break-word;
}

.badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: #334155;
  white-space: nowrap;
}

.badge.warn { background: var(--warn-bg); color: var(--warn-text); border-color: #ead38a; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); border-color: #b9e4ca; }
.badge.info { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.badge.error { background: var(--err-bg); color: var(--err-text); border-color: #f3b7ad; }

.doc-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  color: #374151;
  font-size: 13px;
}

.doc-field {
  padding: 8px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  min-width: 0;
}

.doc-field-label {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.hash {
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  word-break: break-all;
}

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  max-width: 420px;
  padding: 13px 15px;
  border-radius: 12px;
  background: #101827;
  color: white;
  box-shadow: var(--shadow);
  z-index: 1000;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .upload-grid { grid-template-columns: 1fr; }
  .upload-actions { padding-bottom: 0; }
  .cards-row { grid-template-columns: 1fr; }
  .doc-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .topbar { height: auto; padding: 16px; align-items: flex-start; gap: 12px; flex-direction: column; }
  .layout { padding: 10px; }
  .details-header { align-items: flex-start; flex-direction: column; }
  .doc-grid { grid-template-columns: 1fr; }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.user-pill {
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  color: #e5e7eb;
}

.login-layout {
  min-height: calc(100vh - 72px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.login-panel {
  width: 100%;
  max-width: 460px;
  padding: 22px;
}

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

.admin-panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfe;
}

.admin-panel h2 {
  margin-bottom: 10px;
}

button.full {
  width: 100%;
  margin-top: 8px;
}

.user-grid {
  margin: 14px 0 18px;
  display: grid;
  grid-template-columns: 1fr 1.3fr 0.8fr 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfe;
}

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

.document-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.processing-panel {
  margin-top: 12px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fbfcfe;
  padding: 10px;
}

.processing-run {
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
  margin-top: 10px;
}

.processing-run:first-child {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.processing-json {
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  background: #0f172a;
  color: #d1e7ff;
  border-radius: 9px;
  font: 12px/1.4 Consolas, Monaco, monospace;
  max-height: 320px;
  white-space: pre-wrap;
}

.subsection-title {
  margin: 14px 0 8px;
  font-size: 14px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 9px;
  overflow: hidden;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 8px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
  word-break: break-word;
}

.data-table th {
  background: #f1f5f9;
  color: #475569;
  font-weight: 700;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.processing-json.compact {
  max-height: 160px;
}

.json-details {
  margin-top: 12px;
}

.json-details summary {
  cursor: pointer;
  color: #1f3b77;
  font-weight: 700;
}

.rule-grid {
  margin: 14px 0 18px;
  display: grid;
  grid-template-columns: 0.9fr 0.8fr 1.4fr auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fbfcfe;
}

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

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Stage 7 */
.doc-type-inline,
.check-resolution-select,
.notification-status-select {
  border: 1px solid #d8e0ec;
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
  color: #17324d;
  font-size: 13px;
}
button.mini,
.secondary.mini {
  padding: 7px 10px;
  font-size: 12px;
}
.compact-actions {
  margin-top: 8px;
  gap: 8px;
  flex-wrap: wrap;
}
.line-item-card {
  border: 1px solid #dfe7f2;
  border-radius: 12px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fbfdff;
}
.muted-line {
  opacity: 0.62;
}
.manual-status {
  margin-bottom: 6px;
  color: #52677f;
  font-size: 12px;
}

.ai-settings-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* Stage 9.0.5: readable conflict diagnostics in shipment summary */
.summary-attention {
  margin: 8px 0 14px;
}

.summary-attention-ok {
  margin-top: 8px;
}

.summary-attention-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.attention-card-error {
  border-color: #f3b7ad;
  background: var(--err-bg);
}

.attention-card-warn {
  border-color: #ead38a;
  background: var(--warn-bg);
}

.summary-problems-details,
.field-source-details {
  margin-top: 6px;
}

.summary-problems-details summary,
.field-source-details summary {
  cursor: pointer;
  color: #1f3b77;
  font-weight: 700;
}

.field-source-details summary {
  font-size: 12px;
}

.summary-alternatives {
  margin: 7px 0;
  color: #334155;
}

.mini-source-table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 11px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.mini-source-table th,
.mini-source-table td {
  text-align: left;
  padding: 6px;
  border-bottom: 1px solid #e5e7eb;
  vertical-align: top;
}

.mini-source-table th {
  background: #f8fafc;
  color: #475569;
}

.mini-source-table tr:last-child td {
  border-bottom: none;
}

.data-table tr.row-error td {
  background: #fff7f5;
}

.data-table tr.row-warn td {
  background: #fffbeb;
}

.summary-problems-table td:nth-child(4),
.summary-fields-table td:nth-child(2) {
  min-width: 260px;
}

@media (max-width: 1100px) {
  .summary-attention-cards { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .summary-attention-cards { grid-template-columns: 1fr; }
}
