/* Shared Todos - single stylesheet, light + dark via prefers-color-scheme. */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2433;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --danger: #dc2626;
  --ok: #16a34a;
  --warn-text: #7c2d12;
  --row-hover: rgba(120, 130, 150, 0.07);
  --shadow: 0 10px 30px rgba(20, 25, 40, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --panel: #1c2027;
    --text: #e6e9ef;
    --muted: #99a1af;
    --line: #2b313c;
    --accent: #818cf8;
    --accent-hover: #6d78f2;
    --accent-soft: rgba(129, 140, 248, 0.12);
    --danger: #f87171;
    --ok: #4ade80;
    --warn-text: #fcd34d;
    --row-hover: rgba(160, 170, 190, 0.08);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Segoe UI", -apple-system, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

a { color: var(--accent); }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }

/* ---------- centered screens (loading / setup / auth) ---------- */

.center-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.auth-card { width: 380px; max-width: 92vw; }
.setup-card { max-width: 560px; line-height: 1.65; }
.setup-card code {
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 12.5px;
}
.setup-card li { margin-bottom: 6px; }

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */

.field { display: block; margin: 12px 0; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

input, textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }

/* Title, Description and Notes size themselves to their content (see
   autoGrow in app.js), so they never clip text behind an inner scrollbar. */
#rec-title, #rec-description, #rec-notes {
  resize: none;
  overflow-y: hidden;
  line-height: 1.45;
}
/* Title starts exactly as tall as a normal one-line field, then wraps. */
#rec-title { min-height: 38px; }
#rec-description, #rec-notes {
  resize: none;
  overflow-y: hidden;
  min-height: 78px;
  line-height: 1.45;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }

.form-error, .form-info {
  font-size: 13px;
  line-height: 1.5;
  border-radius: 8px;
  padding: 9px 11px;
  margin: 10px 0;
}
.form-error {
  color: var(--danger);
  background: rgba(220, 38, 38, 0.09);
  border: 1px solid rgba(220, 38, 38, 0.35);
}
.form-info {
  color: var(--ok);
  background: rgba(22, 163, 74, 0.09);
  border: 1px solid rgba(22, 163, 74, 0.35);
}

.toggle-line { text-align: center; margin-bottom: 0; }

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary:disabled { opacity: 0.55; cursor: default; }
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}
.btn.ghost:hover { background: var(--row-hover); }
.btn.wide { width: 100%; margin-top: 6px; }

.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 5px 7px;
  border-radius: 7px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--row-hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---------- top bar / layout ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.app-title { font-weight: 700; font-size: 15px; }

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ok);
  display: inline-block;
}
.live-dot.off { background: var(--muted); opacity: 0.6; }

main { max-width: 100%; margin: 0; padding: 14px 14px 52px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
#search-box { flex: 1; max-width: 380px; }
#filter-status { width: auto; }
#sheet-sortdir { width: auto; flex: none; }

/* ---------- table ---------- */

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: calc(100vh - 205px);
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 1;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--row-hover); }

.title-text { font-weight: 600; max-width: 320px; }
.status-done .title-text { text-decoration: line-through; opacity: 0.55; }
/* any custom status marked "counts as completed" behaves like Done */
.status-complete .title-text { text-decoration: line-through; opacity: 0.55; }

