/* Famatel Board — matches the desktop Work Order Board theme */

:root {
  --bg: #36393f;
  --surface: #2c2f33;
  --surface-alt: #32363c;
  --header-bg: #23272a;
  --text: #e6e6e6;
  --text-bright: #ffffff;
  --muted: #b9bbbe;
  --muted-dim: #72767d;
  --border: #40444b;
  --border-input: #4f545c;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-pressed: #3c45a5;
  --accent-soft: rgba(88, 101, 242, 0.15);
  --accent-soft-strong: rgba(88, 101, 242, 0.3);
  --green: #3ba55d;
  --green-dark: #2d8f4e;
  --red: #ed4245;
  --red-dark: #c03537;
  --pill-low: #5a7d69;
  --pill-mid: #9a8655;
  --pill-high: #996568;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  overflow-x: hidden;
  min-height: 100vh;
}

header {
  background: var(--header-bg);
  border-bottom: 2px solid var(--accent);
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  width: 100%;
  max-width: 100%;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-logo {
  height: 36px;
  width: auto;
  display: block;
}

header nav { display: flex; gap: 0.35rem; flex-wrap: wrap; }

header nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  border: 1px solid transparent;
}

header nav a.active {
  background: var(--accent-soft);
  color: var(--text-bright);
  border-color: var(--accent);
}

header nav a.nav-with-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}

.nav-badge:empty {
  display: none;
}

header nav a:hover {
  background: var(--accent-soft);
  color: var(--text-bright);
}

header .spacer { flex: 1; }
header .user { color: var(--muted); font-size: 0.95rem; }

header .header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lang-switcher {
  display: inline-flex;
  align-items: center;
  margin: 0;
}

.lang-switcher select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.28rem 1.6rem 0.28rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%239aa3b2' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.45rem center;
  background-size: 8px 5px;
}

.lang-switcher select:hover,
.lang-switcher select:focus {
  border-color: var(--accent);
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.shift-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.shift-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid var(--border);
}

.shift-pill.on {
  color: var(--green);
  background: rgba(87, 242, 135, 0.12);
  border-color: rgba(87, 242, 135, 0.45);
}

.shift-pill.off {
  color: var(--muted);
  background: var(--surface-alt);
}

.shift-pill.leave {
  color: #c9a0dc;
  background: rgba(180, 140, 200, 0.15);
  border-color: rgba(180, 140, 200, 0.45);
}

.shift-pill.planned {
  color: #9bb7e8;
  background: rgba(155, 183, 232, 0.12);
  border-color: rgba(155, 183, 232, 0.45);
}

.board-lock {
  max-width: 420px;
  margin: 2rem auto;
  text-align: center;
  padding: 1.5rem 1.25rem;
}

.live-reload-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  padding: 0.7rem 1rem;
  background: rgba(232, 168, 56, 0.18);
  border-bottom: 1px solid rgba(232, 168, 56, 0.5);
  color: var(--text-bright);
  font-weight: 600;
}

main {
  padding: 1.25rem;
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }

.messages li {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: rgba(59, 165, 93, 0.15);
  border: 1px solid var(--green);
  color: var(--text-bright);
}

.messages li.error {
  background: rgba(237, 66, 69, 0.15);
  border-color: var(--red);
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

th, td {
  padding: 0.7rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  background: var(--header-bg);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-bright);
  border-bottom: 2px solid var(--accent);
}

tbody tr:nth-child(even) { background: var(--surface-alt); }
tr:last-child td { border-bottom: none; }

.pill {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-bright);
}

.pill.low { background: var(--pill-low); }
.pill.mid { background: var(--pill-mid); }
.pill.high { background: var(--pill-high); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  min-height: 44px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-bright);
  background: var(--accent);
  white-space: nowrap;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease,
    transform 0.08s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.btn:hover { background: var(--accent-hover); }
.btn:active {
  background: var(--accent-pressed);
  transform: scale(0.96);
}

.btn.green { background: var(--green); }
.btn.green:hover { background: var(--green-dark); }
.btn.green:active { background: var(--green-dark); filter: brightness(0.9); }

.btn.cyan {
  background: #4FC3F7;
  color: #0b1e2a;
}
.btn.cyan:hover { background: #39b5ef; color: #0b1e2a; }
.btn.cyan:active { background: #2aa3dc; color: #0b1e2a; }

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--accent);
}

.btn.ghost:hover {
  background: var(--accent-soft);
  color: var(--text-bright);
}

