:root {
  color-scheme: dark;
  --bg: #070908;
  --panel: #101411;
  --panel-2: #151a16;
  --line: #283029;
  --line-soft: #202621;
  --text: #f3f6f3;
  --muted: #96a098;
  --green: #8dd229;
  --amber: #ffba49;
  --red: #ff655f;
  --blue: #63a7ff;
  --violet: #b98bff;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; display: flex; flex-direction: column; background: radial-gradient(circle at 12% -10%, #152016 0, var(--bg) 34%); color: var(--text); font: 14px/1.5 "Roboto", "Helvetica Neue", Arial, ui-sans-serif, system-ui, sans-serif; }
button, select, input, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

.topbar { height: 50px; flex: 0 0 50px; padding: 0 20px; border-bottom: 1px solid var(--line); background: rgba(7,9,8,.94); backdrop-filter: blur(16px); display: flex; align-items: center; justify-content: space-between; z-index: 10; }
.brand-link { display: flex; align-items: center; gap: 10px; }
/* Brand mark holds the QUALQEM logo; a light plate keeps the navy/green
   artwork legible on the dark topbar (navy is ~1.6:1 on the raw background). */
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #fff; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); flex: 0 0 auto; }
.brand-mark img { display: block; width: 28px; height: 28px; object-fit: contain; }
.brand { font-weight: 850; letter-spacing: .08em; }
.product { color: var(--muted); }
.top-actions { display: flex; gap: 12px; align-items: center; }
.status { color: var(--muted); font-size: 12px; }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); margin-right: 7px; }
.status.online::before { background: var(--green); }
button.primary { background: var(--green); color: #0b1206; border: 0; border-radius: 9px; padding: 9px 14px; font-weight: 750; cursor: pointer; }
button.primary:disabled { opacity: .55; cursor: wait; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 9px 14px; font-weight: 650; cursor: pointer; }
button.ghost:hover { border-color: var(--muted); }
button.danger { background: #3a1513; color: #ff9d99; border: 1px solid #64312e; border-radius: 9px; padding: 9px 14px; font-weight: 650; cursor: pointer; }
button.mini { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.spacer { flex: 1; }

.app-shell { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 236px 1fr; overflow: hidden; }
.sidenav { height: 100%; overflow-y: auto; overflow-x: hidden; border-right: 1px solid var(--line); padding: 18px 12px; background: rgba(9,12,10,.6); }
.nav-group-label { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; padding: 16px 10px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 9px; color: #cdd4ce; cursor: pointer; font-weight: 600; }
.nav-link:hover { background: var(--panel); color: var(--text); }
.nav-link.active { background: linear-gradient(120deg, #1d2a17, #16201a); color: var(--text); box-shadow: inset 0 0 0 1px #2f4024; }
.nav-link .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.nav-link.active .dot { background: var(--green); }
.nav-project { margin-top: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.nav-project .name { font-weight: 750; font-size: 13px; margin-bottom: 2px; }
.nav-project .code { color: var(--muted); font-size: 11px; }

.view { height: 100%; overflow-y: auto; overflow-x: hidden; width: 100%; margin: 0 auto; padding: 26px 30px 40px; max-width: 1520px; }
.view-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.view-head h1 { margin: 4px 0 0; font-size: clamp(22px, 2.4vw, 32px); letter-spacing: -.03em; }
.eyebrow { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .15em; margin: 0; text-transform: uppercase; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }

.panel { background: rgba(16,20,17,.94); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-bottom: 14px; }
.panel-heading { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 16px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: linear-gradient(150deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { margin-top: 12px; font-size: 26px; font-weight: 800; letter-spacing: -.03em; }
.kpi.alert .value { color: var(--red); }

.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .cols-2, .cols-3 { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; text-align: left; white-space: nowrap; }
th, td { padding: 10px 10px; border-bottom: 1px solid #232a24; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.badge { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; font-size: 11px; white-space: nowrap; }
.badge.good { color: var(--green); border-color: #33501e; }
.badge.warn { color: var(--amber); border-color: #5c4620; }
.badge.bad { color: var(--red); border-color: #64312e; }
.badge.crit { color: #fff; background: var(--red); border-color: var(--red); }
.empty { color: var(--muted); border: 1px dashed var(--line); border-radius: 9px; padding: 26px; text-align: center; }

.insight { border-left: 3px solid var(--green); background: var(--panel-2); border-radius: 0 9px 9px 0; padding: 12px 14px; margin-bottom: 10px; }
.insight.warning { border-color: var(--amber); }
.insight.danger { border-color: var(--red); }
.insight strong { display: block; margin-bottom: 3px; }

/* Gantt */
.gantt-wrap { overflow: auto; max-height: calc(100vh - 268px); border: 1px solid var(--line); border-radius: 12px; }
/* Plan tab: the Gantt is the only scroll area (no outer scrollbar). */
.view.view-plan { display: flex; flex-direction: column; overflow: hidden; padding: 8px 24px 20px; }
.view.view-plan .view-head { flex: 0 0 auto; align-items: center; margin-bottom: 6px; gap: 10px; }
.view.view-plan .view-head h1 { font-size: 17px; margin-top: 0; }
.view.view-plan .view-head .eyebrow { display: none; }
.view.view-plan .toolbar { gap: 6px; }
.view.view-plan .toolbar button, .view.view-plan .toolbar select, .view.view-plan .toolbar a.ghost { padding: 4px 9px; font-size: 12px; }
.view.view-plan .panel { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; padding: 8px; }
.view.view-plan .panel-heading, .view.view-plan .toolbar { flex: 0 0 auto; }
.view.view-plan .gantt-wrap { flex: 1 1 auto; min-height: 0; max-height: none; }
.gantt-grid { min-width: 900px; position: relative; }
.dep-overlay { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 1; overflow: visible; }
.dep-link { fill: none; stroke: rgba(124, 138, 132, 0.42); stroke-width: 1; }
.dep-link.critical { stroke: rgba(255, 101, 95, 0.9); stroke-width: 1.4; }
.gantt-row { display: grid; grid-template-columns: var(--gw, 72px) var(--gt, 190px) var(--go, 120px) 1fr; border-top: 1px solid var(--line-soft); }
.col-resize { position: absolute; right: -4px; top: 0; width: 9px; height: 100%; cursor: col-resize; z-index: 7; }
.col-resize::after { content: ""; position: absolute; left: 4px; top: 3px; bottom: 3px; width: 1px; background: var(--line); }
.col-resize:hover::after { background: var(--green); }
.gantt-cell.gantt-sticky { position: sticky; background: var(--panel); z-index: 3; }
.gantt-cell.gantt-wbs { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-cell.gantt-owner-cell { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-cell.gantt-num-cell { text-align: right; font-variant-numeric: tabular-nums; }
.gantt-cell.gantt-mode-cell { padding-top: 0; padding-bottom: 0; }
.mode-toggle { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); cursor: pointer; }
.mode-toggle.manual { color: var(--amber); border-color: #5c4620; }
.mode-toggle:hover { border-color: var(--green); color: var(--text); }
.gantt-row.selected .gantt-cell.gantt-sticky { background: #182016; }
.gantt-row.link-source .gantt-cell.gantt-sticky { background: #1c2a1a; }
.gantt-row.head { z-index: 5; }
.gantt-row.head .gantt-cell.gantt-sticky { z-index: 6; background: var(--panel-2); }

/* Report header brand */
.report-title { display: flex; align-items: center; gap: 10px; }
.report-logo { width: 36px; height: 36px; object-fit: contain; flex: 0 0 auto; background: #fff; padding: 3px; border-radius: 8px; box-sizing: content-box; }
.gantt-row.head { border-top: 0; background: var(--panel-2); position: sticky; top: 0; z-index: 2; }
.gantt-cell { padding: 1px 10px; }
.gantt-task { display: flex; flex-direction: row; align-items: baseline; gap: 8px; cursor: pointer; min-width: 0; }
.gantt-task .t-name { font-weight: 620; font-size: 12px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gantt-task .t-name.summary { font-weight: 750; color: #e9efe9; }
.gantt-task .t-meta { color: var(--muted); font-size: 10px; line-height: 1.2; display: flex; gap: 8px; white-space: nowrap; overflow: hidden; flex: 0 1 auto; }
.gantt-track { position: relative; min-height: 20px; }
.gantt-cell.gantt-axis { position: relative; height: 48px; padding: 0; overflow: hidden; }
.axis-months { position: absolute; top: 0; left: 0; right: 0; height: 24px; border-bottom: 1px solid var(--line-soft); }
.axis-months span { position: absolute; top: 4px; padding-left: 7px; border-left: 1px solid var(--line); font-size: 11px; font-weight: 650; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.axis-ticks { position: absolute; top: 24px; left: 0; right: 0; bottom: 0; }
.axis-ticks span { position: absolute; top: 5px; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.axis-ticks span.major { color: #c3ccc5; font-weight: 650; }
.grid-overlay { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 0; overflow: visible; }
.grid-line { stroke: #1c231e; stroke-width: 1; shape-rendering: crispEdges; }
.grid-line.major { stroke: #2a332c; }
.gantt-bar { position: absolute; height: 11px; top: 4px; border-radius: 4px; background: var(--blue); box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset; min-width: 4px; cursor: grab; }
.gantt-bar:active { cursor: grabbing; }
.gantt-resize { position: absolute; right: -3px; top: 0; width: 9px; height: 100%; cursor: ew-resize; }
.gantt-resize::after { content: ""; position: absolute; right: 3px; top: 2px; bottom: 2px; width: 2px; background: rgba(255,255,255,.5); border-radius: 2px; }
.gantt-row.link-source { background: #1c2a1a; box-shadow: inset 3px 0 0 var(--green); }
.gantt-bar.critical { background: var(--red); }
.gantt-bar.done { background: var(--green); }
.gantt-bar.milestone { background: var(--amber); width: 14px !important; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); border-radius: 0; }
.gantt-progress { height: 100%; background: rgba(0,0,0,.22); border-radius: inherit; }
.gantt-row.selected { background: #182016; }

.inspector { position: fixed; top: 62px; right: 0; width: min(440px, 96vw); height: calc(100vh - 62px); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -20px 0 60px rgba(0,0,0,.5); transform: translateX(100%); transition: transform .18s ease; z-index: 9; display: flex; flex-direction: column; }
.inspector.open { transform: translateX(0); }
.inspector-head { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: start; }
.inspector-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.inspector-section { margin-bottom: 18px; }
.inspector-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 10px; }
.field-line { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.field-line .k { color: var(--muted); font-size: 12px; }
.field-line .v { text-align: right; }

/* Forms in modal */
.modal { width: min(760px, 95vw); max-height: 90vh; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 0; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
.modal::backdrop { background: rgba(3,5,4,.72); backdrop-filter: blur(3px); }
.modal form { display: flex; flex-direction: column; max-height: 90vh; }
.modal-head { display: flex; justify-content: space-between; align-items: start; padding: 20px 22px 12px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 19px; margin: 3px 0 0; }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 15px; padding: 18px 22px; overflow-y: auto; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field[hidden] { display: none !important; }
.field.full { grid-column: 1 / -1; }
.field label { color: var(--muted); font-size: 12px; font-weight: 650; }
.field .req { color: var(--red); }
.field input, .field select, .field textarea { width: 100%; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--green); }
.field textarea { resize: vertical; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: auto; }
.field.check label { order: 2; color: var(--text); }
.field .help { color: var(--muted); font-size: 11px; }
.form-error { margin: 14px 22px 0; padding: 10px 12px; border-radius: 9px; background: #2a1312; border: 1px solid #64312e; color: #ffb3af; font-size: 13px; }
.modal-foot { display: flex; align-items: center; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); }
input, select, textarea { color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; background: var(--panel-2); color: var(--text); border: 1px solid var(--green); border-radius: 10px; padding: 12px 17px; font-weight: 650; box-shadow: 0 16px 40px rgba(0,0,0,.5); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateY(0); }

.context-menu { position: fixed; z-index: 40; min-width: 210px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 5px; box-shadow: 0 16px 44px rgba(0,0,0,.6); }
.ctx-item { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: var(--text); padding: 7px 11px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.ctx-item:hover { background: #1d2a17; }
.ctx-item.danger { color: #ff9d99; }
.ctx-item.danger:hover { background: #2a1312; }
.ctx-sep { height: 1px; background: var(--line); margin: 5px 4px; }

tr.selected, .gantt-row.selected { background: #182016; }
.net-node:hover rect { filter: brightness(1.25); }

.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { min-height: 92px; border: 1px solid var(--line); border-radius: 9px; padding: 6px; background: var(--panel-2); }
.cal-cell.empty-cell { background: transparent; border-color: transparent; }
.cal-day { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.cal-chip { display: block; font-size: 11px; padding: 2px 6px; border-radius: 6px; background: #1d2a3a; color: #cfe3ff; margin-bottom: 3px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-chip.critical { background: #3a1513; color: #ffb3af; }

@media (max-width: 860px) { .cal-cell { min-height: 66px; } }

@media print {
  :root { --bg: #fff; --panel: #fff; --panel-2: #f6f7f6; --line: #c8cec9; --line-soft: #e3e6e3; --text: #101410; --muted: #53605a; --green: #2e7d32; --red: #c62828; --blue: #1565c0; --amber: #a86400; }
  html, body { height: auto; overflow: visible; }
  body { background: #fff; display: block; }
  .topbar, .sidenav, .view-head, .toolbar, .inspector, .modal, .toast, .create-panel, .gantt-wrap { display: none !important; }
  .app-shell { display: block; height: auto; overflow: visible; }
  .view { padding: 0; max-width: none; height: auto; overflow: visible; }
  .panel { break-inside: avoid; box-shadow: none; margin-bottom: 10px; }
  .print-area .panel { border: 1px solid #c8cec9; }
  th, td { border-bottom: 1px solid #d5dad6; }
  .kpi { border: 1px solid #c8cec9; }
}

.form-inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.form-inline .field { min-width: 150px; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidenav { height: auto; max-height: 54px; overflow-x: auto; overflow-y: hidden; display: flex; gap: 6px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-group-label, .nav-project { display: none; }
  .view { padding: 18px 14px 30px; }
  .product, .status { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .gantt-wrap { max-height: calc(100vh - 210px); }
}

/* --- Sign-in / identity ------------------------------------------------ */
.whoami { color: var(--muted); font-size: 12px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-screen[hidden] { display: none !important; }
.auth-screen { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 50% 0%, #16241a 0, rgba(4,6,5,.97) 55%); backdrop-filter: blur(4px); }
body.auth-locked .app-shell, body.auth-locked .topbar { display: none !important; }
.auth-card { width: min(380px, 94vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 26px 24px; box-shadow: 0 30px 80px rgba(0,0,0,.65); display: flex; flex-direction: column; gap: 12px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.auth-brand strong { display: block; letter-spacing: .08em; font-weight: 850; }
.auth-brand span { display: block; color: var(--muted); font-size: 12px; }
.auth-card h1 { margin: 4px 0 0; font-size: 20px; }
.auth-card .field { margin: 0; }
.auth-card button { margin-top: 6px; }
.user-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.user-form .field { min-width: 170px; }
.badge-x { background: transparent; border: 0; color: inherit; cursor: pointer; padding: 0 0 0 4px; opacity: .7; }
.badge-x:hover { opacity: 1; color: var(--red); }

/* Telegram linking row: keep the Link button visible next to compact controls */
#view select[data-tg-project] { max-width: 190px; }
#view input[data-tg-thread] { width: 150px; }
#view .row-actions { flex-wrap: wrap; align-items: center; }
#view .row-actions > select,
#view .row-actions > input { flex: 0 0 auto; }

/* Column chooser, status bar, view switcher */
.col-chooser { position: relative; }
.col-chooser > summary { list-style: none; cursor: pointer; border: 1px solid var(--line); border-radius: 9px; padding: 9px 14px; font-weight: 650; }
.col-chooser > summary::-webkit-details-marker { display: none; }
.col-chooser[open] > summary { border-color: var(--green); color: var(--green); }
.col-chooser-panel { position: absolute; z-index: 12; top: calc(100% + 6px); left: 0; min-width: 190px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: 0 16px 40px rgba(0,0,0,.55); }
.col-chooser-panel label { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.col-chooser-panel label:hover { background: #1d2a17; }
.gantt-statusbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border-top: 1px solid var(--line); margin-top: 6px; padding: 6px 4px 0; font-size: 12px; color: var(--muted); }
.view-switch { display: flex; gap: 4px; margin-left: auto; }
.view-switch a { border: 1px solid var(--line); border-radius: 7px; padding: 2px 9px; color: var(--muted); }
.view-switch a:hover { color: var(--text); border-color: var(--muted); }
.view-switch a.active { color: var(--text); border-color: var(--green); background: #182016; }
.axis-ticks span:first-child { transform: none; }
.ts-group { display: inline-flex; align-items: center; gap: 4px; }
.ts-group .muted { margin-right: 2px; }
.ts-group button.active { border-color: var(--green); color: var(--green); background: #182016; }

.ts-group .ts-now { min-width: 96px; }
.ts-group button[data-timescale-step] { width: 28px; font-weight: 800; }

/* Inline rename in the task grid */
.t-rename { width: 100%; font: inherit; font-size: 12px; font-weight: 620; color: var(--text);
  background: var(--bg); border: 1px solid var(--green); border-radius: 6px; padding: 2px 6px; }