.notes-text {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* status pills double as dropdowns (rgba colors work on both themes) */
.status-select {
  appearance: none;
  -webkit-appearance: none;
  width: auto;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.pill-open {
  background: rgba(59, 130, 246, 0.14);
  color: #3b82f6;
  border-color: rgba(59, 130, 246, 0.4);
}
.pill-in_progress {
  background: rgba(245, 158, 11, 0.14);
  color: #d97706;
  border-color: rgba(245, 158, 11, 0.4);
}
.pill-done {
  background: rgba(34, 197, 94, 0.14);
  color: #16a34a;
  border-color: rgba(34, 197, 94, 0.4);
}
@media (prefers-color-scheme: dark) {
  .pill-in_progress { color: #fbbf24; }
  .pill-done { color: #4ade80; }
  .pill-open { color: #60a5fa; }
}

.prio-high { color: var(--danger); font-weight: 600; }
.prio-low { color: var(--muted); }

.due.overdue { color: var(--danger); font-weight: 600; }

.edited-who { font-weight: 500; }
.col-actions { white-space: nowrap; text-align: right; }

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

.version-tag { float: right; opacity: 0.75; }

.statusbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 7px 18px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--line);
}

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 13, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

.modal { width: 560px; max-width: 94vw; max-height: 92vh; overflow: auto; }

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

#modal-meta { margin-top: 10px; line-height: 1.5; }

.conflict {
  background: rgba(245, 158, 11, 0.13);
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: var(--warn-text);
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 13px;
  line-height: 1.55;
  margin: 0 0 12px;
}
.conflict-actions { margin-top: 6px; }
.conflict-actions a { color: inherit; font-weight: 700; }

/* ---------- multi-select dropdowns (assigned / visible / categories) ---------- */

.msel { position: relative; }

.msel-btn {
  width: 100%;
  text-align: left;
  padding: 8px 26px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msel-btn::after {
  content: "\25BE";
  position: absolute;
  right: 9px;
  color: var(--muted);
}
.msel-btn:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.msel-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  width: max-content;
  max-width: 300px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 30;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
}

.msel-row {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.msel-row:hover { background: var(--row-hover); }
.msel-row input { width: auto; margin: 0; accent-color: var(--accent); }
/* Assignees inside the "Visible to" picker: always ticked, never removable */
.msel-row.msel-locked { opacity: 0.75; cursor: default; }
.msel-row.msel-locked input { cursor: default; }
.msel-everyone { border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; font-weight: 600; }
.msel-empty { padding: 8px 10px; color: var(--muted); font-size: 12.5px; max-width: 240px; white-space: normal; }

/* category manager modal */
.modal-sm { width: 430px; }
.cat-add-row { display: flex; gap: 8px; margin: 4px 0 12px; }
.cat-add-row input { flex: 1; }
#cat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow: auto;
}
.cat-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.cat-row:hover { background: var(--row-hover); }
.cat-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.cat-count { white-space: nowrap; }
.cat-row.editing { padding: 4px 0; }
.cat-row.editing input { flex: 1; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }

/* status manager (admins) */
.status-done-tick {
  display: flex;
  gap: 7px;
  align-items: center;
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 13px;
}
.status-done-tick input { width: auto; margin: 0; accent-color: var(--accent); }
#status-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow: auto;
}
.status-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.status-row:hover { background: var(--row-hover); }
.status-row-label { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

/* category chips + restricted-visibility marker in the table */
.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin: 3px 4px 0 0;
}
.lock { margin-left: 6px; font-size: 12px; opacity: 0.8; cursor: default; }
.assigned-names { font-size: 12.5px; max-width: 150px; }

/* ---------- attachments (record form) ---------- */

.attach-section { margin: 6px 0 2px; }
.attach-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); }
#attach-list { display: flex; flex-direction: column; gap: 2px; }
.attach-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 13px;
}
.attach-row:hover { background: var(--row-hover); }
.attach-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.attach-size { white-space: nowrap; }
.attach-uploading { color: var(--muted); font-size: 12.5px; padding: 4px 8px; }

/* ---------- admin area ---------- */

.admin-panel { width: 760px; max-width: 96vw; }
.admin-panel h3 { font-size: 14px; margin: 14px 0 8px; }
.admin-add {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 14px 12px;
  margin-bottom: 6px;
}
.field-narrow { max-width: 130px; }
.admin-user {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 10px;
}
.admin-user-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.admin-user-name { font-weight: 700; }
.admin-user-head select { width: auto; padding: 4px 8px; font-size: 12.5px; }
.admin-user-head .spacer { flex: 1; }
.role-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}
.pw-row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.pw-row input { max-width: 240px; }

/* Alerts editor (Admin panel -> user card -> 🔔 Alerts): a Default
   profile block plus one override block per section. */