.btn.ghost:active {
  background: var(--accent-soft-strong);
  color: var(--text-bright);
  border-color: var(--accent-hover);
  transform: scale(0.96);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

.btn.danger { background: var(--red); }
.btn.danger:hover { background: var(--red-dark); }
.btn.danger:active { background: var(--red-dark); filter: brightness(0.9); }
.btn.full-width { width: 100%; }

.btn:disabled,
.btn.is-busy {
  cursor: wait;
  opacity: 0.85;
  pointer-events: none;
}

.btn.is-busy {
  transform: none;
}

.btn.ghost.is-busy,
.btn.ghost:disabled {
  background: var(--accent);
  color: var(--text-bright);
  border-color: var(--accent);
}

.btn.is-added,
.btn.ghost.is-added {
  background: var(--green) !important;
  color: var(--text-bright) !important;
  border-color: var(--green) !important;
  opacity: 1;
}

.cart-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%) translateY(120%);
  z-index: 1000;
  max-width: min(92vw, 420px);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: var(--header-bg);
  border: 1px solid var(--accent);
  color: var(--text-bright);
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.cart-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.cart-toast.error {
  border-color: var(--red);
}

.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.actions form { margin: 0; }

select, input, textarea {
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  max-width: 100%;
}

select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.full-width,
.stack-form input,
.stack-form select,
.stack-form textarea {
  width: 100%;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.panel-narrow {
  max-width: 400px;
  margin: 6vh auto 0;
  width: 100%;
}

.panel-form {
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

.login-logo {
  display: block;
  height: 56px;
  width: auto;
  margin: 0 auto 1.25rem;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.toolbar h1 {
  font-size: 1.35rem;
  margin: 0;
  color: var(--text-bright);
  font-weight: 700;
}

.toolbar .spacer { flex: 1; }
.muted { color: var(--muted); }
.mine { background: var(--accent-soft-strong) !important; }

.empty {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--muted-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Desktop: table. Mobile: cards. */
.orders-mobile,
.history-mobile {
  display: none;
}

.order-card,
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.order-card.mine,
.history-card {
  border-color: var(--accent);
  background: rgba(44, 47, 51, 0.95);
}

.order-card-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.order-card-number { font-size: 1.05rem; color: var(--text-bright); }

.order-card-assigned {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.order-card-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 1rem;
  margin: 0 0 0.85rem;
}

.order-card-fields > div { min-width: 0; }
.order-card-wide { grid-column: 1 / -1; }

.order-card-fields dt {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-dim);
}

.order-card-fields dd {
  margin: 0.15rem 0 0;
  word-break: break-word;
}

.deadline-overdue {
  color: #ff8a8c;
  font-weight: 700;
}

.deadline-soon {
  color: #ffd166;
  font-weight: 700;
}

.order-card-status { margin: 0 0 0.85rem; }

.status-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.status-label select {
  width: 100%;
  min-height: 44px;
}

.orders-mobile,
.history-mobile {
  flex-direction: column;
  gap: 0.75rem;
}

@media (max-width: 768px) {
  body { font-size: 15px; }
  main { padding: 0.75rem; }
  header { padding: 0.75rem; gap: 0.65rem; }
  .brand-logo { height: 30px; }
  header nav { width: 100%; }
  header nav a {
    flex: 1;
    text-align: center;
    padding: 0.65rem 0.5rem;
  }
  header .spacer { display: none; }
  header .header-actions {
    width: 100%;
    justify-content: space-between;
  }
  header .user {
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55vw;
  }
  .toolbar { align-items: stretch; }
  .toolbar h1 { font-size: 1.15rem; width: 100%; }
  .toolbar .btn { width: 100%; }
  .orders-desktop,
  .history-desktop { display: none !important; }
  .orders-mobile,
  .history-mobile { display: flex; }
  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .actions .btn { width: 100%; }
  .actions form { display: contents; }
  .actions a.btn { grid-column: 1 / -1; }
  .panel,
  .panel-narrow { margin-top: 1rem; padding: 1.1rem; }
  .panel-narrow { margin-top: 4vh; }
}

/* Clickable board rows */
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: var(--accent-soft); }

.order-card-link {
  color: inherit;
  text-decoration: none;
}
.order-card-link:hover { color: var(--accent); text-decoration: underline; }

/* Status pills (read-only status display) */
.status-pill {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-bright);
  background: #6b7385;
  white-space: nowrap;
}
.status-pill.queued-for-cutting,
.status-pill.queued-for-extension-winding { background: #5c6b84; }
.status-pill.laser-cutting,
.status-pill.extension-winding { background: #2e7ea6; }
.status-pill.awaiting-production { background: #9a8655; }
.status-pill.in-production { background: #2d8f4e; }
.status-pill.missing-parts { background: #c03537; }
.status-pill.completed { background: var(--green); }
.status-pill.pending-review { background: #e8a838; color: #1a1a1a; }

/* Worker-controlled production status */
.status-pill.work-status { border: 1px solid rgba(255, 255, 255, 0.15); }
.status-pill.work-status.not-started { background: #4a5060; }
.status-pill.work-status.in-progress { background: #2d8f4e; }
.status-pill.work-status.paused { background: #7a6a3a; }
.status-pill.work-status.work-complete { background: #3a7a8f; }

.partial-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: 0.25rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #c9b6f0;
  border: 1px solid rgba(180, 140, 220, 0.45);
  background: rgba(106, 90, 154, 0.28);
  white-space: nowrap;
  vertical-align: middle;
}

.shipment-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.25rem;
}
.shipment-row input {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border-input);
  background: var(--surface-alt);
  color: var(--text);
}
.shipment-lines {
  margin: 0.35rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.9rem;
}
.shipment-lines li { margin: 0.15rem 0; }

.optional-section {
  padding: 0.85rem;
  border: 1px dashed var(--border-input);
  border-radius: var(--radius);
  background: var(--surface);
}
.optional-section summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}
.optional-section[open] summary {
  color: var(--text-bright);
  margin-bottom: 0.75rem;
}
.work-waiting-hint {
  align-self: center;
  font-size: 0.88rem;
}

.review-pending-banner {
  margin: 0.85rem 0 0;
  padding: 0.75rem 0.9rem;
  border: 1px solid rgba(232, 168, 56, 0.45);
  border-radius: var(--radius);
  background: rgba(232, 168, 56, 0.12);
  font-size: 0.92rem;
}

.review-queue-intro {
  margin: 0 0 1rem;
}

.review-queue-summary {
  margin-bottom: 0.85rem;
  font-size: 0.95rem;
}

.review-queue-table {
  min-width: 0;
  width: 100%;
}

.review-queue-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}

.review-queue-actions form { margin: 0; }

/* Attachment / report markers on the board */
.doc-flag {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.report-flag {
  color: var(--red);
  font-size: 1rem;
  margin-left: 0.25rem;
}
.confirm-flag {
  color: var(--green);
  font-size: 1rem;
  margin-left: 0.25rem;
  font-weight: 700;
}

.confirmation-banner {
  margin-bottom: 0.85rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--green);
  background: rgba(59, 165, 93, 0.12);
  color: var(--text-bright);
  font-size: 0.9rem;
}

/* Order detail page */
.detail-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1rem;
  align-items: start;
}
.detail-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.detail-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.detail-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin: 0 0 1rem;
}
.detail-fields > div { min-width: 0; }
.detail-wide { grid-column: 1 / -1; }
.detail-fields dt {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-dim);
}
.detail-fields dd {
  margin: 0.15rem 0 0;
  word-break: break-word;
}
.detail-actions { align-items: center; }
.detail-status-form select { min-height: 44px; }

.panel-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--text-bright);
}

/* Attachment list */
.attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.attachment-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.65rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.attachment-list li form { margin: 0; }
.attachment-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.attachment-info a {
  color: var(--text-bright);
  font-weight: 600;
  text-decoration: none;
  word-break: break-all;
}
.attachment-info a:hover { color: var(--accent); }
.attachment-meta { font-size: 0.8rem; }

.file-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 0.3rem 0.4rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-bright);
  background: #6b7385;
}
.file-badge.pdf { background: #c03537; }
.file-badge.doc,
.file-badge.docx { background: #2e7ea6; }
.file-badge.jpg,
.file-badge.jpeg,
.file-badge.png,
.file-badge.gif,
.file-badge.webp { background: #6b4fa0; }

.order-materials-section {
  margin-top: 1.25rem;
}

.order-materials-hint {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
}

.order-materials-list .attachment-name {
  color: var(--text-bright);
  font-weight: 600;
}

.attachment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.attachment-actions form { margin: 0; }

.btn-small {
  min-height: 34px;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

/* Problem reports */
.report-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.report-label { margin-bottom: 0.25rem; font-size: 0.85rem; }
.report-hint { margin: 0; font-size: 0.8rem; }

.report-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.report-item {
  padding: 0.65rem 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--red);
  border-radius: 8px;
}
.report-item.resolved { border-color: var(--border); opacity: 0.8; }
.report-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.report-message { margin: 0.4rem 0; word-break: break-word; }

/* Order activity log */
.event-log-panel {
  margin-top: 1rem;
}
.event-log-panel > summary.event-log-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  user-select: none;
}
.event-log-panel > summary.event-log-summary::-webkit-details-marker {
  display: none;
}
.event-log-panel > summary.event-log-summary::before {
  content: "▸";
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
}
.event-log-panel[open] > summary.event-log-summary::before {
  content: "▾";
}
.event-log-panel > summary .panel-title {
  margin: 0;
}
.event-log-count {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.event-log-panel[open] .event-list {
  margin-top: 0.75rem;
  max-height: 22rem;
  overflow-y: auto;
  padding-right: 0.15rem;
}
.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.event-item {
  padding: 0.65rem 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}
.event-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}
.event-time { font-size: 0.85rem; color: var(--muted); }
.event-type {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
}
.event-summary { margin: 0.15rem 0 0.35rem; word-break: break-word; }
.event-actor { font-size: 0.85rem; }

.events-table a {
  color: var(--text-bright);
  font-weight: 600;
  text-decoration: none;
}
.events-table a:hover {
  color: var(--text);
  text-decoration: underline;
}

.reorder-col { width: 3rem; white-space: nowrap; vertical-align: middle; }
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}
.drag-handle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.drag-handle:active { cursor: grabbing; }
.drag-handle-bars {
  display: block;
  width: 0.55rem;
  height: 1rem;
  background:
    radial-gradient(circle, currentColor 0.12rem, transparent 0.13rem) 0 0 / 0.55rem 0.5rem repeat-y;
}
tr.is-dragging {
  opacity: 0.45;
}
tr.drag-over td {
  box-shadow: inset 0 3px 0 var(--accent);
}
.reorder-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
}
.reorder-actions form { margin: 0; width: 100%; }
.reorder-btn {
  min-height: 36px;
  width: 100%;
  padding: 0.25rem 0.4rem;
  font-size: 1.05rem;
  line-height: 1;
  font-weight: 700;
}
.reorder-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.order-card-reorder {
  margin-bottom: 0.75rem;
}
.order-card-reorder .reorder-actions {
  flex-direction: row;
  justify-content: flex-end;
}

