* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: #0f172a;
  background: #f5f7fb;
}

.brand-wordmark {
  margin: 0 0 6px;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.15;
  color: #123f5c;
  background: linear-gradient(105deg, #123f5c 0%, #0f766e 55%, #14b8a6 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .brand-wordmark {
    color: transparent;
  }
}

.brand-wordmark--topbar {
  margin: 0;
  font-size: 1.28rem;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(500px, 100%);
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

.login-card h1 {
  margin: 16px 0 8px;
}

.google-signin {
  margin-top: 20px;
}

.error-msg {
  color: #b91c1c;
  min-height: 24px;
  margin-top: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #dbe2ef;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.env-badge {
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #0f766e;
  background: #ccfbf1;
  border: 1px solid #99f6e4;
  padding: 3px 8px;
  border-radius: 999px;
}

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

.tabbar {
  position: sticky;
  top: 53px;
  z-index: 9;
  display: flex;
  gap: 6px;
  padding: 0 20px;
  background: #fff;
  border-bottom: 1px solid #dbe2ef;
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 18px 14px;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  cursor: pointer;
  color: #64748b;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  color: #123f5c;
}

.tab-btn.is-active {
  color: #0f766e;
  border-bottom-color: #14b8a6;
}

.tab-title {
  font-size: 1rem;
  font-weight: 700;
}

.tab-sub {
  font-size: 0.76rem;
  color: #94a3b8;
}

.tab-btn.is-active .tab-sub {
  color: #5eead4;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-caption {
  margin: 4px 0 0;
  font-size: 0.86rem;
  color: #64748b;
}

.panel-caption code,
.muted code {
  background: #eef2ff;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.82rem;
}

.panel-form {
  max-width: 620px;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-row .muted {
  margin: 2px 0 0;
}

.req {
  color: #dc2626;
}

.optional {
  color: #94a3b8;
  font-weight: 400;
  font-size: 0.82rem;
}

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

.form-actions .primary-btn {
  padding: 10px 20px;
  font-size: 0.95rem;
}

.result-card {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 0.9rem;
}

.result-card.error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.result-card.hidden {
  display: none;
}

.result-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 10px 0 0;
}

.result-grid dt {
  font-weight: 600;
  color: #047857;
}

.result-grid dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.user-pill {
  background: #eef2ff;
  color: #312e81;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.page {
  padding: 20px;
  max-width: 100%;
}

.panel {
  background: #fff;
  border: 1px solid #dbe2ef;
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.summary-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
}

.summary-label {
  display: block;
  font-size: 0.82rem;
  color: #64748b;
  margin-bottom: 4px;
}

.summary-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #123f5c;
}

.muted {
  color: #64748b;
  font-size: 0.9rem;
}

.primary-btn,
.secondary-btn,
.row-call-btn,
a.secondary-btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.primary-btn {
  background: linear-gradient(135deg, #6366f1, #312e81);
  color: #fff;
}

.primary-btn:disabled,
.secondary-btn:disabled,
.row-call-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.secondary-btn,
.row-call-btn {
  background: #fff;
  color: #312e81;
  border: 1px solid #c7d2fe;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

.text-input {
  width: min(360px, 100%);
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 1rem;
}

.language-fieldset {
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}

.language-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin: 6px 0 8px;
}

.language-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.language-option input {
  margin: 0;
}

.panel-table {
  padding: 0;
  overflow: hidden;
}

.table-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #fafbff;
}

.filter-field {
  flex: 1 1 180px;
  min-width: 160px;
}

.filter-input {
  width: 100%;
}

.table-wrap {
  overflow: auto;
  max-height: 70vh;
}

table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
}

thead th {
  position: sticky;
  top: 0;
  background: #eef2ff;
  color: #1e1b4b;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid #c7d2fe;
  white-space: nowrap;
  font-size: 0.85rem;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
  font-size: 0.88rem;
  max-width: 280px;
  white-space: normal;
}

.customer-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.customer-name {
  font-weight: 600;
  color: #123f5c;
}

.docs-cell,
.tags-cell {
  min-width: 220px;
  max-width: 320px;
}

.doc-name-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.doc-name-chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  background: #f1f5f9;
  color: #334155;
}

.doc-name-chip:hover {
  filter: brightness(0.97);
}

.doc-name-chip--missing {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.doc-name-chip--received {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

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

.doc-item {
  padding: 8px 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}

.doc-item-title {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.doc-name {
  font-weight: 600;
  color: #1e293b;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.doc-item-detail,
.doc-item-comment {
  margin-top: 4px;
  font-size: 0.8rem;
  color: #475569;
  line-height: 1.35;
}

.doc-item-comment {
  font-style: italic;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.doc-tag {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  font-size: 0.78rem;
  white-space: normal;
}

tbody tr:nth-child(even) {
  background: #fafbff;
}

tbody tr.selected {
  background: #ecfeff;
}

.json-cell pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  max-width: 380px;
  max-height: 200px;
  overflow: auto;
  background: #f1f5f9;
  padding: 8px;
  border-radius: 6px;
}

/* legacy json-cell kept for compatibility */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #1e293b;
  color: #f8fafc;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  max-width: min(420px, 90vw);
  z-index: 100;
}

.toast.hidden {
  display: none;
}

.toast.error {
  background: #991b1b;
}

.spinner-inline::after {
  content: " …";
  animation: pulse 1s infinite;
}

@keyframes pulse {
  50% { opacity: 0.4; }
}

.back-link {
  color: #475569;
  text-decoration: none;
  font-size: 0.9rem;
  margin-right: 12px;
}

.back-link:hover {
  color: #123f5c;
  text-decoration: underline;
}

.prioritized-search-row {
  position: relative;
}

.prioritized-search-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.prioritized-search-controls .text-input {
  flex: 1;
}

.search-results {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  max-height: 240px;
  overflow: auto;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.search-results.hidden {
  display: none;
}

.search-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.92rem;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus {
  background: #ecfeff;
  outline: none;
}

.prioritized-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.prioritized-item {
  display: grid;
  grid-template-columns: auto auto 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 8px;
  background: #fff;
}

.prioritized-item.is-dragging {
  opacity: 0.55;
}

.prioritized-item.drag-over {
  border-color: #6366f1;
  background: #eef2ff;
}

.drag-handle {
  cursor: grab;
  color: #64748b;
  font-size: 1.1rem;
  user-select: none;
}

.prioritized-rank {
  font-weight: 700;
  color: #123f5c;
  min-width: 1.5rem;
}

.prioritized-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #475569;
}

.prioritized-name {
  font-weight: 500;
}

.prioritized-item .remove-btn {
  padding: 6px 10px;
  font-size: 0.85rem;
}

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

.prioritized-footer-actions {
  display: flex;
  gap: 8px;
}

.save-banner {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
  font-size: 0.92rem;
}

.save-banner.hidden {
  display: none;
}