.alerts-editor {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-top: 10px;
  background: var(--row-hover);
}
.alerts-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px 10px;
  margin-bottom: 10px;
}
.alerts-block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.alerts-block-title {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}
.alerts-block-head .alerts-tabname { font-weight: 700; font-size: 13.5px; }
.alert-kind-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 3px 0;
  font-size: 13px;
}
.alert-kind-label { width: 200px; min-width: 150px; }
.alert-kind-row label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; margin: 0; }
.alert-kind-row input[type=checkbox] { width: auto; margin: 0; }
.status-scope { margin: 2px 0 0 200px; font-size: 12.5px; }
.status-scope .scope-ticks { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 5px; }
.status-scope label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; margin: 0; }
.status-scope input[type=checkbox] { width: auto; margin: 0; }
.alerts-add-row { display: flex; align-items: center; gap: 8px; margin: 2px 0 10px; flex-wrap: wrap; }
.alerts-add-row select { width: auto; padding: 5px 9px; font-size: 12.5px; }
.alerts-buttons { display: flex; gap: 8px; }
@media (max-width: 560px) {
  .alert-kind-label { width: 100%; }
  .status-scope { margin-left: 0; }
}
.perm-table { margin-top: 10px; border-collapse: collapse; font-size: 12.5px; }
.perm-table th {
  position: static;
  padding: 3px 12px 3px 0;
  font-size: 10.5px;
  border-bottom: none;
  background: transparent;
}
.perm-table td { padding: 3px 12px 3px 0; border-bottom: none; vertical-align: middle; }
.perm-table input[type="checkbox"] { width: auto; margin: 0; accent-color: var(--accent); }
.perm-cat-name { min-width: 140px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 40px;
  background: #1f2937;
  color: #f9fafb;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 72vw;
  text-align: center;
}
.toast.ok { background: #065f46; }
.toast.warn { background: #92400e; }
.toast.error { background: #991b1b; }

/* ---------- mobile / PWA layout (phones and small tablets) ---------- */

@media (max-width: 720px) {
  html, body { font-size: 15px; }
  /* 16px inputs stop iOS Safari from zooming in on focus */
  input, textarea, select { font-size: 16px; }
  /* roomier starting size on phones; they grow from here as you type */
  #rec-title { min-height: 42px; }
  #rec-description { min-height: 132px; }
  #rec-notes { min-height: 110px; }
  .btn { padding: 10px 16px; }
  .icon-btn { font-size: 17px; padding: 8px 10px; }

  .topbar {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  main { padding: 12px 10px calc(58px + env(safe-area-inset-bottom)); }

  .toolbar { flex-wrap: wrap; gap: 8px; }
  #search-box { flex: 1 1 100%; max-width: none; order: -1; }
  .toolbar select { flex: 1 1 40%; width: auto; }
  #btn-new { flex: 1 1 100%; }

  /* the table becomes a stack of cards */
  .table-wrap {
    background: transparent;
    border: none;
    border-radius: 0;
    overflow: visible;
    max-height: none;
  }
  table, tbody { display: block; }
  thead { display: none; }
  tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    position: relative;
  }
  tbody tr:hover td { background: transparent; }
  td { display: block; border-bottom: none; padding: 2px 0; }
  tbody tr:last-child td { border-bottom: none; }

  .col-title { flex: 1 1 100%; padding-right: 84px; } /* room for ✎ 🗑 */
  .title-text { max-width: none; font-size: 15.5px; }
  .col-notes { flex: 1 1 100%; }
  .notes-text {
    white-space: normal;
    max-width: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .col-status, .col-priority, .col-due { flex: 0 0 auto; }
  .status-select { font-size: 13px; padding: 5px 12px; }
  .col-due .due::before { content: "Due "; color: var(--muted); font-weight: 400; }
  .col-assigned { flex: 1 1 100%; }
  .col-assigned .assigned-names { max-width: none; }
  .col-assigned .assigned-names::before { content: "Assigned: "; color: var(--muted); }
  .col-visible { flex: 1 1 100%; }
  .col-visible .assigned-names { max-width: none; }
  .col-visible .assigned-names::before { content: "Visible to: "; color: var(--muted); }
  .col-created { flex: 1 1 100%; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
  .col-created .created-when::before { content: "Created "; color: var(--muted); }
  .col-created .created-who::before { content: "by "; }
  .col-edited { flex: 1 1 100%; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
  .col-edited .edited-who::before { content: "Edited by "; color: var(--muted); font-weight: 400; }
  .col-actions { position: absolute; top: 8px; right: 8px; padding: 0; }

  /* modals become full-screen sheets */
  .modal-backdrop { padding: 0; align-items: stretch; justify-content: stretch; }
  .modal {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border-radius: 0;
    border: none;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    padding-top: calc(16px + env(safe-area-inset-top));
  }
  .admin-panel { width: 100%; }
  .modal { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .field-row { flex-wrap: wrap; }
  .field-row .field { flex: 1 1 45%; min-width: 45%; }
  .field-narrow { max-width: none; }
  .msel-panel { left: 0; right: 0; width: auto; min-width: 0; max-width: none; }
  .pw-row { flex-wrap: wrap; }

  .statusbar { padding-bottom: calc(7px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(64px + env(safe-area-inset-bottom)); max-width: 92vw; }
}

/* ---------- tab bar ---------- */

.tabbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 45px;
  z-index: 4;
}
.tab-strip {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.tab-strip::-webkit-scrollbar { display: none; }
.tab-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.tab-btn {
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  padding: 10px 14px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab-btn:hover { color: var(--text); background: var(--row-hover); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn .tab-lock { margin-left: 6px; font-size: 11px; opacity: 0.75; }

.spacer { flex: 1; }
.danger-text { color: var(--danger); }

/* ---------- sheet grid ---------- */

#sheet-table td { white-space: pre-wrap; word-break: break-word; }
.sheet-cell { max-width: 320px; }
.sheet-cell.empty-cell { color: var(--muted); }
/* rows are tap-to-open on phones only; on desktop the gutter pencil opens */
@media (max-width: 720px) {
  .sheet-row-open { cursor: pointer; }
}
.row-open-btn {
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0 3px 0 0;
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
}
.row-open-btn:hover { opacity: 0.7; }
#sheet-body td.sheet-gutter { cursor: grab; }
body.row-dragging { cursor: grabbing; user-select: none; }
body.row-dragging #sheet-body tr:hover td { box-shadow: none; }
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 8px;
  flex-wrap: wrap;
}
#sheet-body td.cell-hit { background: rgba(250, 204, 21, 0.42) !important; }
#sheet-body td.cell-hit-current {
  outline: 2px solid #f59e0b;
  outline-offset: -2px;
  background: rgba(245, 158, 11, 0.55) !important;
}
tr.row-clipboard td {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
@keyframes cellflash {
  from { background-color: rgba(79, 70, 229, 0.38); }
}
#sheet-body td.cell-flash { animation: cellflash 1.3s ease-out; }
tr.row-flash td { animation: cellflash 1.7s ease-out; }
#sheet-body td.cell-fill-preview {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.fill-handle {
  position: fixed;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: 1.5px solid var(--panel);
  border-radius: 2px;
  z-index: 260;
  cursor: crosshair;
}
#sheet-body td.cell-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(79, 70, 229, 0.12) !important;
}
#sheet-body td.cell-selected {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(79, 70, 229, 0.12) !important;
}
.row-drop-line {
  position: fixed;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
  z-index: 250;
  pointer-events: none;
}
#sheet-table td.editing { padding: 0; overflow: visible; }
.cell-editor {
  width: 100%;
  min-height: 25px;
  border: 2px solid var(--accent);
  border-radius: 0;
  padding: 2px 6px;
  font: inherit;
  font-size: 12.5px;
  background: var(--panel);
  color: inherit;
  box-sizing: border-box;
  display: block;
}
textarea.cell-editor { min-height: 56px; resize: vertical; }
.sheet-check { font-size: 15px; }
#row-fields .field:first-child { margin-top: 0; }

@media (max-width: 720px) {
  .tabbar { top: 0; position: static; padding: 0 10px; }
  .tab-actions .btn { padding: 6px 10px; }

  /* the grid becomes one card per row, like the task list */
  #sheet-table, #sheet-table tbody { display: block; }
  #sheet-table thead { display: none; }
  #sheet-body tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
  }
  #sheet-body td {
    display: flex;
    gap: 10px;
    padding: 3px 0;
    border-bottom: none;
    max-width: none;
  }
  #sheet-body td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    padding-top: 1px;
  }
  #sheet-body td.sheet-first { font-weight: 700; font-size: 15px; }
  #sheet-body td.sheet-first::before { display: none; }
  /* cards, not a grid: undo the spreadsheet sizing */
  #sheet-table { table-layout: auto; width: 100% !important; font-size: 14px; }
  #sheet-table colgroup { display: none; }
  .sheet-gutter { display: none !important; }
  .col-resizer { display: none; }
  #sheet-body td {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    border-right: none;
    height: auto;
  }
  #sheet-view .table-wrap { max-height: none; overflow: visible; }
}

.sheet-more { text-align: center; padding: 10px 0 4px; }

/* ---------- spreadsheet-style grid ---------- */

#sheet-view .table-wrap {
  max-height: calc(100vh - 215px);
  overflow: auto;
  border-radius: 8px;
}

#sheet-table {
  table-layout: fixed;          /* column widths come from <colgroup> */
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}