.worker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
}
.worker-list li {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
}

.worker-picker {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
}
.worker-picker label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  cursor: pointer;
  font-weight: 500;
}
.worker-picker input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
}

/* Inline document previews at the bottom of the detail page */
.preview-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1rem;
}
.preview-panel { scroll-margin-top: 1rem; }
.preview-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.preview-head .spacer { flex: 1; }
.preview-frame {
  width: 100%;
  height: 78vh;
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #525659;
}
.doc-preview {
  background: #ffffff;
  color: #1c1e21;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem 2.5rem;
  max-height: 78vh;
  overflow-y: auto;
  line-height: 1.55;
}
.doc-preview img { max-width: 100%; height: auto; }
.doc-preview table { background: transparent; border: 1px solid #ccc; min-width: 0; }
.doc-preview th,
.doc-preview td {
  border: 1px solid #ccc;
  color: #1c1e21;
  background: transparent;
}
.doc-preview th { background: #f0f0f0; text-transform: none; }
.doc-preview a { color: #1a5dbb; }

/* Order positions & bill-of-materials tables (PDF import) */
.bom-block {
  margin-top: 1.25rem;
  min-width: 0;
  max-width: 100%;
}

.bom-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  min-width: 0;
}

.bom-table {
  min-width: 0;
  width: 100%;
  font-size: 0.88rem;
}

.bom-table th,
.bom-table td {
  padding: 0.45rem 0.6rem;
}

.bom-table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.bom-table .cat-no {
  white-space: nowrap;
  color: var(--text-bright);
}

.catalog-copy {
  cursor: pointer;
}

.catalog-copy:hover {
  color: var(--accent);
}

.bom-category td {
  background: var(--header-bg);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bom-section td {
  background: var(--accent-soft, rgba(88, 101, 242, 0.18));
  color: var(--text-bright);
  font-weight: 700;
  border-top: 2px solid var(--accent);
}

.bom-table .stock-short {
  color: var(--red);
  font-weight: 700;
}

.bom-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-bright);
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  user-select: none;
}

.bom-details summary:hover { border-color: var(--accent); }

.bom-details[open] summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.bom-details[open] .bom-scroll > .bom-table,
.bom-details[open] > .bom-table {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: none;
}

.bom-summary-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 0.35rem;
}

