:root {
  --bg: #f4f3f0; --surface: #fff; --ink: #1f2328; --muted: #6b6f76; --line: #e2e0db;
  --accent: #c23b33; --accent-dark: #9e2f29;   /* Pedrosa red (static/logo.svg) */ --accent-soft: #f8e7e5; --danger: #a8322d; --ok: #2f6b3a; --sel: #fff7df;
  --radius: 6px; font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 6px 12px; }
button:hover:not(:disabled) { border-color: #c9c6bf; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
input, select, textarea { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

header { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px; background: var(--accent); color: #fff; }
header h1 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: .2px; display: flex; align-items: center; gap: 10px; }
header h1 img { height: 30px; width: auto; }
header nav { display: flex; gap: 4px; }
header nav button { background: transparent; border: 0; color: #f6d5d2; padding: 16px 12px; border-radius: 0; border-bottom: 3px solid transparent; }
header nav button.active { color: #fff; border-bottom-color: #fff; }
header .user { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: 13px; }
header .user button { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); padding: 4px 10px; }
header .user button:hover:not(:disabled) { border-color: #fff; }
header button:focus-visible { outline-color: #fff; }

main { padding: 16px 20px 80px; }   /* full width: no side margins on wide screens */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

.filters { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; padding: 14px; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filters .range { display: flex; gap: 4px; }
.filters .range input { width: 130px; }
.filters input[type=text], .filters select { width: 170px; }
.filters .search input { width: 220px; }
.filters .actions { display: flex; gap: 6px; margin-left: auto; }

.bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.bar .sel { color: var(--ink); font-weight: 600; }
.bar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: #faf9f7; position: sticky; top: 0; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--ink); }
th .arrow { font-size: 10px; margin-left: 4px; color: var(--accent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.chk, th.chk { width: 36px; }
tbody tr:hover { background: #fbfaf8; }
tbody tr.selected { background: var(--sel); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.badge { display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; text-align: center; border: 0; }
.badge.zero { background: transparent; color: #b5b2ab; font-weight: 400; }

.pager { display: flex; align-items: center; gap: 6px; padding: 10px 14px; font-size: 13px; color: var(--muted); }
.pager .right { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.pager input { width: 56px; text-align: center; }

.selection-bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--ink); color: #fff; display: flex; align-items: center; gap: 14px; padding: 12px 20px; transform: translateY(100%); transition: transform .15s; }
.selection-bar.visible { transform: none; }
.selection-bar button { background: transparent; color: #fff; border-color: #555; }
.selection-bar button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; margin-left: auto; }
.selection-bar button.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }

dialog { border: 0; border-radius: 8px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
#dlg-info { width: min(900px, calc(100vw - 32px)); }
dialog td.notes { white-space: pre-line; min-width: 200px; max-width: 320px; font-size: 13px; }
/* Documents of an order: long names and notes wrap instead of a horizontal scroll */
table.docs td { white-space: normal; overflow-wrap: break-word; vertical-align: top; }
table.docs td:first-child { white-space: nowrap; }
table.docs td.notes { min-width: 120px; }
table.docs td:last-child, table.docs th:last-child { width: 1%; padding-left: 0; }
table.docs .tag { white-space: nowrap; }
@media (max-width: 760px) {   /* narrow screens: one block per document instead of a table */
  table.docs thead { display: none; }
  table.docs, table.docs tbody, table.docs tr, table.docs td { display: block; width: auto; }
  table.docs tr { position: relative; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.docs td { border: 0; padding: 2px 36px 2px 0; min-width: 0; max-width: none; }
  table.docs td:first-child { color: var(--muted); font-size: 12px; }
  table.docs td:last-child { position: absolute; top: 6px; right: 0; padding: 0; width: auto; }
  table.docs td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); }
}
dialog::backdrop { background: rgba(20,24,28,.45); }
dialog form, dialog .dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
dialog h2 { margin: 0; font-size: 16px; }
dialog .order-list { max-height: 120px; overflow: auto; font-size: 12px; color: var(--muted); background: #faf9f7; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; line-height: 1.6; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
dialog textarea { min-height: 70px; resize: vertical; }
dialog .buttons { display: flex; justify-content: flex-end; gap: 8px; }
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.active { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--ink); }
.help { font-size: 12px; color: var(--muted); }
.error { color: var(--danger); font-size: 13px; }

.toast { position: fixed; top: 64px; right: 20px; background: var(--ok); color: #fff; padding: 10px 16px; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.2); z-index: 10; max-width: 420px; }
.toast.error { background: var(--danger); color: #fff; }
.orders-cell { white-space: normal; max-width: 420px; font-size: 12px; color: var(--muted); }
a { color: var(--accent); }
dialog label.check { flex-direction: row; align-items: center; gap: 8px; }
.status-tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.status-tag.active { background: #e4f0e6; color: var(--ok); }
.status-tag.inactive { background: #f1e3e2; color: var(--danger); }
.status-tag.admin { background: var(--accent-soft); color: var(--accent); }
tr.inactive td { color: var(--muted); }
.sync { font-size: 12px; color: var(--muted); }
.sync.failed { color: var(--danger); font-weight: 600; }
#sync-now { font-size: 12px; }
/* Permanent actions: red outline (solid red is for the main buttons, the company colour) */
button.danger { background: var(--surface); border-color: var(--danger); color: var(--danger); font-weight: 600; }
button.danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.selection-bar button.danger { background: transparent; border-color: #c2524c; color: #ffb4ae; margin-left: auto; }
.selection-bar button.danger + button.primary { margin-left: 0; }
.warning { background: #fbf0ef; border: 1px solid #ecc9c6; color: #6e231f; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.impact h3 { font-size: 13px; margin: 8px 0 4px; }
.impact ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.6; max-height: 140px; overflow: auto; }
.impact .delete { color: var(--danger); }
.modes { display: flex; gap: 6px; background: #faf9f7; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; }
.modes label { flex: 1; flex-direction: row; justify-content: center; align-items: center; gap: 6px; padding: 7px; border-radius: 4px; cursor: pointer; font-size: 13px; }
.modes label:has(input:checked) { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.modes input { margin: 0; }
#mode-new, #mode-existing { display: flex; flex-direction: column; gap: 14px; }
#mode-new[hidden], #mode-existing[hidden] { display: none; }
.tc-list { border: 1px solid var(--line); border-radius: var(--radius); max-height: 240px; overflow: auto; }
.tc-list label { flex-direction: row; gap: 10px; align-items: flex-start; padding: 9px 10px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.tc-list label:last-child { border-bottom: 0; }
.tc-list label:hover { background: #fbfaf8; }
.tc-list label:has(input:checked) { background: var(--accent-soft); }
.tc-list input { margin-top: 2px; }
.tc-list .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tc-list .empty { padding: 16px; font-size: 13px; }
.tc-list label.already { cursor: default; color: var(--muted); background: transparent; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; }
.dl { display: inline-flex; vertical-align: middle; margin-left: 6px; color: var(--muted); padding: 2px; border-radius: 3px; }
.dl:hover { color: var(--accent); background: var(--accent-soft); }
#dlg-fix { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; }
dialog .section { padding: 14px 0 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
dialog .section h3 { margin: 0; font-size: 13px; }
dialog .buttons.section { flex-direction: row; justify-content: space-between; }
/* Edit TC: title (with errors) and buttons stay visible while the middle scrolls */
#dlg-fix .dialog-head, #dlg-fix .dialog-foot { position: sticky; z-index: 2; background: var(--surface); }
#dlg-fix .dialog-head { top: 0; margin: -20px -20px 0; padding: 20px 20px 12px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 1px 0 var(--line); }
#dlg-fix .tabs { display: flex; gap: 18px; margin: 4px 0 -12px; overflow-x: auto; }
#dlg-fix .tabs button { border: 0; border-radius: 0; background: none; padding: 8px 0 10px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap; }
#dlg-fix .tabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
#dlg-fix .tabs button:hover:not([aria-selected="true"]) { color: var(--ink); }
#dlg-fix .tab-panel { display: flex; flex-direction: column; gap: 14px; min-height: 260px; }
#dlg-fix .tab-panel > .section:first-child { border-top: 0; padding-top: 4px; }
#dlg-fix .dialog-foot { bottom: 0; margin: 0 -20px -20px; padding: 12px 20px 20px; }
.fix-orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); max-height: 180px; }
.fix-orders label { border-bottom: 0; padding: 6px 10px; align-items: center; }
.changes { width: 100%; font-size: 13px; }
.changes td { white-space: normal; vertical-align: top; }
.changes td:first-child { white-space: nowrap; color: var(--muted); }
button.icon { display: inline-flex; padding: 4px; border-color: transparent; background: none; color: var(--muted); }
button.icon:hover:not(:disabled) { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
[hidden] { display: none !important; }

/* Password field with show/hide button (static/password.js) */
.pw { position: relative; display: block; }
.pw input { width: 100%; padding-right: 34px; }
.pw button.icon { position: absolute; top: 50%; right: 4px; transform: translateY(-50%); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: 320px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 18px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.login h1 img { height: 64px; width: auto; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.login button { padding: 9px; }

/* Narrow screens (phone) */
@media (max-width: 760px) {
  header { flex-wrap: wrap; height: auto; padding: 8px 16px 0; gap: 4px 12px; }
  header h1 { flex: 1; }
  header .user { margin-left: 0; order: 2; }
  header .user #user-name { display: none; }
  header nav { order: 3; width: 100%; overflow-x: auto; }
  header nav button { padding: 10px 10px; }
  main { padding: 12px 16px 120px; }
  .filters label, .filters .search input, .filters input[type=text], .filters select { width: 100%; }
  .filters .range { width: 100%; } .filters .range input { width: 50%; }
  .filters .actions { margin-left: 0; width: 100%; } .filters .actions button { flex: 1; }
  .bar { flex-wrap: wrap; }
  .bar .right { margin-left: 0; }
  .selection-bar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .selection-bar > span { width: 100%; }
  .selection-bar button.danger, .selection-bar button.primary { margin-left: 0; }
  .pager .right { margin-left: 0; flex-wrap: wrap; }
}