#sheet-table th,
#sheet-table td {
  padding: 4px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;          /* one line per cell, like a spreadsheet */
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  max-width: none;
  height: 26px;
}

#sheet-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.02em;
  text-align: left;
  user-select: none;
}

/* drag handle on the right edge of every header cell */
.col-resizer {
  position: absolute;
  top: 0;
  right: 0;            /* inside the cell: th clips overflow */
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 4;
}
.col-resizer:hover { background: var(--accent); opacity: 0.35; }
body.col-resizing { cursor: col-resize; user-select: none; }

/* row-number gutter, frozen at the left edge */
.sheet-gutter {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel) !important;
  color: var(--muted);
  text-align: right;
  font-size: 11px;
  border-right: 1px solid var(--line);
}
th.sheet-gutter { z-index: 3; }

/* 📎 button on rows that carry attachments (gutter is sticky = positioned) */
.row-attach-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  padding: 1px 2px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  opacity: .85;
}
.row-attach-btn:hover {
  opacity: 1;
  transform: translateY(-50%) scale(1.25);
}
#attachlist-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0 4px;
  max-height: 55vh;
  overflow-y: auto;
}
.attachlist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
}
.attachlist-item:hover { border-color: var(--muted); }
.attachlist-name { flex: 1; overflow-wrap: anywhere; }
.attachlist-line { display: flex; align-items: stretch; gap: 6px; }
.attachlist-line .attachlist-item { flex: 1; }
.attachlist-dl { flex: none; padding: 0 10px; font-size: 15px; }
.attachlist-hint { margin-top: 6px; }