.bom-details-short > summary {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 45%, var(--border));
}

/* Worker composition overrides */
.composition-sections-head {
  margin-bottom: 0.75rem;
}

.composition-sections-hint {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
}

.material-highlightable--editable {
  cursor: text;
  user-select: text;
}

.cat-no .material-highlightable {
  display: inline;
}

mark.material-mark {
  background: #ffe566;
  color: #1a1a1a;
  padding: 0.05em 0.12em;
  border-radius: 2px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.material-highlightable--editable mark.material-mark {
  cursor: pointer;
}

.material-highlightable--editable mark.material-mark:hover {
  background: #ffd633;
}

.material-highlight-popup {
  position: fixed;
  z-index: 1200;
  padding: 0.2rem;
  background: var(--surface, #2b2d31);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.material-highlight-popup .btn {
  margin: 0;
  white-space: nowrap;
}

.composition-position {
  margin-top: 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
}

.composition-position > summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  cursor: pointer;
  padding: 0.65rem 0.85rem;
  font-weight: 600;
  color: var(--text-bright);
  user-select: none;
  list-style: none;
}

.composition-position > summary::-webkit-details-marker { display: none; }

.composition-position > summary:hover { border-color: var(--accent); }

.composition-position[open] > summary {
  border-bottom: 1px solid var(--border);
}

.composition-position-title { flex: 1 1 auto; }

.composition-edit-link { margin-left: auto; }

.composition-position-body {
  padding: 0.75rem 0.85rem 0.9rem;
}

.composition-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
}

