/* Several rules below set an explicit non-"none" `display` on elements that
   JS also toggles via the `hidden` attribute/property (flex panels, modal
   backdrops, etc). Without this, an author rule with equal-or-higher
   specificity than the UA stylesheet's `[hidden] { display: none }` can win
   the cascade by origin order, leaving an element JS believes is hidden
   still visually on screen. `hidden` must always mean hidden, everywhere in
   this app, so this is a deliberate, blanket !important. */
[hidden] { display: none !important; }

:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: #d8d8dc;
  --accent: #0071e3;
  --danger: #d70015;
  --radius: 12px;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --panel: #2c2c2e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --border: #3a3a3c;
    --accent: #409cff;
    --danger: #ff6961;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-card h1 { margin-top: 0; }

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar h1 { margin: 0; font-size: 1.25rem; display: flex; align-items: center; }
.topbar h1 a { color: inherit; text-decoration: none; display: flex; align-items: center; }
.topbar h1 a:hover { opacity: 0.8; }
.topbar h1 a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* AllianceSI brandmark — public/static/icons/alliance-si-mark.svg, the same
   stored artifact lib/ganttPdf.js renders into every PDF export. Sized to
   sit comfortably next to a 1.25rem h1 without changing the topbar's
   height. */
.brand-mark { height: 1.35em; width: auto; margin-right: 0.45em; flex: 0 0 auto; }

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}

.nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  justify-content: center;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: calc(var(--radius) - 4px);
  font-size: 0.95rem;
  white-space: nowrap;
}

.nav a:hover { background: var(--bg); }
.nav a.active { color: var(--text); background: var(--bg); font-weight: 600; }

@media (max-width: 700px) {
  .nav-toggle { display: inline-flex; align-items: center; order: 1; }
  .topbar h1 { order: 0; }
  .topbar .btn-small { order: 2; }

  .nav {
    order: 3;
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    gap: 0.15rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem 0.75rem;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    z-index: 20;
  }

  .nav.open { display: flex; }
  .nav a { padding: 0.6rem 0.5rem; }
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-value { font-size: 1.6rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }
.stat-tile.stat-alert .stat-value { color: var(--danger); }

.quick-add-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

@media (min-width: 700px) {
  .quick-add-grid { grid-template-columns: 1fr 1fr; }
}

.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}
.back-link:hover { text-decoration: underline; }

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .layout { grid-template-columns: 1fr 1.6fr; align-items: start; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.panel h2 { margin-top: 0; font-size: 1.05rem; }

.inline-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

/* Without this, the text input's own width:100% is used as its flex-basis,
   so it competes 1-for-1 with its rigid siblings (date field, submit button)
   for space instead of just taking whatever's left over. On narrower rows
   (e.g. nested side-by-side grids on larger screens) that collapses it down
   toward its minimum content width instead of the remaining space. */
.inline-form input[type="text"] {
  flex: 1 1 0%;
  min-width: 0;
}

.todo-quick-add input[type="date"] { flex: 0 0 auto; width: auto; max-width: 9.5rem; }

input[type="text"],
input[type="search"],
input[type="tel"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="color"],
textarea,
select {
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

/* type="search" adds a native cancel/clear affordance on the right in some
   browsers; keep it from crowding right up against the field's own padding. */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

textarea { resize: vertical; }

.btn {
  font: inherit;
  padding: 0.5rem 0.9rem;
  border-radius: calc(var(--radius) - 4px);
  border: none;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }

@media (min-width: 900px) {
  input[type="text"],
  input[type="search"],
  input[type="tel"],
  input[type="email"],
  input[type="url"],
  input[type="number"],
  input[type="password"],
  input[type="date"],
  textarea,
  select,
  .btn {
    padding: 0.7rem 1rem;
    font-size: 1.05rem;
  }

  .btn-small { padding: 0.45rem 0.85rem; font-size: 0.9rem; }
  .todo-quick-add input[type="date"] { max-width: 11.5rem; }
}

.message { color: var(--muted); font-size: 0.9rem; }
.message.error { color: var(--danger); }

.todo-list, .customer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.todo-item, .customer-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
}

.todo-item.done .todo-text { text-decoration: line-through; color: var(--muted); }
.todo-text {
  flex: 1;
  cursor: text;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
}
.todo-text:hover { background: var(--bg); }

.todo-edit-input {
  flex: 1;
  padding: 0.15rem 0.3rem;
  font: inherit;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  line-height: 1;
  touch-action: none;
  font-size: 1.3rem;
  padding: 0.4rem 0.3rem;
  margin: -0.4rem -0.3rem;
  user-select: none;
  -webkit-user-select: none;
}

.todo-item.dragging {
  opacity: 0.6;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  position: relative;
  z-index: 5;
}

/* Reordering: a drag handle on PC-sized screens, plain up/down buttons on
   mobile-sized ones — dragging with a fingertip on a small screen is
   unreliable (imprecise targets, scroll-vs-drag ambiguity), so below the
   same width the nav collapses at, swap it for two unambiguous taps. */
.reorder-arrows { display: none; }

@media (max-width: 700px) {
  .drag-handle { display: none; }

  .reorder-arrows {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
  }

  .arrow-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.65rem;
    line-height: 1;
    padding: 0.2rem 0.35rem;
    cursor: pointer;
  }

  .arrow-btn:disabled {
    opacity: 0.3;
    cursor: default;
  }
}

