* { box-sizing: border-box; }
body { font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; margin: 0; background: #f4f5f7; color: #1a1a1a; }
.topbar { background: #14261d; color: #fff; padding: 10px 20px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px; row-gap: 8px; }
.topbar .brand { font-weight: 700; font-size: 18px; letter-spacing: 0.5px; order: 0; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; order: 1; }
.topbar nav a { color: #cfd8e3; text-decoration: none; padding: 8px 10px; border-radius: 4px; font-size: 14px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.topbar nav a svg { width: 15px; height: 15px; flex: none; opacity: 0.9; }
.topbar nav a:hover, .topbar nav a.active { background: #1f3a2b; color: #fff; }
.topbar .job-search { order: 2; margin-left: auto; }
.topbar-account { order: 3; margin: 0 !important; position: relative; }
.topbar form { margin: 0; }
.topbar button.linklike { background: none; border: none; color: #cfd8e3; cursor: pointer; font-size: 14px; padding: 8px 10px; white-space: nowrap; }
.account-trigger { display: inline-flex; align-items: center; gap: 6px; background: none; border: none; color: #cfd8e3; cursor: pointer; font-size: 14px; padding: 8px 10px; white-space: nowrap; border-radius: 4px; }
.account-trigger:hover { background: #1f3a2b; color: #fff; }
.account-menu { display: none; position: absolute; top: 34px; right: 0; width: 200px; background: #fff; border: 1px solid #e2e5e9; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,0.12); z-index: 50; padding: 6px 0; }
.account-menu a { display: flex; align-items: center; gap: 8px; padding: 8px 14px; color: #1a1a1a; text-decoration: none; font-size: 14px; }
.account-menu a svg { width: 15px; height: 15px; flex: none; opacity: 0.7; }
.account-menu a:hover, .account-menu a.active { background: #f4f5f7; }
.account-menu-divider { height: 1px; background: #eee; margin: 6px 0; }
.account-menu form { margin: 0; }
.account-menu form button { width: 100%; text-align: left; background: none; border: none; color: #b3261e; cursor: pointer; font-size: 14px; padding: 8px 14px; }
.account-menu form button:hover { background: #f4f5f7; }
.container { max-width: 1200px; margin: 24px auto; padding: 0 20px; }
h1 { font-size: 22px; margin-bottom: 4px; }
.subtitle { color: #666; margin-bottom: 20px; }
.card { background: #fff; border: 1px solid #e2e5e9; border-radius: 8px; padding: 16px 20px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #eee; font-size: 14px; }
th { background: #fafbfc; color: #555; font-weight: 600; }
tr:hover td { background: #fafcff; }
.btn { display: inline-block; background: #1e5b34; color: #fff; padding: 8px 14px; border-radius: 6px; text-decoration: none; font-size: 14px; border: none; cursor: pointer; }
.btn.secondary { background: #eef1f5; color: #1a1a1a; }
.btn.danger { background: #e5484d; }
.btn-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
input, select, textarea { padding: 8px 10px; border: 1px solid #d7dbe0; border-radius: 6px; font-size: 14px; width: 100%; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; margin-top: 12px; color: #333; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.stat { background: #fff; border-radius: 8px; padding: 16px; border: 1px solid #e2e5e9; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .label { color: #666; font-size: 13px; }
a.stat { display: block; text-decoration: none; color: inherit; transition: box-shadow 0.15s, border-color 0.15s; }
a.stat:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-color: #b8c0c9; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: #eef1f5; }
.badge.completed { background: #dff5e1; color: #1f7a34; }
.badge.assigned { background: #fff4d6; color: #93690a; }
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-box { background: #fff; padding: 32px; border-radius: 10px; width: 90%; max-width: 320px; border: 1px solid #e2e5e9; }
.error { color: #e5484d; font-size: 13px; margin-top: 8px; }
a.plain { color: #1e5b34; text-decoration: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid #e2e5e9; margin-bottom: 16px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: #555; font-size: 14px; border-bottom: 2px solid transparent; }
.tabs a.active { color: #1e5b34; border-color: #1e5b34; font-weight: 600; }
.tabs a { cursor: pointer; }
.badge.crew { background: #e3ecff; color: #2445a8; }
details > summary { cursor: pointer; color: #1e5b34; font-size: 13px; }
details ul { font-size: 13px; color: #444; }
@media print { .no-print { display: none !important; } }
.job-search { position: relative; margin-right: 4px; }
.job-search input { width: 220px; padding: 6px 10px; border-radius: 6px; border: 1px solid #2c4a38; background: #1f3a2b; color: #fff; font-size: 13px; }
.job-search input::placeholder { color: #9fb3a6; }
.job-search input:focus { outline: none; border-color: #3a7a52; background: #24422f; }
.job-search-results { display: none; position: absolute; top: 34px; right: 0; width: 280px; max-height: 320px; overflow-y: auto; background: #fff; border: 1px solid #e2e5e9; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,0.12); z-index: 50; }
.job-search-item { display: block; padding: 8px 12px; color: #1a1a1a; text-decoration: none; font-size: 13px; border-bottom: 1px solid #f0f0f0; }
.job-search-item:hover { background: #f4f5f7; }
.job-search-item:last-child { border-bottom: none; }
.job-search-empty { padding: 10px 12px; color: #888; font-size: 13px; }
.badge.backcharge { background: #ffe1e1; color: #b3261e; }
.negative-amount { color: #b3261e; font-weight: 600; }
.amount-materials { color: #2445a8; font-weight: 600; }
.amount-balance { color: #b3261e; font-weight: 600; }
.amount-jobvalue { color: #1e5b34; font-weight: 600; }

/* ---------- Scheduler ---------- */
.sched-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.sched-toolbar .btn { margin: 0; }
.sched-range { font-weight: 700; font-size: 16px; min-width: 220px; text-align: center; }
.sched-board { display: grid; position: relative; min-width: 900px; }
.sched-cell { border-bottom: 1px solid #e2e5e9; border-right: 1px solid #eee; padding: 4px 8px; font-size: 12px; }
.sched-header { background: #fafbfc; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #555; position: sticky; top: 0; z-index: 2; }
.sched-header.sched-today { background: #eaf6ee; }
.sched-dow { font-weight: 700; font-size: 11px; letter-spacing: 0.5px; }
.sched-date { font-size: 11px; }
.sched-label-header { background: #fafbfc; border-right: 1px solid #eee; position: sticky; left: 0; z-index: 3; }
.sched-tradebar { background: #eef2f6; color: #2445a8; font-weight: 700; font-size: 12px; padding: 4px 10px; border-bottom: 1px solid #e2e5e9; display: flex; align-items: center; }
.sched-lanebg { border-bottom: 1px solid #f0f0f0; }
.sched-block { margin: 3px 2px; border-radius: 4px; padding: 3px 8px; font-size: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; display: flex; align-items: center; box-shadow: 0 1px 2px rgba(0,0,0,0.15); user-select: none; }
.sched-block.sched-appt { opacity: 0.85; }
.sched-block-link { color: #fff; text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; -webkit-user-drag: none; display: inline-flex; align-items: center; }
.sched-check { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 14px; height: 14px; border-radius: 50%; background: #3a3a3a; color: #fff; font-size: 9px; margin-right: 4px; }
.sched-block.sched-completed { opacity: 0.92; }
.unsched-item { display: inline-flex; flex-direction: column; gap: 2px; border-left: 4px solid #8a8f98; background: #fafbfc; border-radius: 4px; padding: 6px 10px; margin: 4px 6px 4px 0; font-size: 13px; }
.unsched-item:active { cursor: grabbing; }
.sched-scroll { cursor: grab; user-select: none; }
.sched-scroll.grabbing { cursor: grabbing; }
.sched-board { user-select: none; }
.badge.role-full { background: #dff5e1; color: #1f7a34; }
.badge.role-view { background: #e3ecff; color: #2445a8; }
.view-only-banner { background: #fff4d6; color: #93690a; text-align: center; font-size: 13px; padding: 6px 12px; }

/* ---------- Mobile responsiveness ---------- */
body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.card { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
  .container { padding: 0 12px; margin: 16px auto; }
  .card { padding: 12px 14px; }
  h1 { font-size: 19px; }

  /* Topbar: brand + sign-out on row 1, job search full-width on row 2,
     nav as a horizontally-scrollable pill row on row 3 -- avoids the
     cramped wrapping/overlap that happens with the desktop layout. */
  .topbar { padding: 10px 12px; }
  .topbar .brand { order: 0; font-size: 16px; }
  .topbar-account { order: 1; font-size: 12px; }
  .topbar button.linklike { font-size: 12px; padding: 6px 0; }
  .account-trigger { font-size: 12px; padding: 6px 0; }
  .account-menu { top: 28px; }
  .topbar .job-search { order: 2; width: 100%; margin-left: 0; }
  .topbar .job-search input { width: 100%; }
  .topbar nav { order: 3; width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 2px; padding-bottom: 2px; }
  .topbar nav a { font-size: 13px; padding: 6px 8px; }

  /* Tables scroll horizontally inside their card instead of blowing out
     the whole page width -- the card itself is the scroll container
     (see the base .card rule above), this just tightens spacing. */
  table { font-size: 13px; }
  th, td { padding: 6px 8px; }

  .stat .num { font-size: 21px; }
  .sched-toolbar { flex-wrap: wrap; }
  .sched-range { min-width: 0; }
}
