:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel-2: #1c242d;
  --border: #2a3540;
  --border-strong: #3a4757;
  --text: #e6edf3;
  --text-muted: #8b98a8;
  --text-dim: #5b6774;
  --accent: #4da3ff;
  --today: #ff6b35;

  /* Shop colors (accessible on dark bg) */
  --fsj: #38b2ac;       /* teal */
  --fsj-soft: rgba(56, 178, 172, 0.18);
  --wcrt: #d69e2e;      /* amber */
  --wcrt-soft: rgba(214, 158, 46, 0.18);
  --gp: #4a7fea;        /* blue */
  --gp-soft: rgba(74, 127, 234, 0.18);

  --row-h: 32px;
  --label-w: 160px;
  --day-w: 6px;         /* pixels per day; adjustable */

  --danger: #e53e3e;
  --success: #48bb78;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 13px;
  height: 100%;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--accent); }
.brand h1 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.brand .subtitle { color: var(--text-muted); font-size: 12px; }

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.legend { display: flex; gap: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; }
.swatch {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
}
.swatch-fsj { background: var(--fsj); }
.swatch-wcrt { background: var(--wcrt); }
.swatch-gp { background: var(--gp); }
.swatch-today { background: var(--today); }

.filter-group { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; }
select, input[type="date"], input[type="text"], textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 12px;
}
select:focus, input:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease;
}
.btn:hover { background: #263040; }
.btn-primary { background: var(--accent); color: #061423; border-color: var(--accent); }
.btn-primary:hover { background: #6fb6ff; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #c53030; }

.hint {
  padding: 6px 16px;
  background: var(--panel-2);
  color: var(--text-muted);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.hint strong { color: var(--text); }

/* Gantt */
.gantt-wrap {
  height: calc(100vh - 98px);
  overflow: hidden;
  position: relative;
}
.gantt {
  display: flex;
  flex-direction: row;
  height: 100%;
  position: relative;
}

/* Fixed labels column */
.labels-col {
  width: var(--label-w);
  min-width: var(--label-w);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border-strong);
  z-index: 10;
}
.labels-scroll {
  flex: 1;
  overflow: hidden;  /* synced with rows-scroll via JS */
  position: relative;
}
.labels-scroll .labels-inner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  will-change: transform;
}
.labels-scroll .cell-label {
  width: 100%;
  min-width: 0;
  border-right: none;
}

/* Scrollable timeline column */
.timeline-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.timeline-header-wrap {
  height: 52px;
  overflow: hidden;
  background: var(--panel);
  border-bottom: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  min-height: var(--row-h);
  height: var(--row-h);
}

.cell-label {
  width: var(--label-w);
  min-width: var(--label-w);
  padding: 0 12px;
  display: flex;
  align-items: center;
  background: var(--panel);
  font-size: 12px;
  color: var(--text);
  gap: 8px;
  height: var(--row-h);
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}
.header-label {
  height: 52px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-strong);
  background: var(--panel);
}
.turbine-tag {
  display: inline-block;
  width: 6px;
  height: 20px;
  border-radius: 2px;
  flex-shrink: 0;
}

.timeline-header {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: relative;
}
.months-row, .weeks-row {
  display: flex;
  position: relative;
}
.months-row { height: 28px; border-bottom: 1px solid var(--border); }
.weeks-row { height: 24px; }

.month-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border-strong);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.month-cell.alt { background: var(--panel-2); }

.week-cell {
  border-right: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.rows-scroll {
  overflow: auto;
  flex: 1;
  position: relative;
}
.labels-scroll .cell-label:nth-child(even) {
  background: #171e25;
}

.timeline {
  position: relative;
  flex-shrink: 0;
  height: var(--row-h);
  background-image:
    linear-gradient(to right, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: calc(var(--day-w) * 7) 100%;
}

.row:nth-child(even) .timeline { background-color: rgba(255, 255, 255, 0.012); }
.row:nth-child(even) .cell-label { background: #171e25; }

/* Today vertical line */
.today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--today);
  z-index: 15;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(255, 107, 53, 0.4);
}
.today-line::before {
  content: 'TODAY';
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--today);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 2px;
  letter-spacing: 0.05em;
}