.todo-due-date {
  flex: 0 0 auto;
  width: auto;
  max-width: 9rem;
  font-size: 0.85rem;
  padding: 0.3rem 0.4rem;
}
.todo-due-date.overdue { border-color: var(--danger); color: var(--danger); }

.customer-item {
  cursor: pointer;
  justify-content: space-between;
}
.customer-item:hover { border-color: var(--accent); }
.customer-item.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}
.icon-btn:hover { color: var(--danger); }

.customer-layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 600px) {
  .customer-layout { grid-template-columns: 1fr 1.4fr; }
}

.customer-name-field {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.field-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
  margin-bottom: 0.75rem;
}

@media (min-width: 500px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
}

.field-block, .field-grid label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.field-block input, .field-block textarea, .field-grid input {
  margin-top: 0.3rem;
  color: var(--text);
  font-size: 0.95rem;
}

.field-block input[type="date"], .field-grid input[type="date"] {
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--bg);
  width: 100%;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.hint { color: var(--muted); font-size: 0.9rem; }

.empty-hint { text-align: center; padding: 2rem 1rem; }
.empty-hint::before {
  content: "";
  display: block;
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 0.6rem;
  opacity: 0.35;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5'%3E%3Cpath d='M3 7l2-4h14l2 4M3 7v12a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V7M3 7h18M9 11h6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.5'%3E%3Cpath d='M3 7l2-4h14l2 4M3 7v12a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V7M3 7h18M9 11h6'/%3E%3C/svg%3E") center / contain no-repeat;
}

.layout-single { grid-template-columns: 1fr; max-width: 700px; }

.customer-list-page { max-width: 800px; margin: 0 auto; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.list-header h2 { margin-bottom: 0; }

.list-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.list-controls #searchInput { flex: 1; }
.list-controls #sortSelect { flex: 0 0 auto; width: auto; }

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.tag-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
}

.tag-chip:hover { border-color: var(--accent); }
.tag-chip.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Global search */
.global-search { position: relative; }

.search-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  width: min(320px, 90vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  padding: 0.75rem;
  z-index: 30;
}

.search-results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  max-height: 300px;
  overflow-y: auto;
}

.search-results li {
  padding: 0.5rem 0.4rem;
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  font-size: 0.9rem;
}

.search-results li:hover, .search-results li.active-result { background: var(--bg); }
.search-results .result-kind { color: var(--muted); font-size: 0.75rem; margin-left: 0.4rem; }
.search-results .no-results { color: var(--muted); cursor: default; }
.search-results .no-results:hover { background: none; }

.customer-item .customer-arrow { color: var(--muted); }

/* Settings */
.segmented {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.settings-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  color: var(--text);
  text-decoration: none;
}

