@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap');

:root {
  --bg: #0a0a0a;
  --surface: #171717;
  --surface-alt: #262626;
  --border: #262626;
  --border-light: #404040;
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --text-dim: #737373;
  --primary: #663399;
  --primary-dark: #52277a;
  --primary-soft: rgba(102, 51, 153, 0.22);
  --danger: #f87171;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --success: #4ade80;
  --success-soft: rgba(34, 197, 94, 0.16);
  --warn: #fbbf24;
  --warn-soft: rgba(217, 119, 6, 0.18);
  --radius: 8px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

/* --- Stage theming: re-colors the project page based on its current stage
   so it's always obvious which stage you're looking at. --- */
body[data-stage="quoting"] { --primary: #f59e0b; --primary-dark: #d97706; --primary-soft: rgba(245, 158, 11, 0.2); }
body[data-stage="planning"] { --primary: #3b82f6; --primary-dark: #2563eb; --primary-soft: rgba(59, 130, 246, 0.2); }
body[data-stage="execution"] { --primary: #22c55e; --primary-dark: #16a34a; --primary-soft: rgba(34, 197, 94, 0.2); }
body[data-stage="post"] { --primary: #a855f7; --primary-dark: #9333ea; --primary-soft: rgba(168, 85, 247, 0.2); }
body[data-stage] .app-header { border-bottom-color: var(--primary); border-bottom-width: 2px; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--surface-alt); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

a { color: var(--primary); text-decoration: none; }

h1, h2, h3 { font-weight: 700; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 15px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 13px;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: var(--surface-alt); color: var(--text); border-color: var(--border-light); }
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fdfcff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fdfcff; }
.btn-danger { color: var(--danger); border-color: transparent; background: var(--danger-soft); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.28); color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

input[type="text"], input[type="password"], input[type="email"], input[type="tel"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field { margin-bottom: 14px; }

/* --- App shell --- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header .brand {
  font-weight: 800;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.app-header nav {
  display: flex;
  gap: 4px;
}
.app-header nav a {
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s;
}
.app-header nav a.active, .app-header nav a:hover { background: var(--primary-soft); color: var(--text); }
.app-header .user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.page-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-title h1 { font-size: 22px; margin: 0; font-weight: 800; color: var(--text); }

/* --- Login --- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; font-weight: 800; }
.login-card p.sub { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }
.error-msg {
  background: var(--danger-soft);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}
.notice-msg {
  background: var(--primary-soft);
  color: #d5c2ea;
  border: 1px solid rgba(102, 51, 153, 0.4);
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
}

/* --- Project cards (dashboard) --- */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.project-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow 0.15s, transform 0.15s;
}
.project-card:hover { box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); transform: translateY(-1px); }
.project-card .num { font-size: 11px; color: var(--text-dim); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.project-card h3 { margin: 0; font-size: 17px; font-weight: 700; color: var(--text); }
.project-card .loc { font-size: 13px; color: var(--text-muted); }

.stage-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: fit-content;
}
.stage-quoting { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.stage-planning { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }
.stage-execution { background: rgba(34, 197, 94, 0.18); color: #86efac; }
.stage-post { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }

.progress-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s;
}
.progress-label { font-size: 12px; color: var(--text-muted); }

.stage-stepper {
  display: flex;
  gap: 4px;
}
.stage-stepper .step {
  flex: 1;
  height: 5px;
  border-radius: 999px;
  background: var(--surface-alt);
}
.stage-stepper .step.done { background: var(--primary); }
.stage-stepper .step.current { background: var(--primary); opacity: 0.5; }

/* --- Tables (task boards) --- */
.board-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 14px;
  padding-bottom: 4px;
}
.board-tabs button {
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  white-space: nowrap;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.board-tabs button:hover { color: var(--text); border-color: var(--border-light); }
.board-tabs button.active { background: var(--primary); color: #fdfcff; border-color: var(--primary); }

.stage-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
  padding-bottom: 4px;
}
.stage-tab {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.stage-tab:hover { color: var(--text); border-color: var(--border-light); }
.stage-tab .chip { background: var(--surface-alt); }
.stage-tab-quoting.active { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border-color: rgba(245, 158, 11, 0.4); }
.stage-tab-planning.active { background: rgba(59, 130, 246, 0.18); color: #93c5fd; border-color: rgba(59, 130, 246, 0.4); }
.stage-tab-execution.active { background: rgba(34, 197, 94, 0.18); color: #86efac; border-color: rgba(34, 197, 94, 0.4); }
.stage-tab-post.active { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; border-color: rgba(168, 85, 247, 0.4); }
.stage-tab-none.active { background: var(--surface-alt); color: var(--text); border-color: var(--border-light); }
.stage-tab.active .chip { background: rgba(255, 255, 255, 0.12); color: inherit; }

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
table.task-table {
  border-collapse: collapse;
  width: 100%;
  table-layout: auto;
}
table.task-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--text-dim);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.task-table th:first-child, table.task-table td:first-child {
  min-width: 170px;
}

/* Desktop: every column has a user-draggable width (see .col-resize-handle
   and initColumnResize() in project.js), remembered per board. Fixed table
   layout means the header row's widths are authoritative, so dragging a
   handle resizes exactly that column. Cell text still wraps (via
   auto-growing textareas) instead of ever being cut off — if you make the
   columns wider than the screen, the board scrolls horizontally, which is
   now something you control on purpose rather than something forced on you. */
@media (min-width: 861px) {
  .table-wrap { overflow-x: auto; }
  table.task-table { table-layout: fixed; }
  table.task-table th {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    position: relative;
    box-sizing: border-box;
  }
  table.task-table td {
    overflow: visible;
    box-sizing: border-box;
  }
  table.task-table td select {
    min-width: 0;
    width: 100%;
  }
  table.task-table td input {
    min-width: 0;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  table.task-table td:first-child input {
    min-width: 0;
  }
  table.task-table td textarea.cell-autosize {
    min-width: 0;
    width: 100%;
  }
  .col-resize-handle {
    position: absolute;
    top: 5px;
    bottom: 5px;
    right: 0;
    width: 10px;
    cursor: col-resize;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .col-resize-handle::after {
    content: '';
    width: 4px;
    height: 100%;
    border-radius: 2px;
    background: var(--text-dim);
    opacity: 0.9;
    transition: background 0.12s ease, opacity 0.12s ease, width 0.12s ease;
  }
  .col-resize-handle:hover::after, .col-resize-handle.resizing::after {
    background: var(--primary);
    opacity: 1;
    width: 5px;
  }
}
table.task-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.task-table tbody tr { transition: background 0.1s; }
table.task-table tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
table.task-table tr:last-child td { border-bottom: none; }
table.task-table td input, table.task-table td select, table.task-table td textarea.cell-autosize {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 6px 6px;
  border-radius: 6px;
  min-width: 88px;
  width: auto;
}
table.task-table td:first-child input {
  min-width: 150px;
  width: 100%;
}
table.task-table .task-stage-select {
  min-width: 96px;
}
table.task-table td input[type="checkbox"] {
  min-width: 0;
  width: auto;
}
/* Auto-growing text cells (task title + free-text columns): behave like a
   normal single-line field but wrap and grow taller instead of clipping
   content when the text is longer than the column is wide. */
table.task-table td textarea.cell-autosize {
  display: block;
  resize: none;
  overflow: hidden;
  font: inherit;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}
table.task-table td:first-child textarea.task-title {
  min-width: 150px;
  width: 100%;
  font-weight: 700;
}
table.task-table td input:hover, table.task-table td select:hover, table.task-table td textarea.cell-autosize:hover { border-color: var(--border); }
table.task-table td input:focus, table.task-table td select:focus, table.task-table td textarea.cell-autosize:focus { border-color: var(--primary); background: var(--surface); box-shadow: none; }

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: white;
  border: none;
}

.task-done-row { opacity: 0.5; }
.task-done-row td:first-child { text-decoration: line-through; }

/* --- Phases / info panel --- */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
  overflow: hidden;
}
.card h4 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  font-weight: 800;
}

.phase-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1fr) 22px;
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  min-width: 0;
}
.phase-row label.phase-name { margin: 0; font-size: 13px; color: var(--text); font-weight: 700; text-transform: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phase-row input[type="date"] {
  min-width: 0;
  width: 100%;
  padding: 8px 4px;
  font-size: 13px;
}
.phase-row .del-phase {
  padding: 2px;
  font-size: 11px;
  line-height: 1;
  min-width: 0;
}

/* --- Clients / Additional Scope / Status Checklist --- */
#clients-card-area, #scope-card-area {
  margin-bottom: 16px;
}
.client-list { margin-bottom: 10px; }
.client-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr) minmax(0, 1fr) 22px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.client-row input { min-width: 0; width: 100%; }
.client-row .del-client { padding: 2px; font-size: 11px; line-height: 1; min-width: 0; }

.checklist-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.checklist-tab {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
}
.checklist-tab:hover { color: var(--text); border-color: var(--border-light); }
.checklist-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.checklist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.checklist-row:last-child { border-bottom: none; }
.checklist-label {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  flex: 1;
  min-width: 0;
}
/* Higher-specificity element+class selectors here so these beat the global
   `input[type=...], select { width: 100% }` base rule — otherwise every one
   of these controls stretches to fill the row and overlaps its own label. */
select.checklist-status-select {
  flex-shrink: 0;
  width: auto;
  min-width: 170px;
  border: none;
  font-size: 12px;
}
input.checklist-date-input, input.checklist-text-input {
  flex-shrink: 0;
  width: 220px;
  max-width: 100%;
}

.subhire-block {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.subhire-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 190px 22px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.subhire-row input { min-width: 0; width: 100%; }
.subhire-row .del-subhire { padding: 2px; font-size: 11px; line-height: 1; min-width: 0; }

/* --- Dropdown/status option editor (Add/Edit Column modal) --- */
.option-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.option-row .opt-label { flex: 1; }
.option-row .opt-color { width: 36px; height: 34px; padding: 2px; flex-shrink: 0; background: var(--surface); border: 1px solid var(--border); }
.option-row .opt-done {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: none;
  flex-shrink: 0;
  white-space: nowrap;
}
.option-row .opt-done input { width: auto; }
.option-row .remove-option-row { flex-shrink: 0; padding: 6px 9px; }

.map-embed {
  width: 100%;
  height: 220px;
  border: 0;
  border-radius: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal h2 {
  margin: 0 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.tpl-board {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.tpl-board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.tpl-col-chip, .tpl-task-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 6px;
  font-size: 14px;
}
.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: var(--surface-alt);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* --- Responsive --- */

/* Task boards: below this width, stop making the row wider than the
   screen (which just forces horizontal scrolling) and instead stack each
   task into a compact card with label:value rows — no side-scrolling
   needed no matter how many columns a board has. */
@media (max-width: 860px) {
  .table-wrap { overflow-x: visible; }
  table.task-table thead { display: none; }
  table.task-table, table.task-table tbody, table.task-table tr, table.task-table td {
    display: block;
    width: 100%;
  }
  table.task-table tr {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
  }
  table.task-table tr:last-child { border-bottom: none; }
  table.task-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 0;
    border-bottom: none;
    min-width: 0;
  }
  table.task-table td[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    width: 84px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    color: var(--text-dim);
  }
  table.task-table td input, table.task-table td select {
    min-width: 0;
    width: auto;
    flex: 1;
    text-align: right;
  }
  table.task-table td textarea.cell-autosize {
    min-width: 0;
    width: auto;
    flex: 1;
    text-align: left;
  }
  table.task-table td:first-child {
    justify-content: flex-start;
    padding-top: 8px;
  }
  table.task-table td:first-child::before { display: none; }
  table.task-table td:first-child textarea.task-title {
    text-align: left;
    font-weight: 700;
    font-size: 15px;
    flex: 1;
    width: 100%;
  }
  table.task-table td.td-actions { justify-content: flex-end; padding-bottom: 4px; }
  table.task-table td.wide-cell { display: block; padding: 8px 0 0; }
}

@media (max-width: 720px) {
  .app-header { padding: 10px 14px; }
  .app-header nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around; padding: 6px 4px; }
  .app-header nav a { flex: 1; text-align: center; font-size: 11px; padding: 8px 4px; }
  .app-header .user-menu span { display: none; }
  body { padding-bottom: 56px; }
  .container { padding: 14px; }
  .phase-row { grid-template-columns: 1fr; gap: 4px; margin-bottom: 14px; }
  .project-grid { grid-template-columns: 1fr; }
  .client-row, .subhire-row { grid-template-columns: 1fr; gap: 4px; margin-bottom: 14px; }
  .client-row .del-client, .subhire-row .del-subhire { justify-self: flex-start; }
  .checklist-row { flex-wrap: wrap; }
  .checklist-status-select, .checklist-date-input, .checklist-text-input { width: 100%; }
}