/* ---------- notifications bell ---------- */
.notif { position: relative; }
#btn-notif { position: relative; padding-left: 10px; padding-right: 10px; }
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}
.notif-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(420px, 92vw);
  max-height: min(70vh, 560px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .18);
  z-index: 60;
  padding: 10px;
}
.notif-head { display: flex; align-items: center; gap: 8px; margin: 2px 4px 10px; }
.notif-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  margin-bottom: 8px;
  font-size: 13px;
}
.notif-item.unread { border-left: 4px solid var(--danger); }
.notif-item .notif-meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 3px; }
.notif-item .notif-title { font-weight: 600; overflow-wrap: anywhere; }
.notif-item .notif-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--muted);
  max-height: 130px;
  overflow: hidden;
  margin: 4px 0 6px;
}
.notif-item .notif-status-line { font-weight: 700; margin: 2px 0; }
.notif-item .notif-status-to { color: var(--accent); }
.notif-empty { color: var(--muted); text-align: center; padding: 18px 0 12px; }

/* Phones: the bell is near the left edge, so the right-anchored dropdown
   would open off-screen — span the viewport instead (toggleNotifPanel
   sets top/max-height to sit just under the bell). */
@media (max-width: 720px) {
  .notif-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    top: 110px;
    width: auto;
    max-height: calc(100vh - 130px);
  }
}