.settings-list a:hover { border-color: var(--accent); }
.settings-list .settings-desc { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }

/* Appearance editor */
.theme-columns {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

@media (min-width: 800px) {
  .theme-columns { grid-template-columns: 1fr 1fr; }
}

.color-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0;
}

.color-field label { font-size: 0.9rem; }
.color-field input[type="color"] { width: 3rem; padding: 0.2rem; height: 2.2rem; }

.theme-preview {
  border: 1px solid var(--preview-border, var(--border));
  border-radius: var(--preview-radius, var(--radius));
  overflow: hidden;
  background: var(--preview-bg, var(--bg));
  font-family: var(--preview-font, var(--font-family));
}

.theme-preview .preview-topbar {
  background: var(--preview-panel, var(--panel));
  border-bottom: 1px solid var(--preview-border, var(--border));
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--preview-text, var(--text));
}

.theme-preview .preview-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.theme-preview .preview-card {
  background: var(--preview-panel, var(--panel));
  border: 1px solid var(--preview-border, var(--border));
  border-radius: calc(var(--preview-radius, var(--radius)) - 4px);
  padding: 0.6rem 0.8rem;
  color: var(--preview-text, var(--text));
}

.theme-preview .preview-muted { color: var(--preview-muted, var(--muted)); font-size: 0.85rem; }

.theme-preview .preview-btn {
  align-self: flex-start;
  background: var(--preview-accent, var(--accent));
  color: white;
  border: none;
  border-radius: calc(var(--preview-radius, var(--radius)) - 4px);
  padding: 0.45rem 0.8rem;
  font-size: 0.9rem;
}

.theme-preview .preview-danger { color: var(--preview-danger, var(--danger)); font-size: 0.85rem; }

.preview-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.4rem; }

.appearance-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* Devices & activity */
.device-list, .activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
}

.custom-field-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.custom-field-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
}

.custom-field-item .field-label {
  flex: 0 0 auto;
  width: 9rem;
  max-width: 35%;
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-field-item .field-value { flex: 1; }

.file-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
}

.file-item .file-name {
  flex: 1;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-item .file-name:hover { color: var(--accent); text-decoration: underline; }
.file-item .file-meta { flex: 0 0 auto; color: var(--muted); font-size: 0.8rem; }
.file-item .file-move-select { flex: 0 0 auto; width: auto; max-width: 9rem; padding: 0.3rem 0.5rem; font-size: 0.82rem; }

.file-folder-item.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.file-folder-label {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-folder-item.active .file-folder-label { color: var(--accent); font-weight: 600; }

.activity-list li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.activity-list li:last-child { border-bottom: none; }

.due-item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}
.due-item-list li:hover { color: var(--accent); }
.due-item-meta { flex: 0 0 auto; color: var(--muted); font-size: 0.8rem; }
.due-item.overdue .due-item-meta { color: var(--danger); font-weight: 600; }

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
  width: min(420px, calc(100vw - 2rem));
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.7rem 0.9rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
  animation: toast-in 0.18s ease-out;
}

.toast-error { border-left-color: var(--danger); }
.toast.toast-leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; }

.toast span { flex: 1; font-size: 0.9rem; }

.toast-action {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  font: inherit;
  padding: 0.2rem 0.4rem;
}

.toast-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.2rem;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Accessibility: visible keyboard focus everywhere interactive */
.btn:focus-visible,
.nav a:focus-visible,
.nav-toggle:focus-visible,
.customer-item:focus-visible,
.settings-list a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.icon-btn:focus-visible,
.arrow-btn:focus-visible,
.toast-action:focus-visible,
.toast-close:focus-visible,
.back-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Gantt planner */
.gantt-page {
  max-width: 1800px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2rem;
}

.gantt-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.gantt-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.gantt-search { width: 12rem; }

