/* CSMG Job Database — deliberately plain QuickBooks-style shell (spec §18).
   Visual design pass deferred per owner. */

* { box-sizing: border-box; }
body {
  margin: 0; font-family: "Segoe UI", system-ui, Arial, sans-serif;
  font-size: 14px; color: #222; background: #f4f5f8;
  display: grid; grid-template-columns: 215px minmax(0, 1fr); min-height: 100vh;
}

/* sidebar — sticky by the book: the grid item opts out of stretching
   (align-self: start) so `position: sticky` has a scrolling ancestor to pin
   against; it is exactly one viewport tall and scrolls internally if the menu
   ever outgrows the screen. No fixed positioning, no JS. */
.sidebar {
  background: #2b2f33; color: #d8dcdf; padding: 0 0 24px;
  position: sticky; top: 0; align-self: start;
  height: 100vh; overflow-y: auto; box-sizing: border-box;
}
.sidebar .brand {
  padding: 16px 18px; font-weight: 700; font-size: 15px; color: #fff;
  border-bottom: 1px solid #3d4348;
}
.sidebar .brand small { display: block; font-weight: 400; color: #9aa2a9; font-size: 11px; }
.sidebar .section { padding: 12px 18px 4px; font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; color: #8a939b; }
.sidebar a { display: block; padding: 7px 18px; color: #d8dcdf; text-decoration: none; }
.sidebar a:hover { background: #3a4046; color: #fff; }
.sidebar a.active { background: #2ca01c; color: #fff; font-weight: 600; }

/* topbar + content */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff; border-bottom: 1px solid #dfe2e6; padding: 10px 22px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 12px;
  position: sticky; top: 0; z-index: 5;
}

/* sortable tables: any table.grid header is clickable (app.js) */
table.grid th { cursor: pointer; user-select: none; }
table.grid th.sorted-asc::after { content: " ▲"; font-size: 9px; }
table.grid th.sorted-desc::after { content: " ▼"; font-size: 9px; }
table.grid th:focus-visible { outline: 2px solid #1a6bb0; outline-offset: -2px; }
table.grid.no-sort th { cursor: default; }
table.grid tr[tabindex]:focus-visible td { background: #eaf3fb; outline: 2px solid #1a6bb0; outline-offset: -2px; }
.topbar h1 { font-size: 17px; margin: 0; }
.topbar .user { font-size: 13px; color: #555; }
.topbar select { padding: 4px 6px; max-width: 100%; }
.topbar select.needs-user { outline: 2px solid #b02a37; }
.content { padding: 20px 22px; max-width: 1200px; min-width: 0; overflow-wrap: anywhere; }

/* cards */
.cards { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.card {
  background: #fff; border: 1px solid #dfe2e6; border-radius: 6px;
  padding: 12px 16px; min-width: 150px; flex: 1 1 150px;
}
.card .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #777; }
.card .value { font-size: 20px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.card.auth-prompt .value { font-size: 14px; font-weight: 600; }
.card.good .value { color: #1e7e34; }
.card.bad .value { color: #b02a37; }

.panel { background: #fff; border: 1px solid #dfe2e6; border-radius: 6px;
  padding: 14px 16px; margin-bottom: 18px; }
.panel h2 { font-size: 14px; margin: 0 0 10px; }

/* tables — every table.grid sits in a .table-wrap so a wide grid scrolls
   inside its panel and the page body never scrolls sideways */
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
table.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: #666; border-bottom: 2px solid #dfe2e6; padding: 7px 8px; white-space: nowrap;
}
table.grid td { border-bottom: 1px solid #eceef1; padding: 7px 8px; word-break: break-word; overflow-wrap: anywhere; }
table.grid tr:hover td { background: #f6faf6; }
table.grid tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px;
  font-weight: 600; background: #e9ecef; color: #444; white-space: nowrap; }
.badge.green { background: #d9f0d3; color: #1e7e34; }
.badge.red { background: #f8d7da; color: #b02a37; }
.badge.yellow { background: #fff3cd; color: #8a6d00; }
.badge.gray { background: #e9ecef; color: #555; }

/* forms */
form.entry { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px 16px; }
form.entry label { display: flex; flex-direction: column; font-size: 12px; color: #555; gap: 4px; }
form.entry input, form.entry select, form.entry textarea {
  padding: 6px 8px; border: 1px solid #c6cbd1; border-radius: 4px; font-size: 13px;
}
form.entry .full { grid-column: 1 / -1; }
button, .btn {
  background: #2ca01c; color: #fff; border: 0; border-radius: 4px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { background: #248317; }
button.secondary, .btn.secondary { background: #e9ecef; color: #333; }
button.secondary:hover, .btn.secondary:hover { background: #d8dcdf; }

.msg { padding: 10px 12px; border-radius: 4px; margin: 10px 0; font-size: 13px; display: none; }
.msg.ok { background: #d9f0d3; color: #1e7e34; display: block; }
.msg.err { background: #f8d7da; color: #b02a37; display: block; }
.msg.warn { background: #fff3cd; color: #8a6d00; display: block; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { padding: 6px 8px; border: 1px solid #c6cbd1; border-radius: 4px; max-width: 100%; }
.toolbar label { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.muted { color: #888; }
a { color: #1a6bb0; }

/* friendly 404 (pages.py) */
.not-found { background: #fff; border: 1px solid #dfe2e6; border-radius: 6px; padding: 24px; max-width: 560px; }
.not-found h2 { margin: 0 0 8px; font-size: 18px; }

/* master index */
.index-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.index-grid a.tile {
  display: block; background: #fff; border: 1px solid #dfe2e6; border-radius: 6px;
  padding: 14px 16px; text-decoration: none; color: #222;
}
.index-grid a.tile:hover { border-color: #2ca01c; }
.index-grid a.tile b { display: block; margin-bottom: 4px; color: #1a6bb0; }
.index-grid a.tile span { font-size: 12px; color: #777; }

/* ------------------------------------------------------------ responsive
   Below 900px the sidebar becomes a horizontal top nav and the content is a
   single column; above it the sticky sidebar is untouched. */
@media (max-width: 899px) {
  body { display: block; }
  .sidebar {
    position: static; height: auto; overflow: visible; padding: 0 8px 8px;
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px;
  }
  .sidebar .brand { flex: 1 1 100%; padding: 10px 8px; border-bottom: 1px solid #3d4348; margin-bottom: 4px; }
  .sidebar .section { flex: 0 0 auto; padding: 4px 4px 4px 8px; }
  .sidebar a { display: inline-block; padding: 5px 9px; border-radius: 4px; }
  .topbar { padding: 8px 12px; position: static; }
  .topbar h1 { font-size: 16px; }
  .content { padding: 12px; max-width: 100%; }
  .cards { gap: 8px; }
  .card { min-width: 120px; flex-basis: 120px; }
  form.entry { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .toolbar input, .toolbar select, .toolbar a.btn, .toolbar button { min-width: 0 !important; }
  .toolbar input[type="search"], .toolbar input[type="number"], .toolbar select { width: 100%; }
  .index-grid { grid-template-columns: 1fr; }
}

/* Orders page: inline Paid / Deposit flag pickers under the status badges */
.flags { margin-top: 4px; font-size: 12px; color: var(--muted, #555); white-space: nowrap; }
select.flag { font-size: 12px; padding: 1px 4px; margin-left: 2px; }

/* Role visibility (owner decision 2026-09-08, spec point 381e): the shell
   stamps <html data-role="sales|gm|admin|owner|">. Anything marked
   .mgmt-only (GP, GP%, total cost, commission, management-only form fields
   and panels) disappears for a salesman — the API already omits the figures;
   this keeps the headers, labels and panels in step with them. */
html[data-role="sales"] .mgmt-only { display: none !important; }

/* ------------------------------------------------------------- sign-in
   Public pages (login / forgot / reset, auth_base.html): no sidebar, one
   centred card in the shell's colours. */
body.auth-page { display: block; min-height: 100vh; background: #2b2f33; }
.auth-wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 24px 16px;
}
.auth-brand { color: #fff; font-weight: 700; font-size: 20px; text-align: center; margin-bottom: 16px; }
.auth-brand small { display: block; font-weight: 400; color: #9aa2a9; font-size: 13px; margin-top: 2px; }
.auth-card {
  background: #fff; border-radius: 8px; border-top: 4px solid #2ca01c;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25); padding: 24px 26px;
  width: 100%; max-width: 400px; overflow-wrap: anywhere;
}
.auth-card h1 { font-size: 19px; margin: 0 0 14px; }
.auth-card p { margin: 0 0 12px; }
.auth-card .btn, .auth-card button[type="submit"] { width: 100%; padding: 10px 16px; font-size: 14px; }
.auth-card button:disabled { opacity: .65; cursor: wait; }
.auth-links { text-align: center; margin-top: 14px !important; font-size: 13px; }
/* reset / set-up page: "Your username is …" — what they will sign in with */
.auth-card .username-note {
  background: #f3faf1; border: 1px solid #cfe8c8; border-radius: 4px; padding: 8px 10px; color: #333;
}

/* the stacked form used on the auth card and the My account page */
form.auth-form { display: flex; flex-direction: column; gap: 12px; max-width: 400px; }
form.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #555; font-weight: 600; }
form.auth-form input {
  padding: 9px 10px; border: 1px solid #c6cbd1; border-radius: 4px; font-size: 15px; width: 100%;
}
form.auth-form input:focus { outline: 2px solid #2ca01c; outline-offset: 0; border-color: #2ca01c; }
form.auth-form .msg { margin: 0; }
form.auth-form button { align-self: flex-start; }
.hint { font-size: 12px; color: #777; margin: -4px 0 0; }

/* top bar: the signed-in person, My account, Sign out */
.topbar .user.signed-in { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; }
.topbar .user.signed-in .who { font-weight: 600; color: #333; }
.topbar .user.signed-in a { text-decoration: none; }
.topbar .user.signed-in a:hover, .topbar .user.signed-in a.active { text-decoration: underline; }
button.small, .btn.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .6; cursor: default; }

/* My account */
.account-panel { max-width: 560px; }
dl.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0 0 12px; }
dl.kv dt { color: #777; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding-top: 2px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Users page */
/* words wrap only at spaces here (the table scrolls inside .table-wrap on a
   phone instead of breaking "owner" into "own / er") */
.users-table td { word-break: normal; overflow-wrap: normal; white-space: nowrap; }
.users-table td.wrap { white-space: normal; min-width: 110px; }
.users-table td.wrap.when { min-width: 90px; }
.users-table td.row-actions { white-space: normal; min-width: 180px; }
.users-table td.row-actions button { margin: 2px 0; }
.users-table tr.inactive td { color: #999; }
.users-table tr.detail-row td { background: #f6f8fa; white-space: normal; }
.users-table tr.detail-row:hover td { background: #f6f8fa; }
form.entry label.check { flex-direction: row; align-items: flex-start; gap: 6px; }
form.entry label.check input { padding: 0; margin: 2px 6px 0 0; }
.link-box { border-color: #2ca01c; background: #f3faf1; }
.link-box h2 { margin-bottom: 6px; }
.link-box p { margin: 0 0 10px; }
.link-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-row input {
  flex: 1 1 260px; min-width: 0; padding: 7px 8px; border: 1px solid #c6cbd1; border-radius: 4px;
  font-family: Consolas, "Courier New", monospace; font-size: 12px; background: #fff;
}

@media (max-width: 899px) {
  .auth-card { padding: 20px 18px; }
  .topbar .user.signed-in { gap: 6px 10px; }
  .users-table td.row-actions { min-width: 180px; }
}