/* Month dividers in rows area */
.month-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-strong);
  pointer-events: none;
  z-index: 1;
}

/* Work bars */
.bar {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 3px;
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 500;
  color: white;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: box-shadow 0.1s ease, transform 0.05s ease;
  z-index: 2;
  user-select: none;
  border: 1px solid transparent;
}
.bar:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.3);
  z-index: 3;
}
.bar.dragging { cursor: grabbing; opacity: 0.85; z-index: 10; }
.bar.has-comment::after {
  content: '●';
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 9px;
  color: rgba(255,255,255,0.9);
}

.bar-fsj { background: var(--fsj); }
.bar-wcrt { background: var(--wcrt); color: #1a1408; }
.bar-gp { background: var(--gp); color: #ffffff; }
.bar.status-complete { opacity: 0.55; }
.bar.status-on-hold { background-image: repeating-linear-gradient(45deg, rgba(0,0,0,0.15) 0 4px, transparent 4px 8px); }
.bar.status-in-progress { border-color: rgba(255,255,255,0.5); }

.bar-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: ew-resize;
  z-index: 4;
}
.bar-handle.left { left: 0; }
.bar-handle.right { right: 0; }
.bar-handle:hover { background: rgba(255,255,255,0.25); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0;
  width: 520px;
  max-width: 92vw;
  max-height: 92vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal h2 { margin: 0; font-size: 15px; font-weight: 600; }
.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.close-btn:hover { color: var(--text); }
#barForm { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
#barForm label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); font-weight: 500; }
#barForm input, #barForm select, #barForm textarea {
  font-size: 13px;
  padding: 7px 10px;
}
#barForm textarea { resize: vertical; min-height: 80px; font-family: inherit; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-footer {
  display: flex;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 14px;
  align-items: center;
}
.modal-footer .spacer { flex: 1; }

/* Tooltip */
.tooltip {
  position: fixed;
  background: #0a0e13;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  max-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  pointer-events: none;
  z-index: 50;
  line-height: 1.5;
}
.tooltip[hidden] { display: none; }
.tooltip .tt-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.tooltip .tt-location { color: var(--accent); font-size: 12px; margin-bottom: 6px; }
.tooltip .tt-meta { color: var(--text-muted); font-size: 11px; margin-bottom: 6px; }
.tooltip .tt-comment { color: var(--text); white-space: pre-wrap; border-top: 1px solid var(--border); padding-top: 6px; margin-top: 4px; }
.tooltip .tt-comment.empty { color: var(--text-dim); font-style: italic; }

/* Turbine label — clickable */
.cell-label.clickable {
  cursor: pointer;
  transition: background 0.1s ease;
  position: relative;
}
.cell-label.clickable:hover {
  background: #1f2832 !important;
}
.cell-label.clickable:hover .turbine-name { color: var(--accent); }
/* If a manufacturer color is set inline on the name, it overrides the hover color */
.cell-label.clickable:hover .turbine-name[style*="color"] { filter: brightness(1.15); }
.cell-label .turbine-name { transition: color 0.1s ease, filter 0.1s ease; font-weight: 600; }
.cell-label .turbine-specs {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70px;
  text-align: right;
}
.cell-label .turbine-specs.has-spec { color: var(--text-muted); }

/* Side panel */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--border-strong);
  box-shadow: -8px 0 24px rgba(0,0,0,0.5);
  z-index: 80;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.18s ease-out;
}
.side-panel[hidden] { display: none; }
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
.side-panel header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.side-panel h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.01em;
}
#spForm {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 1;
}
#spForm label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
#spForm select, #spForm textarea {
  font-size: 13px;
  padding: 7px 10px;
}
#spForm textarea { resize: vertical; min-height: 70px; font-family: inherit; }
.side-panel-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 14px;
}