.gantt-clock {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.gantt-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.gantt-inline-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.gantt-inline-toggle input { width: auto; }

.gantt-status-select { width: auto; flex: 0 0 auto; }

/* Frozen header + frozen sidebar, via plain sticky positioning inside one
   shared scroll container — both axes scroll together natively, so the
   sidebar/timeline rows can never drift out of alignment with each other. */
.gantt-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  max-height: 72vh;
}

.gantt-canvas {
  display: flex;
  align-items: flex-start;
  width: max-content;
  min-width: 100%;
}

.gantt-sidebar-col {
  position: sticky;
  left: 0;
  z-index: 2;
  width: var(--gantt-sidebar-width, 260px);
  flex: 0 0 var(--gantt-sidebar-width, 260px);
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.gantt-sidebar-resize-handle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
  touch-action: none;
}
.gantt-sidebar-resize-handle:hover,
.gantt-sidebar-resize-handle.is-dragging {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}
.gantt-sidebar-resize-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.gantt-corner {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 48px;
  width: 100%;
  display: flex;
  align-items: center;
  padding: 0 0.75rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--panel);
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
}

.gantt-sidebar-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 0.5rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  overflow: hidden;
}
.gantt-sidebar-row:hover { background: var(--bg); }
.gantt-sidebar-row.gantt-sidebar-task { padding-left: 1.5rem; }
.gantt-sidebar-row.gantt-placeholder-row { cursor: default; color: var(--muted); font-size: 0.8rem; }
.gantt-sidebar-row.gantt-placeholder-row:hover { background: none; }
.gantt-sidebar-row.is-archived { opacity: 0.6; }

.gantt-collapse-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0.2rem;
  line-height: 1;
  flex: 0 0 auto;
}

.gantt-color-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex: 0 0 auto;
}
.gantt-color-dot.small { width: 0.45rem; height: 0.45rem; }

.gantt-row-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
}
.gantt-sidebar-row:not(.gantt-sidebar-task) .gantt-row-name { font-weight: 600; }

.gantt-row-meta {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--muted);
}

.gantt-sidebar-row .icon-btn {
  flex: 0 0 auto;
  opacity: 0;
  font-size: 0.85rem;
}
.gantt-sidebar-row:hover .icon-btn,
.gantt-sidebar-row .icon-btn:focus-visible {
  opacity: 1;
}
.gantt-sidebar-row .gantt-overdue-btn {
  opacity: 1;
  color: var(--danger);
}
.gantt-sidebar-row .icon-btn:disabled {
  opacity: 0.2;
  cursor: default;
}

