:root {
  --green: #1a9e5b;
  --green-dark: #148049;
  --green-tint: #e8f6ee;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e2e6ea;
  --border-strong: #cfd5db;
  --text: #1d2730;
  --muted: #67727e;
  --faint: #98a2ad;
  --red: #d33f3f;
  --red-bg: #fdeceb;
  --amber: #b26b00;
  --amber-bg: #fff3d9;
  --blue: #2e6bd6;
  --blue-bg: #e9f0fc;
  --shadow: 0 1px 2px rgba(16, 24, 32, 0.06), 0 1px 3px rgba(16, 24, 32, 0.08);
  --shadow-lg: 0 8px 28px rgba(16, 24, 32, 0.16);
  --radius: 8px;
  --sidebar: 232px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.hidden { display: none !important; }

/* ---------- buttons + inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: #fff; cursor: pointer;
  font-weight: 600; white-space: nowrap;
}
.btn:hover { background: #f7f8f9; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef1f3; }
.btn:disabled { opacity: 0.5; cursor: default; }
.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: #fff;
}
textarea.input { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; }
.input:focus { outline: 2px solid rgba(26, 158, 91, 0.35); border-color: var(--green); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--green); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- auth screens ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 20px; margin: 12px 0 4px; }
.auth-card p { color: var(--muted); margin: 0 0 18px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; letter-spacing: -0.2px; }
.logo-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--green); display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 6px 5px; align-items: start; }
.logo-mark i { background: #fff; border-radius: 1.5px; display: block; }
.logo-mark i:nth-child(1) { height: 18px; } .logo-mark i:nth-child(2) { height: 12px; } .logo-mark i:nth-child(3) { height: 8px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100%; }
.sidebar { background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.sidebar .brand { padding: 16px 16px 10px; }
.ws-switch { margin: 6px 12px 10px; }
.ws-switch select { font-weight: 700; }
.nav { padding: 4px 8px; flex: 1; overflow-y: auto; }
.nav-label { font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: 0.6px; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px;
  color: var(--text); text-decoration: none; font-weight: 600; position: relative;
}
.nav a:hover { background: #f3f5f7; }
.nav a.active { background: var(--green-tint); color: var(--green-dark); }
.nav a.active::before { content: ""; position: absolute; left: -8px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--green); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 600; }
.sidebar .me { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: #dfe7ee; color: #33414e; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.me .who { flex: 1; min-width: 0; }
.me .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .who small { color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--border); padding: 14px 20px 0; }
.topbar-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: -0.2px; }
.topbar .spacer { flex: 1; }
.search { position: relative; }
.search input { width: 240px; padding-left: 32px; }
.search svg { position: absolute; left: 9px; top: 9px; width: 16px; height: 16px; color: var(--faint); }
.tabs { display: flex; gap: 2px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 9px 12px 10px; cursor: pointer; color: var(--muted);
  font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; display: flex; gap: 6px; align-items: center;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--green-dark); border-bottom-color: var(--green); }
.tab .n { background: #eef1f3; color: var(--muted); border-radius: 10px; padding: 0 7px; font-size: 12px; line-height: 18px; }
.tab.active .n { background: var(--green-tint); color: var(--green-dark); }
.tab .n.alert { background: var(--red-bg); color: var(--red); }
.content { flex: 1; min-height: 0; overflow: auto; }
.mobile-top, .menu-scrim { display: none; }

/* ---------- board ---------- */
.board { display: flex; gap: 12px; padding: 16px 20px 20px; height: 100%; overflow-x: auto; align-items: stretch; }
.col {
  flex: 0 0 280px; background: #eef1f4; border-radius: 10px; display: flex; flex-direction: column;
  max-height: 100%; min-height: 0; border: 1px solid transparent;
}
.col.over { background: #fbeeee; border-color: #f3c9c9; }
.col.drop { border-color: var(--green); background: #e9f5ee; }
.col-head { padding: 10px 12px 8px; display: flex; align-items: center; gap: 8px; }
.col-head h3 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }
.col-head .cnt { font-size: 12px; font-weight: 700; color: var(--muted); background: #fff; border-radius: 10px; padding: 0 8px; line-height: 20px; }
.col.over .col-head .cnt { background: var(--red); color: #fff; }
.col-head .info { margin-left: auto; color: var(--faint); cursor: help; display: grid; place-items: center; }
.col-head .info svg { width: 16px; height: 16px; }
.col-head .add { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 4px; font-size: 18px; line-height: 1; }
.col-head .add:hover { background: #e1e6ea; color: var(--text); }
.col-body { padding: 0 8px 10px; overflow-y: auto; flex: 1; min-height: 60px; }
.col-empty { color: var(--faint); font-size: 12px; text-align: center; padding: 14px 0; }
.wip-note { font-size: 11px; color: var(--red); font-weight: 600; padding: 0 12px 6px; }

.card {
  background: #fff; border-radius: 8px; padding: 10px 11px; margin-bottom: 8px; box-shadow: var(--shadow);
  cursor: pointer; border-left: 3px solid transparent; position: relative;
}
.card:hover { box-shadow: 0 2px 8px rgba(16, 24, 32, 0.14); }
.card.late { border-left-color: var(--red); }
.card.soon { border-left-color: #e0a100; }
.card.blocked { background: #fff8f8; }
.card.dragging { opacity: 0.4; }
.placeholder { height: 54px; border: 2px dashed #9fd3b5; border-radius: 8px; margin-bottom: 8px; background: rgba(26, 158, 91, 0.06); }
.card-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.jobno { font-weight: 700; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card .cust { font-weight: 700; line-height: 1.3; }
.card .desc { color: #3b4752; font-size: 13px; margin-top: 2px; line-height: 1.35; word-break: break-word; }
.card-foot { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.card-foot .age { font-size: 11px; color: var(--faint); font-weight: 600; }
.card-foot .age.warn { color: var(--amber); }
.card-foot .age.bad { color: var(--red); }
.card-foot .avatar { margin-left: auto; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 8px; line-height: 18px; white-space: nowrap; }
.pill.due { margin-left: auto; background: #eef1f3; color: #46525d; }
.pill.late { background: var(--red-bg); color: var(--red); }
.pill.soon { background: var(--amber-bg); color: var(--amber); }
.pill.block { background: var(--red); color: #fff; }
.pill.noflex { background: #fff; color: var(--amber); border: 1px solid #f0cf8e; line-height: 16px; }
.pill.rush { background: #fde7f0; color: #b8236a; }
.pill.tag { background: var(--blue-bg); color: var(--blue); }
.pill.stage { background: #eef1f3; color: #3b4752; }
.pill.done { background: var(--green-tint); color: var(--green-dark); }

/* ---------- list ---------- */
.list-wrap { padding: 16px 20px 24px; }
table.list { width: 100%; border-collapse: separate; border-spacing: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fafbfc; cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; }
table.list th .arr { color: var(--green); }
table.list td { padding: 10px 12px; border-bottom: 1px solid #eef0f2; vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: #f8faf9; }
table.list td.num { font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; white-space: nowrap; }
.list-empty { padding: 40px; text-align: center; color: var(--muted); background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- side panel ---------- */
.scrim { position: fixed; inset: 0; background: rgba(16, 24, 32, 0.25); z-index: 40; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 100%; background: #fff; z-index: 41;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.panel-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.panel-head .top { display: flex; align-items: center; gap: 8px; }
.panel-head h2 { font-size: 17px; margin: 6px 0 0; line-height: 1.3; }
.panel-head .saved { font-size: 12px; color: var(--green-dark); margin-left: auto; opacity: 0; transition: opacity 0.2s; }
.panel-head .saved.on { opacity: 1; }
.panel-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.stage-box { background: #f7f8fa; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 16px; }
.stage-box .row { display: flex; gap: 8px; }
.stage-box .dod { font-size: 12px; color: var(--muted); margin-top: 8px; }
.stage-box .dod b { color: var(--text); }
.andon { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 4px 0 16px; }
.andon.on { border-color: #f1b3b3; background: #fff6f6; }
.andon .check { font-weight: 700; }
.andon .input { margin-top: 8px; }
.section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 20px 0 8px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f0f2f4; font-size: 13px; }
.feed li:last-child { border-bottom: 0; }
.feed .t { color: var(--faint); font-size: 12px; white-space: nowrap; }
.feed .comment { background: #f5f7f9; border-radius: 6px; padding: 6px 9px; margin-top: 3px; white-space: pre-wrap; }
.comment-box { display: flex; gap: 8px; margin-bottom: 8px; }
.comment-box .input { height: 36px; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(16, 24, 32, 0.35); z-index: 50; display: grid; place-items: start center; padding: 8vh 16px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; box-shadow: var(--shadow-lg); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal-head h2 { font-size: 17px; margin: 0; flex: 1; }
.modal-body { padding: 18px 20px 6px; }
.modal-foot { padding: 12px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- admin ---------- */
.admin { padding: 20px; max-width: 1000px; }
.box { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 20px; }
.box-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.box-head h2 { font-size: 15px; margin: 0; flex: 1; }
.box-body { padding: 16px; }
.box table { width: 100%; border-collapse: collapse; }
.box th { text-align: left; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.box td { padding: 8px 10px; border-bottom: 1px solid #f0f2f4; vertical-align: middle; }
.box tr:last-child td { border-bottom: 0; }
.stage-row td .input { height: 32px; }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.ws-roles { display: grid; gap: 8px; }
.ws-roles .r { display: flex; align-items: center; gap: 10px; }
.ws-roles .r span { flex: 1; font-weight: 600; }
.ws-roles select { width: 160px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #1d2730; color: #fff; padding: 10px 16px; border-radius: 8px; font-weight: 600; opacity: 0; pointer-events: none; transition: all 0.2s; z-index: 60; max-width: calc(100% - 32px); }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--red); }

/* ---------- TV mode ---------- */
body.tv { background: #10171e; color: #e9eef2; overflow: hidden; }
.tv-wrap { height: 100vh; display: flex; flex-direction: column; padding: 18px 20px; gap: 14px; }
.tv-head { display: flex; align-items: center; gap: 24px; }
.tv-head h1 { margin: 0; font-size: 28px; letter-spacing: -0.3px; }
.tv-head .clock { margin-left: auto; font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tv-stat { display: flex; flex-direction: column; align-items: center; background: #1b2530; border-radius: 10px; padding: 6px 18px; min-width: 110px; }
.tv-stat b { font-size: 28px; line-height: 1.1; }
.tv-stat span { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: #9fb0bf; }
.tv-stat.red b { color: #ff7b7b; } .tv-stat.amber b { color: #ffc95c; }
.tv-board { flex: 1; display: flex; gap: 10px; min-height: 0; }
.tv-col { flex: 1 1 0; min-width: 0; background: #18222c; border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; }
.tv-col.over { box-shadow: inset 0 0 0 2px #e05252; }
.tv-col h3 { margin: 0; padding: 10px 12px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; display: flex; gap: 8px; align-items: center; }
.tv-col h3 .cnt { margin-left: auto; background: #2a3846; padding: 0 9px; border-radius: 10px; font-size: 13px; }
.tv-col.over h3 .cnt { background: #e05252; }
.tv-cards { padding: 0 8px 8px; overflow: hidden; flex: 1; }
.tv-card { background: #233140; border-radius: 8px; padding: 8px 10px; margin-bottom: 7px; border-left: 4px solid transparent; }
.tv-card.late { border-left-color: #ff6b6b; } .tv-card.soon { border-left-color: #ffc14d; }
.tv-card.blocked { background: #3a2329; }
.tv-card .l1 { display: flex; gap: 6px; align-items: center; font-size: 12px; color: #9fb0bf; font-weight: 700; }
.tv-card .l1 .d { margin-left: auto; }
.tv-card .l1 .d.late { color: #ff8f8f; } .tv-card .l1 .d.soon { color: #ffd27a; }
.tv-card .c { font-weight: 700; font-size: 15px; line-height: 1.25; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-card .s { font-size: 13px; color: #c3cfd9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-more { text-align: center; color: #9fb0bf; font-size: 13px; padding: 4px; }
.tv-exit { position: fixed; right: 12px; bottom: 10px; color: #6d7f90; font-size: 12px; text-decoration: none; }

/* ---------- mobile ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 45; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-lg); }
  .shell.menu-open .sidebar { transform: none; }
  .shell.menu-open .menu-scrim { display: block; }
  .menu-scrim { display: none; position: fixed; inset: 0; background: rgba(16, 24, 32, 0.3); z-index: 44; }
  .mobile-top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #fff; border-bottom: 1px solid var(--border); }
  .mobile-top .title { font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar { padding: 10px 16px 0; }
  .topbar h1 { display: none; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .topbar .spacer, .hide-mobile { display: none; }
  .board { padding: 12px 16px 16px; scroll-snap-type: x mandatory; gap: 10px; }
  .col { flex-basis: 84vw; scroll-snap-align: start; }
  .list-wrap { padding: 12px 16px; }
  table.list .opt { display: none; }
  .panel { width: 100%; }
  .admin { padding: 14px 16px; }
  .row2 { grid-template-columns: 1fr; }
  .modal-wrap { padding-top: 16px; }
}