/* ---------- task-table column filter ---------- */
#todo-table.hide-notes    .col-notes    { display: none !important; }
#todo-table.hide-status   .col-status   { display: none !important; }
#todo-table.hide-priority .col-priority { display: none !important; }
#todo-table.hide-due      .col-due      { display: none !important; }
#todo-table.hide-assigned .col-assigned { display: none !important; }
#todo-table.hide-visible  .col-visible  { display: none !important; }
#todo-table.hide-created  .col-created  { display: none !important; }
#todo-table.hide-edited   .col-edited   { display: none !important; }

/* arrow-key navigation: keep the focused cell clear of the sticky
   header and the frozen row-number gutter when it scrolls into view */
#sheet-body td { scroll-margin-top: 34px; scroll-margin-left: 70px; }

/* generic row colours driven by a Coloured dropdown column */
#sheet-body tr.rc-green td { background: rgba(34, 197, 94, 0.14); }
#sheet-body tr.rc-yellow td { background: rgba(250, 204, 21, 0.18); }
#sheet-body tr.rc-red td { background: rgba(239, 68, 68, 0.15); }
#sheet-body tr.rc-blue td { background: rgba(59, 130, 246, 0.15); }
#sheet-body tr.rc-orange td { background: rgba(249, 115, 22, 0.16); }
#sheet-body tr.rc-purple td { background: rgba(168, 85, 247, 0.15); }
#sheet-body tr.rc-teal td { background: rgba(20, 184, 166, 0.16); }
#sheet-body tr.rc-pink td { background: rgba(236, 72, 153, 0.14); }
#sheet-body tr.rc-grey td { background: rgba(107, 114, 128, 0.16); }
#sheet-body tr.rc-brown td { background: rgba(146, 94, 62, 0.18); }
.rc-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
}
.rc-dot-green { background: #22c55e; } .rc-dot-yellow { background: #eab308; }
.rc-dot-red { background: #ef4444; } .rc-dot-blue { background: #3b82f6; }
.rc-dot-orange { background: #f97316; } .rc-dot-purple { background: #a855f7; }
.rc-dot-teal { background: #14b8a6; } .rc-dot-pink { background: #ec4899; }
.rc-dot-grey { background: #6b7280; } .rc-dot-brown { background: #92603e; }
.rc-bg-green { background: rgba(34, 197, 94, 0.25); } .rc-bg-yellow { background: rgba(250, 204, 21, 0.3); }
.rc-bg-red { background: rgba(239, 68, 68, 0.25); } .rc-bg-blue { background: rgba(59, 130, 246, 0.25); }
.rc-bg-orange { background: rgba(249, 115, 22, 0.25); } .rc-bg-purple { background: rgba(168, 85, 247, 0.25); }
.rc-bg-teal { background: rgba(20, 184, 166, 0.25); } .rc-bg-pink { background: rgba(236, 72, 153, 0.25); }
.rc-bg-grey { background: rgba(107, 114, 128, 0.25); } .rc-bg-brown { background: rgba(146, 94, 62, 0.3); }
.coloropt-row { display: flex; gap: 6px; align-items: center; margin: 4px 0; }
.coloropt-row input { flex: 1; min-width: 0; }
.coloropt-color { width: 110px; flex: none; }

/* the sheet's own Green / Yellow / Red colour coding */
#sheet-body tr.st-green  td { background: rgba(34, 197, 94, 0.14); }
#sheet-body tr.st-yellow td { background: rgba(250, 204, 21, 0.18); }
#sheet-body tr.st-red    td { background: rgba(239, 68, 68, 0.15); }
#sheet-body tr:hover td { box-shadow: inset 0 0 0 9999px rgba(120, 130, 150, 0.06); }

/* The spreadsheet rules above are desktop-only: re-assert the phone card
   layout last so it wins on narrow screens. */
@media (max-width: 720px) {
  #sheet-table { table-layout: auto; width: 100%; font-size: 14px; }
  #sheet-table colgroup { display: none; }
  #sheet-table th { position: static; }
  .sheet-gutter, .col-resizer { display: none !important; }
  #sheet-body td {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    border-right: none;
    border-bottom: none;
    height: auto;
    padding: 3px 0;
  }
  #sheet-body tr.st-green  td,
  #sheet-body tr.st-yellow td,
  #sheet-body tr.st-red    td,
  #sheet-body tr[class*=" rc-"] td { background: transparent; }
  #sheet-body tr.st-green,  #sheet-body tr.rc-green  { border-left: 4px solid rgba(34, 197, 94, 0.85); }
  #sheet-body tr.st-yellow, #sheet-body tr.rc-yellow { border-left: 4px solid rgba(250, 204, 21, 0.9); }
  #sheet-body tr.st-red,    #sheet-body tr.rc-red    { border-left: 4px solid rgba(239, 68, 68, 0.85); }
  #sheet-body tr.rc-blue   { border-left: 4px solid rgba(59, 130, 246, 0.85); }
  #sheet-body tr.rc-orange { border-left: 4px solid rgba(249, 115, 22, 0.85); }
  #sheet-body tr.rc-purple { border-left: 4px solid rgba(168, 85, 247, 0.85); }
  #sheet-body tr.rc-teal   { border-left: 4px solid rgba(20, 184, 166, 0.85); }
  #sheet-body tr.rc-pink   { border-left: 4px solid rgba(236, 72, 153, 0.85); }
  #sheet-body tr.rc-grey   { border-left: 4px solid rgba(107, 114, 128, 0.85); }
  #sheet-body tr.rc-brown  { border-left: 4px solid rgba(146, 94, 62, 0.85); }
  #sheet-view .table-wrap { max-height: none; overflow: visible; }
}

/* per-tab access table + column editor (tab settings) */
#tab-perms .perm-table { width: 100%; }
.tab-cols-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.tab-cols-row input[type="text"] { flex: 1; min-width: 0; }
.tab-cols-row select { width: 150px; flex: none; }
.colmove { padding: 4px 8px; flex: none; }
.tab-cols-opts { width: 100%; margin: -2px 0 8px; }
.modal-wide { max-width: 720px; width: min(720px, calc(100vw - 32px)); }
#row-fields input[readonly] { color: var(--muted); }

/* cell links + the right-click menu */
#sheet-body td a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.cell-menu {
  position: fixed;
  z-index: 300;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  min-width: 150px;
  padding: 4px;
}
.cell-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 12px;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 6px;
  font: inherit;
  color: inherit;
}
.cell-menu button:hover { background: rgba(120, 130, 150, 0.14); }
.row-link-input { margin-top: 4px; }
.attach-row input[type="text"] { flex: 1; min-width: 0; }
.link-toggle { border: 0; background: none; cursor: pointer; padding: 0 4px; opacity: 0.5; font-size: 13px; }
.link-toggle.on { opacity: 1; }

/* the "Columns" display filter */
.colvis { position: relative; display: inline-block; }
.colvis .msel-panel { max-height: 320px; overflow-y: auto; }

/* the Columns panel opens leftward from the right edge */
.colvis .msel-panel { left: auto; right: 0; }

/* row editor fields grow with their content, like the record form */
#row-fields .grow-field {
  resize: none;
  overflow-y: hidden;
  line-height: 1.45;
  min-height: 78px;
}
#row-fields .grow-single { min-height: 38px; }
@media (max-width: 720px) {
  #row-fields .grow-single { min-height: 42px; }
}

/* phone cards show only the fields that have something in them */
@media (max-width: 720px) {
  #sheet-body td.empty-cell { display: none; }
}

/* the TENWAYS logo in the header */
.app-logo { height: 30px; width: auto; display: block; }
@media (max-width: 720px) {
  .app-logo { height: 24px; }
}
