/* PLC Integration Tracker — Vitoria (Integra Wave 7) */
:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1c232d;
  --line: #2a323d;
  --line-2: #39424f;
  --text: #e6edf3;
  --text-dim: #97a3b2;
  --text-mute: #6b7684;
  --accent: #2f81f7;
  --accent-2: #1f6feb;

  --todo: #6b7684;
  --progress: #d29922;
  --problem: #f85149;
  --done: #2ea043;

  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ---------- Layout ---------- */
.app { max-width: 1180px; margin: 0 auto; padding: 18px 20px 80px; }

header.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.brand { display: flex; flex-direction: column; gap: 2px; margin-right: auto; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .2px; }
.brand .sub { color: var(--text-mute); font-size: 12px; }

.gprogress { min-width: 240px; }
.gprogress .label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.bar { height: 8px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--done)); border-radius: 99px; transition: width .3s; }

.tools { display: flex; gap: 8px; }
.btn {
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font-size: 13px; transition: .15s;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: #222b36; }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--problem); color: var(--problem); }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.icon { padding: 5px 8px; }

/* ---------- Line tabs ---------- */
.lines { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.line-tab {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 99px;
  padding: 6px 12px 6px 14px; display: flex; align-items: center; gap: 9px; transition: .15s;
}
.line-tab:hover { border-color: var(--line-2); }
.line-tab.active { border-color: var(--accent); background: #16233a; }
.line-tab .name { font-weight: 600; letter-spacing: .3px; }
.line-tab .mini { width: 46px; height: 5px; background: var(--bg-3); border-radius: 99px; overflow: hidden; }
.line-tab .mini > span { display: block; height: 100%; background: var(--done); }
.line-tab .pct { font-size: 11px; color: var(--text-mute); min-width: 30px; text-align: right; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search { flex: 1; min-width: 180px; position: relative; }
.search input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px 8px 32px; outline: none;
}
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 10px; top: 9px; color: var(--text-mute); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 99px;
  padding: 5px 11px; font-size: 12px; color: var(--text-dim); display: inline-flex; gap: 6px; align-items: center;
}
.chip.active { color: var(--text); border-color: var(--line-2); background: var(--bg-3); }
.chip .dot { width: 8px; height: 8px; border-radius: 99px; }

/* ---------- Person filter + global search hits ---------- */
#personFilter {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; outline: none; color: var(--text); max-width: 190px;
}
#personFilter:focus { border-color: var(--accent); }
#personFilter.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.hits-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: -4px 0 12px; }

/* ---------- Due badge ---------- */
.t-due { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.t-due.soon { color: var(--progress); font-weight: 600; }
.t-due.overdue { color: var(--problem); font-weight: 700; }

/* ---------- Dashboard ---------- */
.modal.wide { max-width: 720px; }
table.dash { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dash th, table.dash td { padding: 7px 9px; text-align: left; border-bottom: 1px solid var(--line); }
table.dash th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); }
table.dash tbody tr { cursor: pointer; }
table.dash tbody tr:hover { background: var(--bg-3); }
table.dash .dl-name { font-weight: 700; }
table.dash .dl-prog .mini { display: inline-block; width: 60px; height: 5px; background: var(--bg-3); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
table.dash .dl-prog .mini > span { display: block; height: 100%; background: var(--done); }
table.dash .dl-blocked { color: var(--problem); font-weight: 700; }
table.dash .dl-high { color: var(--progress); font-weight: 700; }
table.dash .dl-overdue { color: var(--problem); font-weight: 700; }
table.dash td.zero { color: var(--text-mute); font-weight: 400; }
table.dash tfoot td { border-top: 2px solid var(--line-2); border-bottom: none; font-weight: 700; }

/* ---------- History filters ---------- */
.log-filters { display: flex; gap: 8px; margin-bottom: 10px; }
.log-filters select { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; outline: none; color: var(--text); flex: 1; }
.log-filters select:focus { border-color: var(--accent); }

/* ---------- Line summary ---------- */
.line-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.line-head h2 { margin: 0; font-size: 20px; }
.line-head .counts { display: flex; gap: 10px; flex-wrap: wrap; }
.count { font-size: 12px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; }
.count .dot { width: 9px; height: 9px; border-radius: 99px; }

/* ---------- Station groups & rows ---------- */
.group { margin-bottom: 18px; }
.group-title { font-size: 12px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .8px; margin: 6px 2px 8px; }
.group-title .grp-count { color: var(--text-dim); background: var(--bg-3); border-radius: 99px; padding: 1px 7px; font-size: 11px; margin-left: 4px; }

/* Area header (grouping + own tasks) */
.area-group { margin-bottom: 18px; }
.area-head {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 7px 10px; margin: 4px 0 8px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg-2);
}
.area-head:hover { border-color: var(--line-2); }
.area-head.open { border-color: var(--accent); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.area-head .expand { background: none; border: none; color: var(--text-mute); padding: 2px; display: flex; }
.area-head .area-title { font-weight: 700; letter-spacing: .4px; }
.area-tasks {
  border: 1px solid var(--accent); border-top: none; border-radius: 0 0 9px 9px;
  padding: 10px 12px 12px; margin: -8px 0 10px; background: #131922;
}

/* PLC divider */
.plc-divider {
  font-size: 13px; font-weight: 700; letter-spacing: .5px; color: var(--accent);
  border-top: 1px solid var(--line-2); padding: 12px 2px 2px; margin: 10px 0 4px;
}
.plc-divider.muted { color: var(--text-mute); }

/* Area editor */
.area-list { display: flex; flex-direction: column; gap: 7px; margin: 8px 0 12px; }
.area-row, .area-add { display: flex; align-items: center; gap: 7px; }
.area-add { border-top: 1px solid var(--line); padding-top: 12px; }
.area-row select, .area-add select { background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 7px; padding: 6px 8px; outline: none; }
.area-row input, .area-add input { width: 70px; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; outline: none; }
.area-row input:focus, .area-add input:focus { border-color: var(--accent); }
.a-dash { color: var(--text-mute); }
.area-row .a-del { margin-left: auto; }

.station {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 8px; overflow: hidden; border-left: 3px solid var(--todo);
}
.station.s-progress { border-left-color: var(--progress); }
.station.s-problem { border-left-color: var(--problem); }
.station.s-done { border-left-color: var(--done); }

.st-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.st-row .expand { background: none; border: none; color: var(--text-mute); padding: 2px; display: flex; }
.st-row .code { font-family: "Cascadia Code", "Consolas", monospace; font-weight: 600; letter-spacing: .3px; min-width: 108px; }
.type-badge {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text-dim);
}
.st-meta { color: var(--text-mute); font-size: 12px; display: flex; gap: 10px; }
.st-progress-mini { flex: 1; max-width: 160px; }
.st-spacer { flex: 1; }

.status-select {
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 5px 10px; font-size: 12px; font-weight: 600; outline: none;
}
.status-select:focus { border-color: var(--accent); }

.tasks-count { font-size: 11px; color: var(--text-mute); min-width: 62px; text-align: right; }
.status-badge { font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 99px; border: 1px solid; background: var(--bg-3); white-space: nowrap; }

/* ---------- Station detail ---------- */
.st-detail { border-top: 1px solid var(--line); padding: 12px 14px 14px 42px; background: #131922; display: none; }
.station.open .st-detail { display: block; }
.st-detail h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); }