.composition-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.composition-badge.planned {
  background: rgba(142, 154, 175, 0.25);
  color: #c5cad3;
}

.composition-badge.actual {
  background: rgba(59, 165, 93, 0.2);
  color: #8ee4a8;
}

.composition-badge.customized {
  background: rgba(255, 209, 102, 0.18);
  color: #ffd166;
}

.composition-note {
  width: 100%;
  margin: 0.15rem 0 0;
  padding: 0.55rem 0.7rem;
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
}

.composition-line-added td { background: rgba(59, 165, 93, 0.08); }
.composition-line-changed td { background: rgba(255, 209, 102, 0.08); }
.composition-line-removed td {
  background: rgba(237, 66, 69, 0.1);
  color: #ff8a8c;
  text-decoration: line-through;
}

.composition-line-removed .cat-no {
  color: #ff8a8c;
}

.composition-change-tag.removed {
  background: rgba(237, 66, 69, 0.25);
  color: #ff8a8c;
  text-decoration: none;
}

.composition-change-tag {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  vertical-align: middle;
}

.composition-change-tag.added {
  background: rgba(59, 165, 93, 0.25);
  color: #8ee4a8;
}

.composition-change-tag.changed {
  background: rgba(255, 209, 102, 0.25);
  color: #ffd166;
}

.composition-planned-details {
  margin-top: 0.75rem;
}

.composition-planned-details > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 0.45rem;
}

.composition-planned-table td { opacity: 0.85; }

.composition-position-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.composition-editor { max-width: 960px; }

.composition-subtitle { margin: 0.25rem 0 0; }

.composition-editor-hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.composition-edit-table .field-input {
  width: 100%;
  min-width: 4.5rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.88rem;
}

.composition-edit-table .field-input.is-locked {
  background: var(--surface);
  color: var(--muted);
  border-color: color-mix(in srgb, var(--border) 70%, transparent);
  cursor: default;
  opacity: 0.95;
}

.composition-edit-table td { vertical-align: middle; }

.composition-row-actions {
  width: 2.5rem;
  text-align: center;
}

.composition-editor-actions { margin: 0.65rem 0 0.85rem; }

.composition-note-field textarea {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
}