.status-pill {
  flex: 0 0 auto;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--bg);
  color: var(--muted);
}
.status-pill.status-in_progress { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.status-pill.status-blocked { background: color-mix(in srgb, #ff9500 20%, transparent); color: #ff9500; }
.status-pill.status-done { background: color-mix(in srgb, #34c759 20%, transparent); color: #34c759; }

/* Same visual footprint as .status-pill above, just interactive — used
   where a public share-link viewer is allowed to change a task's status
   (public-project.js). Beating the global select{width:100%} rule (see the
   input.gantt-hours-input comment below for why the element-qualified
   selector matters) so it stays pill-sized instead of filling the row. */
select.status-pill-select {
  flex: 0 0 auto;
  width: auto;
  max-width: 6.5rem;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.1rem 1.1rem 0.1rem 0.45rem;
  border: none;
  border-radius: 999px;
  background-color: var(--bg);
  color: var(--muted);
  cursor: pointer;
}

.gantt-solo-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.gantt-solo-bar h2 {
  margin: 0;
  font-size: 1rem;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gantt-share-box {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: 1 1 320px;
  min-width: 0;
}
.gantt-share-box label {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}
.gantt-share-box input {
  flex: 1 1 auto;
  min-width: 8rem;
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Beats the global `input[type="number"] { width: 100% }` rule (an
   attribute selector outranks a lone class on specificity) — without this,
   the box inflates to fill the sidebar row instead of staying a small
   fixed-size cell. */
input.gantt-hours-input {
  flex: 0 0 3rem;
  width: 3rem;
  padding: 0.15rem 0.3rem;
  font-size: 0.78rem;
  text-align: right;
}
/* Same specificity concern as .gantt-hours-input above. Progress % — the
   other field public-project.js lets a share-link viewer edit. */
input.gantt-progress-input {
  flex: 0 0 3rem;
  width: 3rem;
  padding: 0.15rem 0.3rem;
  font-size: 0.78rem;
  text-align: right;
}
.gantt-hours-badge {
  flex: 0 0 auto;
  width: 2.4rem;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.gantt-hours-col-label {
  flex: 0 0 auto;
  width: 2.4rem;
  text-align: right;
  margin-right: 0.4rem;
}

.public-view-badge {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}

.gantt-timeline-col { position: relative; }

.gantt-header {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.gantt-header-months, .gantt-header-days { position: relative; height: 24px; }
.gantt-header-months { border-bottom: 1px solid var(--border); }

.gantt-header-month {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  padding-left: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  border-left: 1px solid var(--border);
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
}

.gantt-header-day {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: var(--muted);
  border-left: 1px solid var(--border);
  box-sizing: border-box;
  line-height: 1.15;
}
.gantt-header-day.is-today { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 700; }

.gantt-body { position: relative; }

/* Grid lines + weekend shading are two CSS background layers computed once
   per render (see computeRowBackgroundLayers in gantt.js) rather than DOM
   nodes — a multi-year date range would otherwise mean thousands of divs
   repeated on every row. */
.gantt-header-days, .gantt-timeline-row {
  background-image: var(--gantt-row-bg-image, none);
  background-position: var(--gantt-row-bg-pos, 0 0);
  background-repeat: repeat;
}

.gantt-timeline-row {
  position: relative;
  border-bottom: 1px solid var(--border);
  box-sizing: border-box;
}

.gantt-today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--danger);
  z-index: 1;
  pointer-events: none;
}

.gantt-bar-wrap {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border-radius: calc(var(--radius) - 6px);
  overflow: hidden;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  touch-action: none;
}
.gantt-bar-wrap:active { cursor: grabbing; }
.gantt-bar-wrap.is-dragging { opacity: 0.85; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); z-index: 5; }
.gantt-bar-wrap.is-overdue { outline: 2px solid var(--danger); outline-offset: 1px; }

.gantt-bar-progress { position: absolute; top: 0; bottom: 0; left: 0; background: rgba(0, 0, 0, 0.22); }
.gantt-bar-label {
  position: relative;
  padding: 0 0.4rem;
  font-size: 0.72rem;
  line-height: 1;
  height: 100%;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

.gantt-bar-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}
.gantt-bar-handle.left { left: 0; }
.gantt-bar-handle.right { right: 0; }

.gantt-milestone {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%) rotate(45deg);
  cursor: grab;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.gantt-milestone.is-overdue { outline: 2px solid var(--danger); outline-offset: 1px; }

.gantt-project-summary-bar {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 6px;
  border-radius: 3px;
  opacity: 0.55;
  pointer-events: none;
}

.gantt-drag-badge {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  background: var(--text);
  color: var(--panel);
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 6;
}

.gantt-connectors { position: absolute; top: 0; left: 0; pointer-events: none; overflow: visible; }

.gantt-overdue-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.color-swatches { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 1rem; }
.color-swatch {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.color-swatch-inherit {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  border: 2px dashed var(--border);
  background: none;
  cursor: pointer;
  font-size: 0.55rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.color-swatch-inherit.selected { border-color: var(--text); border-style: solid; }
.color-swatch-custom { width: 2.2rem; height: 1.6rem; padding: 0.15rem; }

/* Modals (project/task editors) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem;
  z-index: 200;
  overflow-y: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(560px, 100%);
  padding: 1.5rem;
}
.modal h2 { margin-top: 0; }
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.5rem;
}
.modal-actions .btn-danger { margin-right: auto; }

.gantt-help-hint { margin-top: -0.25rem; }

.gantt-settings-panel { max-height: 75vh; overflow-y: auto; }

.gantt-filter-row .gantt-toolbar-group { row-gap: 0.4rem; }

.gantt-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  padding: 0.45rem 0.7rem;
}
.gantt-bulk-bar select { width: auto; flex: 0 0 auto; }
.gantt-bulk-shift-input { width: 5.5rem; flex: 0 0 auto; }

.gantt-sidebar-row .gantt-select-checkbox { flex: 0 0 auto; margin: 0; }

/* Dependency editor (task modal) */
.gantt-dependency-list { list-style: none; margin: 0 0 0.6rem; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; }
.gantt-dependency-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  font-size: 0.85rem;
}
.gantt-dependency-item .gantt-dependency-meta { color: var(--muted); font-size: 0.78rem; }
.gantt-dependency-item .icon-btn { margin-left: auto; opacity: 1; }
.gantt-dependency-item.is-violated { border-color: var(--danger); }

.gantt-dependency-add { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-bottom: 1rem; }
.gantt-dependency-add select { flex: 1 1 9rem; width: auto; }
.gantt-dependency-add input[type="number"] { flex: 0 0 4.5rem; width: auto; }

.gantt-status-add-form { flex-wrap: wrap; align-items: center; }
.gantt-status-add-form input[type="text"] { flex: 1 1 8rem; }
.gantt-status-add-form input[type="color"] { flex: 0 0 auto; width: 2.4rem; padding: 0.2rem; height: 2.2rem; }

.gantt-status-manage-item { display: flex; align-items: center; gap: 0.5rem; }
.gantt-status-manage-item .gantt-color-dot { flex: 0 0 auto; }
.gantt-status-manage-item input[type="text"] { flex: 1 1 auto; }
.gantt-status-manage-item .arrow-btn { display: inline-flex; }

/* Bars: keyboard focus, critical path, baseline ghost */
.gantt-bar-wrap, .gantt-milestone { outline-offset: 2px; }
.gantt-bar-wrap:focus-visible, .gantt-milestone:focus-visible { outline: 2px solid var(--accent); }
.gantt-bar-wrap.is-critical { box-shadow: 0 0 0 2px #ff3b30 inset; }
.gantt-milestone.is-critical { box-shadow: 0 0 0 2px #ff3b30; }

.gantt-baseline-bar {
  position: absolute;
  top: 50%;
  transform: translateY(9px);
  height: 4px;
  border-radius: 2px;
  background: var(--muted);
  opacity: 0.55;
  pointer-events: none;
}

/* List view (#19) */
.gantt-list-view { display: flex; flex-direction: column; gap: 1rem; }
.gantt-list-group {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.gantt-list-group h3 { margin: 0 0 0.5rem; display: flex; align-items: center; gap: 0.5rem; font-size: 1rem; }
.gantt-project-note {
  margin: -0.15rem 0 0.7rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg);
  border-radius: calc(var(--radius) - 4px);
  white-space: pre-wrap;
}
.gantt-list-task {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.gantt-list-task:last-child { border-bottom: none; }
.gantt-list-task:hover { background: var(--bg); }
.gantt-list-task .gantt-row-name { flex: 1 1 auto; }
.gantt-list-dates { flex: 0 0 auto; font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.gantt-list-empty { color: var(--muted); font-size: 0.85rem; padding: 0.3rem 0.4rem; }

@media (max-width: 700px) {
  .gantt-sidebar-col { width: 190px; flex-basis: 190px; }
  .gantt-search { width: 8rem; }
}

/* Print: keep the actual content, drop everything interactive/chrome */
@media print {
  .topbar, .toast-container, .back-link, .detail-actions, #saveStatus,
  .nav-toggle, .btn, .icon-btn, #noteForm, .empty-hint,
  .gantt-toolbar, .gantt-filter-row, .modal-backdrop, .gantt-help-hint {
    display: none !important;
  }

  body { background: white; color: black; }
  .layout { max-width: none; padding: 0; }
  .panel { border: none; padding: 0; margin-bottom: 1rem; }
  input, textarea { border: none; padding: 0; background: none; color: black; }
  .gantt-scroll { max-height: none; overflow: visible; border: none; }
  .gantt-page { max-width: none; padding: 0; }
}