/* ---------- Task cards ---------- */
.task-cards { display: flex; flex-direction: column; gap: 7px; }
.task-card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  border-left: 3px solid var(--line-2); overflow: hidden;
}
.task-card.s-progress { border-left-color: var(--progress); }
.task-card.s-blocked { border-left-color: var(--problem); }
.task-card.s-done { border-left-color: var(--done); }

.task-main { display: flex; align-items: center; gap: 10px; padding: 8px 12px; }
.task-main .t-expand { background: none; border: none; color: var(--text-mute); padding: 2px; display: flex; }
.prio-badge { width: 20px; height: 20px; border-radius: 6px; color: #0b0e12; font-weight: 800; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.t-title { font-weight: 500; cursor: pointer; }
.task-card.s-done .t-title { color: var(--text-mute); text-decoration: line-through; }
.t-assignee { font-size: 12px; color: var(--text-dim); background: var(--bg-3); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; cursor: pointer; white-space: nowrap; }
.t-assignee.none { color: var(--text-mute); border-style: dashed; }
.t-spacer { flex: 1; }
.t-cmt { font-size: 12px; color: var(--text-mute); white-space: nowrap; }
.t-status { background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; padding: 4px 9px; font-size: 12px; font-weight: 600; outline: none; }
.t-status:focus { border-color: var(--accent); }

.task-detail { border-top: 1px solid var(--line); padding: 11px 12px 12px; background: var(--bg-2); }
.t-meta { font-size: 12px; color: var(--text-mute); margin-bottom: 10px; }
.t-fields { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.t-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--text-dim); }
.t-fields input, .t-fields select { background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; outline: none; color: var(--text); }
.t-fields input:focus, .t-fields select:focus { border-color: var(--accent); }
.t-fields .f-assignee { min-width: 150px; }
.f-spacer { flex: 1; }

