:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --text: #1d2330;
  --muted: #667085;
  --border: #d9dde5;
  --primary: #1f5eff;
  --primary-dark: #1546c4;
  --ok: #157f3b;
  --warn: #a15c00;
  --bad: #b42318;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--primary); }
main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
main.narrow { max-width: 760px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 24px 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }

#nav { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 20px; background: #101828; color: #fff; flex-wrap: wrap; }
#nav a { color: #d0d5dd; text-decoration: none; margin-left: 16px; }
#nav a.active, #nav a:hover { color: #fff; }
#nav .nav-left, #nav .nav-right { display: flex; align-items: center; gap: 8px; }
#nav .company-name { font-weight: 600; }
#nav .logo { height: 28px; }
img.logo { max-height: 60px; max-width: 240px; }
#nav select { padding: 4px; }
.company-switcher { position: relative; }
.company-toggle { background: none; border: 1px solid transparent; border-radius: 6px; color: #fff; font: inherit; font-weight: 600; padding: 4px 8px; cursor: pointer; }
.company-toggle:hover, .company-toggle[aria-expanded="true"] { border-color: #475467; background: #1d2939; }
.company-menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 280px; background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(16, 24, 40, .18); padding: 6px; }
.company-menu > button { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; border-radius: 6px; padding: 8px; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.company-menu > button:hover { background: var(--bg); }
.company-menu > button.current { font-weight: 600; }
.company-menu .menu-logo { width: 28px; height: 28px; object-fit: contain; flex: 0 0 28px; }
.company-add { border-top: 1px solid var(--border); margin-top: 6px; padding: 8px 8px 4px; }
.company-add input { padding: 6px 8px; }
.link-button { background: none; border: none; color: #d0d5dd; cursor: pointer; font: inherit; text-decoration: underline; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 18px 20px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0 0 8px; font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 12px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.tile.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(31, 94, 255, .2); }
.tile .count { font-size: 24px; font-weight: 700; display: block; }
.tile .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tile.alert-tile .count { color: var(--bad); }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f0f4ff; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f4; white-space: nowrap; }
.badge-active, .badge-paid, .badge-xero_synced, .badge-completed, .badge-processed { background: #dcfae6; color: var(--ok); }
.badge-awaiting_deposit, .badge-pending, .badge-processing, .badge-payment_received, .badge-xero_sync_pending { background: #eef4ff; color: #1546c4; }
.badge-payment_overdue, .badge-failed, .badge-retrying, .badge-xero_sync_error, .badge-held_for_review, .badge-suspended { background: #fee4e2; color: var(--bad); }
.badge-cancelled { background: #f2f4f7; color: var(--muted); }
.flag { display: inline-block; margin-left: 6px; color: var(--bad); font-weight: 700; font-size: 12px; }

label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff;
}
textarea { min-height: 120px; }
.inline { display: flex; gap: 8px; align-items: flex-end; }
.inline > * { flex: 1; }
.inline > button { flex: 0 0 auto; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin: 10px 0; }
.check input { margin-top: 3px; width: 18px; height: 18px; flex: 0 0 auto; }

button, .button { display: inline-block; padding: 9px 16px; border-radius: 6px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
button:hover:not(:disabled) { background: var(--primary-dark); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: #fff; color: var(--primary); }
button.danger { background: var(--bad); border-color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.alert { padding: 10px 14px; border-radius: 6px; margin: 10px 0; }
.alert-error { background: #fee4e2; color: var(--bad); }
.alert-warn { background: #fef0c7; color: var(--warn); }
.alert-ok { background: #dcfae6; color: var(--ok); }
.alert-info { background: #eef4ff; color: #1546c4; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#logo-preview img.logo { display: block; margin: 8px 0; border: 1px solid #e4e7ec; padding: 6px; background: #fff; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }

.schedule-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-variant-numeric: tabular-nums; }
.schedule-row.total { font-weight: 700; border-bottom: none; }
.terms-section { border-left: 4px solid var(--primary); padding: 4px 14px; margin: 14px 0; background: #f8faff; }
.terms-section h3 { margin-top: 6px; }
.terms-section p { white-space: pre-line; margin: 6px 0; }
#u-stores-wrap { grid-column: 1 / -1; border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 14px; }
.commitment { border: 2px solid var(--line, #d0d5dd); border-radius: 8px; padding: 4px 16px; margin: 14px 0; }
.commitment p { margin: 10px 0; }
.big-notice { font-size: 18px; font-weight: 700; text-align: center; padding: 14px; border: 2px solid var(--warn); color: var(--warn); border-radius: 8px; margin: 14px 0; }
.audit-entry { font-size: 13px; border-bottom: 1px solid var(--border); padding: 6px 0; }
.audit-entry details pre { white-space: pre-wrap; background: #f6f7f9; padding: 8px; border-radius: 4px; }
.perm-grid td, .perm-grid th { text-align: center; }
.perm-grid td:first-child, .perm-grid th:first-child { text-align: left; }
.login-box { max-width: 380px; margin: 80px auto; }
