:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #64748b;
  --line: #d8dee8;
  --primary: #c75b12;
  --primary-dark: #9a4309;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
.topbar { height: 64px; display: flex; align-items: center; gap: 24px; padding: 0 28px; background: #fff7ed; border-bottom: 1px solid #fed7aa; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 800; color: var(--primary-dark); font-size: 20px; }
nav { display: flex; gap: 10px; flex: 1; }
nav a, .tabs a { padding: 10px 14px; border-radius: 6px; font-weight: 700; color: #6b3c16; }
nav a:hover, .tabs a.active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.topbar form { display: flex; align-items: center; gap: 12px; }
.menu-toggle { display: none; width: 38px; height: 38px; border: 1px solid #fed7aa; border-radius: 6px; background: #fff; color: var(--primary-dark); font-size: 20px; font-weight: 800; cursor: pointer; }
.page { max-width: 1240px; margin: 0 auto; padding: 28px; }
.hero { display: flex; justify-content: space-between; align-items: end; margin-bottom: 18px; }
h1, h2 { margin: 0 0 8px; }
.muted, .hint { color: var(--muted); }
.panel, .login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 22px; box-shadow: 0 8px 24px rgba(15,23,42,.06); margin-bottom: 18px; }
.collapsible-header { margin-bottom: 0; }
.collapsible-header p { margin: 0; }
.collapsible-body { margin-top: 16px; }
.collapsible-body[hidden] { display: none; }
.narrow { max-width: 860px; margin-left: auto; margin-right: auto; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #fff7ed, #eef2ff); }
.login-card { width: min(420px, 100%); }
.stack, .grid { display: grid; gap: 14px; }
.grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 700; color: #475569; }
input, select, textarea { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font: inherit; background: #f8fafc; color: var(--text); }
textarea { resize: vertical; min-width: 220px; }
.span-2 { grid-column: span 2; }
.actions { display: flex; align-items: end; }
.btn { border: 1px solid var(--line); background: #fff; min-height: 38px; border-radius: 6px; padding: 8px 12px; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; margin: 2px; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.small { min-height: 32px; padding: 5px 9px; font-size: 12px; }
.status-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 10px; border-radius: 999px; background: #fff7ed; color: var(--primary-dark); font-weight: 800; }
.notes-cell { min-width: 220px; max-width: 320px; white-space: normal; line-height: 1.35; }
.table-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.action-form { margin: 0; display: inline-flex; }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: #6b3c16; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 800; line-height: 1; }
.icon-btn:hover { border-color: #f59e0b; color: var(--primary); background: #fff7ed; }
.icon-btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.icon-btn.primary:hover { background: var(--primary-dark); }
.square-action { width: 76px; min-height: 64px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: #6b3c16; cursor: pointer; display: inline-grid; place-items: center; align-content: center; gap: 5px; padding: 7px 6px; font-weight: 800; line-height: 1.05; box-shadow: 0 1px 3px rgba(15,23,42,.08); }
.square-action span:last-child { font-size: 10px; text-align: center; }
.square-icon { font-size: 18px; line-height: 1; }
.square-action:hover { border-color: #f59e0b; color: var(--primary); background: #fff7ed; }
.update-action { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.update-action:hover { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.history-action { background: #f7eee7; color: #8a4b20; border-color: #e7c7ad; }
.history-action:hover { background: #f1dfd0; color: #6f3a18; border-color: #d8a47a; }
.onboard-action { background: #ecfdf3; color: #166534; border-color: #bbf7d0; }
.onboard-action:hover { background: #dcfce7; color: #14532d; border-color: #86efac; }
.terminate-action { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.terminate-action:hover { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.modal-backdrop[hidden] { display: none; }
.modal-backdrop { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px; background: rgba(15, 23, 42, .46); }
.modal { width: min(720px, 100%); max-height: min(80vh, 720px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; box-shadow: 0 24px 80px rgba(15, 23, 42, .28); }
.small-modal { width: min(440px, 100%); }
.modal-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 18px; }
.row { display: flex; gap: 14px; align-items: center; }
.between { justify-content: space-between; }
.inline { display: inline-flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.filters-form label { min-width: 150px; }
.wide { width: 100%; margin: 10px 0 18px; }
.wide label { flex: 1; }
.tabs { display: flex; gap: 8px; }
table { width: 100%; border-collapse: collapse; margin-top: 14px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 12px 10px; vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
td span { display: block; color: var(--muted); margin-top: 3px; }
.alert { background: #fee2e2; color: #991b1b; padding: 10px; border-radius: 6px; margin: 12px 0; }
.alert.success { background: #dcfce7; color: #166534; }
button:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 800px) {
  .topbar { height: auto; display: grid; grid-template-columns: 1fr auto auto; align-items: center; padding: 12px; gap: 10px; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; }
  nav { grid-column: 1 / -1; width: 100%; display: none; grid-template-columns: 1fr; gap: 8px; padding: 10px; background: #fff; border: 1px solid #fed7aa; border-radius: 8px; box-shadow: 0 10px 24px rgba(15,23,42,.08); }
  nav.open { display: grid; }
  nav a { width: 100%; padding: 11px 12px; text-align: left; border-radius: 6px; background: #fff7ed; white-space: nowrap; }
  .topbar form { width: auto; justify-content: flex-end; gap: 8px; }
  .topbar form span { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand { font-size: 18px; }
  .hero { display: block; }
  .hero h1 { font-size: 24px; }
  .panel { padding: 14px; }
  nav, .row, .inline { width: 100%; }
  .row { align-items: flex-start; flex-direction: column; }
  .tabs { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tabs a { text-align: center; padding: 11px 8px; }
  .inline label, .filters-form label { width: 100%; min-width: 0; }
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .page { padding: 16px; }
  .records-table { display: block; margin-top: 16px; }
  .records-table thead { display: none; }
  .records-table tbody { display: grid; gap: 14px; }
  .records-table tr { display: grid; gap: 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 8px 20px rgba(15,23,42,.06); }
  .records-table td { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 12px; align-items: start; border-bottom: 1px solid #eef2f7; padding: 10px 0; white-space: normal; }
  .records-table td:last-child { border-bottom: 0; }
  .records-table td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
  .records-table .empty-cell { display: block; text-align: center; }
  .records-table .empty-cell::before { content: ""; display: none; }
  .notes-cell { min-width: 0; max-width: none; }
  .table-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
  .square-action { width: 100%; min-height: 70px; }
  .modal-backdrop { padding: 12px; align-items: end; }
  .modal { max-height: 88vh; width: 100%; padding: 16px; }
  textarea { min-width: 0; }
}

@media (max-width: 480px) {
  .page { padding: 12px; }
  .records-table td { grid-template-columns: 1fr; gap: 6px; }
  .table-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
