:root {
  color-scheme: light;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #d7e0ea;
  --border-strong: #aec0d1;
  --text: #17202a;
  --muted: #657386;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --blue: #2563eb;
  --amber: #b45309;
  --green: #15803d;
  --red: #b91c1c;
  --shadow: 0 12px 28px rgba(21, 35, 52, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  line-height: 1.45;
}

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

.brand,
.top-actions,
.card-actions,
.compact-form,
.user-card,
.comment-toolbar,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  position: relative;
}

.brand-mark,
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.brand-mark {
  width: 40px;
  height: 40px;
  font-size: 15px;
}

.avatar {
  width: 34px;
  height: 34px;
  font-size: 15px;
}

.user-card {
  position: relative;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.user-card span,
.user-card small {
  display: block;
  white-space: nowrap;
}

.user-card span {
  font-size: 13px;
  font-weight: 800;
}

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

.eyebrow {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 23px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

h3 {
  margin-bottom: 14px;
  font-size: 16px;
}

button,
input,
textarea {
  font: inherit;
}

.ui-button,
.icon-button {
  min-height: 38px;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.ui-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.ui-button-primary {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
}

.ui-button-primary:hover {
  background: var(--primary-hover);
}

.ui-button-neutral {
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: #1d3448;
}

.ui-button-neutral:hover {
  background: #e8f1f6;
}

.ui-button-danger {
  border: 1px solid #f0b4b4;
  background: #fff5f5;
  color: var(--red);
}

.ui-button-danger:hover {
  background: #fee2e2;
}

.icon-button {
  width: 36px;
  padding: 0;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 22px;
  line-height: 1;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(520px, 1.15fr) minmax(420px, 0.85fr);
  gap: 20px;
  padding: 20px;
  align-items: start;
}

.list-panel,
.details-panel {
  min-width: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.list-create-button {
  margin-left: auto;
}

.counter {
  min-width: 28px;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e6f2f1;
  color: var(--primary-hover);
  text-align: center;
  font-size: 13px;
  font-weight: 800;
}

.table-wrap,
.card-details,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow: auto;
}

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

th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

td .badge {
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f9fbfd;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: #eef8f7;
}

.badge,
.step-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
}

.badge {
  background: #eaf0ff;
  color: var(--blue);
}

.badge.review {
  background: #fff4df;
  color: var(--amber);
}

.badge.done {
  background: #e7f6ec;
  color: var(--green);
}

.badge.return {
  background: #fff7ed;
  color: #c2410c;
}

.badge.reject {
  background: #fee2e2;
  color: var(--red);
}

.step-pill {
  background: #e6f2f1;
  color: var(--primary-hover);
}

.card-details {
  padding: 20px;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.card-actions {
  flex-wrap: wrap;
  padding: 14px 0 0;
}

.card-id {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.card-header h2 {
  font-size: 21px;
}

.status-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

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

.detail-grid {
  display: grid;
  grid-template-columns: minmax(170px, 0.34fr) minmax(0, 1fr);
  gap: 0;
  margin: 16px 0;
}

.detail-item {
  display: contents;
}

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

.detail-label,
label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.detail-value {
  min-width: 0;
  margin-bottom: 0;
  padding: 9px 0;
  white-space: pre-wrap;
  font-size: 15px;
}

.detail-label {
  margin: 0;
  padding: 9px 14px 9px 0;
}

.text-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.compact-form {
  flex-wrap: wrap;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  margin: 0;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: #1d3448;
  cursor: pointer;
  font-weight: 800;
  box-shadow: none;
}

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

.user-menu {
  position: absolute;
  top: 54px;
  right: 0;
  z-index: 30;
  min-width: 190px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.menu-action {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-weight: 800;
}

.menu-action:hover {
  background: var(--surface-2);
}

.danger-text {
  color: var(--red);
}

.attachment-link {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface-2);
  color: var(--blue);
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
}

.attachment-item {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.attachment-item .attachment-link {
  padding-right: 32px;
}

.attachment-delete {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 22px;
  height: 22px;
  border: 1px solid #f0b4b4;
  border-radius: 50%;
  background: #fff5f5;
  color: var(--red);
  cursor: pointer;
  font-size: 15px;
  font-weight: 900;
  line-height: 20px;
  text-align: center;
  padding: 0;
}

.route-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: route;
}

.route-list li {
  position: relative;
  min-height: 62px;
  margin-bottom: 9px;
  padding: 9px 10px 9px 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  counter-increment: route;
  color: var(--muted);
}

.route-list li.active {
  border-color: #14b8a6;
  background: #ecfdf5;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.12);
}

.route-list li.approved {
  border-color: #86efac;
  background: #f0fdf4;
  color: var(--green);
}

.route-list li.returned {
  border-color: #fdba74;
  background: #fff7ed;
  color: #c2410c;
}

.route-list li.rejected {
  border-color: #fca5a5;
  background: #fef2f2;
  color: var(--red);
}

.route-list li.pending {
  opacity: 0.86;
}

.route-list li::before {
  content: counter(route);
  position: absolute;
  left: 11px;
  top: 11px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #e7eef5;
  color: #315168;
  font-size: 12px;
  font-weight: 900;
}

.route-list li.active::before {
  background: var(--primary);
  color: #fff;
}

.route-list li.approved::before {
  background: #22c55e;
  color: #fff;
}

.route-list li.returned::before {
  background: #f97316;
  color: #fff;
}

.route-list li.rejected::before {
  background: #ef4444;
  color: #fff;
}

.route-step-title {
  display: block;
  color: var(--text);
  font-weight: 900;
}

.route-step-meta {
  display: block;
  margin-top: 3px;
  font-size: 12px;
}

.route-decision-button {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin-top: 8px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.approval-actions {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.inline-actions {
  margin-top: 12px;
  margin-left: -38px;
  width: calc(100% + 38px);
}

.action-card {
  flex: 1 1 170px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.action-card strong,
.action-card span {
  display: block;
}

.action-card strong {
  margin-bottom: 4px;
}

.action-card span {
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
}

.action-card .ui-button {
  width: 100%;
  margin-top: 10px;
}

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

.comment-form,
.comments {
  display: grid;
  gap: 10px;
}

.comment-form {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #f7fbfc;
}

.comment-form textarea {
  min-height: 150px;
}

.comment-toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.comment-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.comment {
  border-left: 3px solid var(--primary);
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
  background: var(--surface-2);
}

.comment-meta {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.dialog {
  width: min(920px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.small-dialog {
  width: min(520px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.35);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  background: #17202a;
  color: #fff;
  box-shadow: var(--shadow);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  gap: 12px;
  background: rgba(244, 247, 250, 0.76);
  color: var(--text);
}

.loading-overlay > * {
  grid-column: 1;
  grid-row: 1;
}

.loading-overlay strong {
  transform: translateY(40px);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #cbd5e1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

body.busy .workspace,
body.busy .topbar {
  pointer-events: none;
  user-select: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

@media (max-width: 760px) {
  .topbar,
  .top-actions,
  .card-header,
  .status-stack {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    padding: 16px;
  }

  .workspace {
    padding: 12px;
  }

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