/* Scrollbar styling */
.rows-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.rows-scroll::-webkit-scrollbar-track { background: var(--bg); }
.rows-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
.rows-scroll::-webkit-scrollbar-thumb:hover { background: #4a5766; }

/* ---------- Auth & permissions UI ---------- */

/* Top-bar identity & role pill */
.user-ident {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
  margin-right: 4px;
  white-space: nowrap;
}
.user-ident strong { color: var(--text); font-weight: 600; }
.controls-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}
.role-pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 4px;
  vertical-align: 1px;
  border: 1px solid transparent;
}
.role-pill.role-admin {
  background: rgba(214,158,46,0.15);
  color: #f6d77a;
  border-color: rgba(214,158,46,0.4);
}
.role-pill.role-editor {
  background: rgba(56,178,172,0.15);
  color: var(--accent);
  border-color: rgba(56,178,172,0.4);
}
.role-pill.role-viewer {
  background: rgba(150,160,170,0.15);
  color: #c5c8cc;
  border-color: rgba(150,160,170,0.4);
}

/* View-only mode visual cue */
body.view-only .timeline { cursor: default; }
body.view-only .bar { cursor: pointer; }
body.view-only .bar-handle { cursor: pointer !important; }
body.view-only .hint::after {
  content: " — Viewer mode (read-only)";
  color: var(--wcrt);
  font-weight: 600;
}

/* ---------- Sign-in overlay ---------- */
.signin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 18, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}
.signin-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.signin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.signin-logo {
  color: var(--accent);
  margin-bottom: 12px;
}
.signin-card h2 {
  margin: 0 0 8px 0;
  font-size: 20px;
  color: var(--text);
}
.signin-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 20px 0;
  line-height: 1.5;
}
.signin-hint strong { color: var(--text); }
#signInForm label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
#signInForm input,
#signInForm select {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  text-transform: none;
  letter-spacing: normal;
  font-weight: normal;
  box-sizing: border-box;
}
#signInForm input:focus,
#signInForm select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56,178,172,0.15);
}
.signin-error {
  min-height: 18px;
  font-size: 12px;
  color: #ff7a7a;
  margin: -6px 0 12px 0;
}
.signin-btn {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
}

body.locked { overflow: hidden; }

/* ---------- Modal: wide variant for users / audit ---------- */
.modal.modal-wide {
  max-width: 760px;
  width: 90vw;
}

/* ---------- Users management ---------- */
.users-body { padding: 0 4px 4px; }
.users-hint {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(56,178,172,0.06);
  padding: 10px 14px;
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  margin: 0 0 16px 0;
  line-height: 1.6;
}
.users-hint strong { color: var(--text); }

.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 16px;
}
.users-table thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.users-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #1a2129;
  vertical-align: middle;
}
.users-table input,
.users-table select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
}
.users-table input:focus,
.users-table select:focus {
  outline: none;
  border-color: var(--accent);
}
.users-table input:disabled,
.users-table select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

.add-user-row h3 {
  font-size: 13px;
  margin: 16px 0 10px 0;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.add-user-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.add-user-grid input,
.add-user-grid select {
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
}
.add-user-grid input:focus,
.add-user-grid select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------- Audit log ---------- */
.audit-body {
  max-height: 60vh;
  overflow-y: auto;
  padding: 0 4px;
}
.audit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.audit-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.audit-table td {
  padding: 7px 10px;
  border-bottom: 1px solid #1a2129;
  vertical-align: top;
}
.audit-time {
  white-space: nowrap;
  color: var(--text-muted);
  font-feature-settings: "tnum";
}
.audit-details {
  color: var(--text-muted);
  font-size: 11.5px;
  word-break: break-word;
}
.audit-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 30px !important;
  font-style: italic;
}
.audit-count {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
  margin-right: 12px;
}

/* ---------- Last-edit footer in bar modal ---------- */
.last-edit-info {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  padding: 8px 0 4px 0;
  border-top: 1px solid #1a2129;
  margin-top: 6px;
}

/* Tooltip last-edit line */
.tt-edited {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 10.5px;
  color: var(--text-dim);
}
.tt-edited strong { color: var(--text-muted); }

/* Disabled buttons in view-only mode */
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