.comments h5 { margin: 0 0 7px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.comment-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 8px; }
.comment { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
.c-top { display: flex; gap: 8px; align-items: baseline; }
.c-author { font-weight: 600; font-size: 13px; }
.c-time { font-size: 11px; color: var(--text-mute); }
.c-text { font-size: 13px; color: var(--text-dim); margin-top: 3px; white-space: pre-wrap; }
.add-comment { display: flex; gap: 6px; }
.add-comment input { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; outline: none; }
.add-comment input:focus { border-color: var(--accent); }

.add-task { display: flex; gap: 6px; margin-top: 10px; }
.add-task input[type=text] { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; outline: none; }
.add-task input:focus { border-color: var(--accent); }
.add-task .prio-select { background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 7px; padding: 0 8px; outline: none; }

.st-detail .row-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.st-notes { margin-top: 16px; }
.st-notes textarea { width: 100%; min-height: 60px; resize: vertical; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; outline: none; }
.st-notes textarea:focus { border-color: var(--accent); }

.empty { text-align: center; color: var(--text-mute); padding: 50px 20px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none;
  align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: var(--shadow); width: 100%; max-width: 460px; max-height: 85vh; overflow: auto;
}
.modal h3 { margin: 0; padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 15px; }
.modal .body { padding: 16px 18px; }
.modal .foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.type-toggle { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.type-toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.hint { color: var(--text-mute); font-size: 12px; margin: 4px 0 0; }

/* ---------- Activity log ---------- */
.log-list { max-height: 60vh; overflow: auto; }
.log-item { padding: 9px 4px; border-bottom: 1px solid var(--line); }
.log-item:last-child { border-bottom: none; }
.log-top { display: flex; align-items: center; gap: 8px; }
.log-user { font-weight: 600; }
.log-act { font-size: 11px; color: var(--text-dim); background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 6px; padding: 1px 7px; }
.log-time { margin-left: auto; font-size: 11px; color: var(--text-mute); }
.log-sum { font-size: 13px; color: var(--text-dim); margin-top: 3px; }
.log-loc { font-family: "Cascadia Code", "Consolas", monospace; color: var(--text-mute); }

#btnUser { font-weight: 600; }

/* ---------- View toggle (Tasks / Lines) ---------- */
.view-toggle { display: flex; border: 1px solid var(--line-2); border-radius: 9px; overflow: hidden; flex-shrink: 0; }
.vt-btn { background: var(--bg-2); border: none; padding: 8px 14px; color: var(--text-dim); font-size: 13px; cursor: pointer; }
.vt-btn.active { background: var(--accent-2); color: #fff; font-weight: 600; }
body.view-tasks #lines, body.view-tasks #searchHits, body.view-tasks #statusFilters { display: none; }

/* ---------- Flat task list (mobile-first) ---------- */
.task-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 12px; }
.tasks-flat { display: flex; flex-direction: column; gap: 8px; }
.ft-row {
  display: flex; align-items: center; gap: 11px; text-align: left; width: 100%;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 13px; border-left: 3px solid var(--todo); cursor: pointer; color: var(--text);
}
.ft-row:active { background: var(--bg-3); }
.ft-row.s-progress { border-left-color: var(--progress); }
.ft-row.s-blocked { border-left-color: var(--problem); }
.ft-row.s-done { border-left-color: var(--done); opacity: .75; }
.ft-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ft-text { font-weight: 600; line-height: 1.35; }
.ft-row.s-done .ft-text { text-decoration: line-through; color: var(--text-mute); }
.ft-ctx { font-size: 12px; color: var(--text-mute); }
.ft-status { font-size: 12px; font-weight: 700; white-space: nowrap; }

/* ---------- Bottom sheet ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: none; z-index: 70; }
.sheet-back.open { display: block; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-bottom: none;
  border-radius: 16px 16px 0 0; padding: 12px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 85vh; overflow: auto; box-shadow: var(--shadow);
}
.sheet-grab { width: 42px; height: 4px; border-radius: 99px; background: var(--line-2); margin: 0 auto 12px; }
.sh-title { font-weight: 700; font-size: 16px; }
.sh-ctx { color: var(--text-mute); font-size: 12px; margin: 3px 0 14px; font-family: "Cascadia Code", "Consolas", monospace; }
.sh-status { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.sh-st {
  padding: 14px 8px; border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--bg-3); font-weight: 700; color: var(--text-dim); cursor: pointer; font-size: 14px;
}
.sh-st.active { border-color: var(--c); color: var(--c); background: var(--bg); }
.sh-row { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.sh-row input[type=text] { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; outline: none; }
.sh-row input[type=text]:focus { border-color: var(--accent); }
.sh-row input[type=date] { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none; color: var(--text); }
.sh-row select { background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 11px; outline: none; color: var(--text); flex: 1; }
.sh-foot { justify-content: flex-end; margin-top: 4px; }
.qa-lines { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.qa-lines .chip { flex-shrink: 0; }
.qa-prio { display: flex; gap: 6px; }
.qa-me { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-dim); margin-left: auto; }
.qa-me input { width: 17px; height: 17px; accent-color: var(--accent); }

/* ---------- FAB (quick add) ---------- */
#fab {
  position: fixed; right: 18px; bottom: 18px; width: 58px; height: 58px; border-radius: 99px;
  background: var(--accent-2); border: none; color: #fff; font-size: 30px; line-height: 1;
  display: none; align-items: center; justify-content: center; box-shadow: var(--shadow);
  z-index: 60; cursor: pointer;
}
#fab:hover { background: var(--accent); }
body.view-tasks #fab { display: flex; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .app { padding: 10px 10px 90px; }
  .brand .sub { display: none; }
  .brand h1 { font-size: 15px; }
  header.top { gap: 8px; padding-bottom: 10px; margin-bottom: 10px; }
  .gprogress { order: 3; flex-basis: 100%; min-width: 0; }
  .tools { flex-wrap: wrap; gap: 6px; }
  .btn { padding: 9px 11px; }
  .toolbar { gap: 8px; }
  .search { min-width: 130px; }
  #personFilter { max-width: 130px; padding: 9px 8px; }
  .line-tab { padding: 8px 10px; }
  .st-row { flex-wrap: wrap; padding: 12px; row-gap: 8px; }
  .st-meta { display: none; }
  .status-select, .t-status { padding: 8px 10px; }
  .task-main { flex-wrap: wrap; row-gap: 8px; }
  .t-fields { flex-direction: column; align-items: stretch; }
  .t-fields .f-spacer { display: none; }
  .modal { max-width: 100%; }
  .ft-row { padding: 14px 13px; }
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 9px; padding: 10px 16px;
  box-shadow: var(--shadow); opacity: 0; transition: .25s; pointer-events: none; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