@media (max-width: 768px) {
  .detail-grid {
    grid-template-columns: 1fr;
    min-width: 0;
  }
  .detail-side,
  .panel,
  .composition-position,
  .composition-position-body {
    min-width: 0;
    max-width: 100%;
  }
  .attachment-list li { flex-wrap: wrap; }
  .preview-frame { height: 60vh; min-height: 320px; }
  .doc-preview { padding: 1rem; }

  /* BOM / materials: stack as cards so the page stays viewport-width */
  .bom-scroll:not(:has(.composition-edit-table)):not(:has(.events-table)) {
    overflow-x: visible;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) {
    border: none;
    background: transparent;
    overflow: visible;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) thead {
    display: none;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) tbody {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) tr {
    display: block;
    margin: 0;
    padding: 0.65rem 0.75rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) th,
  .bom-table:not(.composition-edit-table):not(.events-table) td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.28rem 0;
    border: none;
    white-space: normal;
    text-align: left;
    word-break: break-word;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) td + td {
    border-top: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  }

  .bom-table:not(.composition-edit-table):not(.events-table) td::before {
    content: attr(data-label);
    flex: 0 1 42%;
    max-width: 9rem;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.3;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) td:not([data-label])::before,
  .bom-table:not(.composition-edit-table):not(.events-table) td[data-label=""]::before {
    display: none;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) .cat-no {
    display: block;
    padding: 0 0 0.4rem;
    margin-bottom: 0.15rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-bright);
    white-space: normal;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) .cat-no::before {
    display: none;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) .cat-no + td {
    border-top: none;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-category,
  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-section {
    padding: 0.5rem 0.75rem;
    background: var(--header-bg);
  }

  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-section {
    background: var(--accent-soft, rgba(88, 101, 242, 0.18));
    border-color: var(--accent);
  }

  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-category td,
  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-section td {
    display: block;
    padding: 0;
    border: none;
    font-size: 0.8rem;
  }

  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-category td::before,
  .bom-table:not(.composition-edit-table):not(.events-table) tr.bom-section td::before {
    display: none;
  }

  .composition-line-added,
  .composition-line-changed,
  .composition-line-removed {
    border-left-width: 3px;
    border-left-style: solid;
  }

  .composition-line-added { border-left-color: var(--green); }
  .composition-line-changed { border-left-color: #ffd166; }
  .composition-line-removed { border-left-color: var(--red); }

  .events-table {
    min-width: 36rem;
  }

  /* Composition editor: stacked field cards, no sideways swipe */
  .composition-editor {
    max-width: none;
  }

  .composition-editor-hint {
    font-size: 0.88rem;
    line-height: 1.4;
  }

  .composition-editor .bom-scroll {
    overflow: visible;
    max-width: 100%;
  }

  .composition-edit-table {
    min-width: 0;
    width: 100%;
    border: none;
    background: transparent;
    overflow: visible;
  }

  .composition-edit-table thead {
    display: none;
  }

  .composition-edit-table tbody {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .composition-edit-table tr.composition-edit-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem 0.7rem;
    margin: 0;
    padding: 0.85rem;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  .composition-edit-table tr.composition-edit-row td {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    width: auto;
    min-width: 0;
    padding: 0;
    border: none;
    vertical-align: top;
  }

  .composition-edit-table tr.composition-edit-row td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.2;
  }

  .composition-edit-table td.field-catalog,
  .composition-edit-table td.field-name,
  .composition-edit-table td.field-category,
  .composition-edit-table td.composition-row-actions {
    grid-column: 1 / -1;
  }

  .composition-edit-table td.field-category.is-empty-field,
  .composition-edit-table td.field-required.is-empty-field {
    display: none;
  }

  .composition-edit-table .field-input {
    min-width: 0;
    min-height: 44px;
    padding: 0.55rem 0.7rem;
    font-size: 1rem;
  }

  .composition-edit-table .field-input.is-locked {
    min-height: 40px;
  }

  .composition-edit-table td.composition-row-actions {
    margin-top: 0.15rem;
  }

  .composition-edit-table td.composition-row-actions::before {
    display: none;
  }

  .composition-edit-table .remove-line-btn {
    width: 100%;
    min-height: 44px;
  }

  .composition-editor-actions .btn {
    width: 100%;
    min-height: 44px;
  }

  .composition-editor .actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) {
  .table-wrap { overflow-x: auto; }
  table { min-width: 900px; }
  .orders-desktop table {
    min-width: 0;
    width: 100%;
  }
  .orders-desktop th,
  .orders-desktop td {
    padding: 0.55rem 0.55rem;
    font-size: 0.92rem;
  }
  .orders-desktop td.muted {
    max-width: 12rem;
  }
}
