/* ============================================================
   Kamagram Portal — design system
   Notion-inspired: clean, light, neutral grays, subtle borders
   ============================================================ */

:root {
  --bg:            #ffffff;
  --bg-sidebar:    #f7f7f5;
  --bg-hover:      #efefef;
  --bg-active:     #e9e9e7;
  --bg-subtle:     #f1f1ef;
  --text:          #37352f;
  --text-muted:    #787774;
  --text-faint:    #9b9a97;
  --border:        #e9e9e7;
  --border-strong: #ddddda;
  --accent:        #2383e2;
  --accent-soft:   #e7f1fb;
  --shadow-sm:     0 1px 2px rgba(15, 15, 15, 0.08);
  --shadow-md:     0 4px 12px rgba(15, 15, 15, 0.12);
  --radius:        6px;
  --radius-lg:     10px;
  --sidebar-w:     250px;

  /* status / tag palette */
  --c-gray:   #e3e2e0; --c-gray-t:   #4b4a47;
  --c-brown:  #eee0da; --c-brown-t:  #6b4c3f;
  --c-orange: #fadec9; --c-orange-t: #8a4f24;
  --c-yellow: #fdecc8; --c-yellow-t: #856a2d;
  --c-green:  #dbeddb; --c-green-t:  #2c5c3f;
  --c-blue:   #d3e5ef; --c-blue-t:   #28526b;
  --c-purple: #e8deee; --c-purple-t: #543b6b;
  --c-pink:   #f5e0e9; --c-pink-t:   #7a3b56;
  --c-red:    #ffe2dd; --c-red-t:    #9b2c20;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; margin: 0; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.app__main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

.sidebar__workspace {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}
.sidebar__workspace .logo {
  width: 22px; height: 22px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
}
.sidebar__search { margin: 4px 4px 6px; }
.sidebar__search .input { padding: 5px 9px; font-size: 13px; background: var(--bg); }
.sidebar__section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 12px 8px 4px;
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 8px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
}
.sidebar__link:hover { background: var(--bg-hover); }
.sidebar__link.is-active { background: var(--bg-active); color: var(--text); font-weight: 500; }
.sidebar__link .ico { width: 18px; text-align: center; opacity: 0.85; }
.sidebar__spacer { flex: 1; }
.sidebar__user {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* ---------- Avatars ---------- */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #2383e2;
  color: #fff;
  display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

.avatar--blue { background: #2383e2; color: #fff; }
.avatar--green { background: #2db95f; color: #fff; }
.avatar--purple { background: #9c27b0; color: #fff; }
.avatar--orange { background: #ff9800; color: #fff; }
.avatar--pink { background: #e91e63; color: #fff; }
.avatar--red { background: #f44336; color: #fff; }

.avatar--sm {
  width: 24px; height: 24px;
  font-size: 11px;
  border-width: 1px;
}

.avatar-stack {
  display: inline-flex;
  gap: 0;
}

.avatar-stack .avatar {
  margin-left: -8px;
}

.avatar-stack .avatar:first-child {
  margin-left: 0;
}

/* Avatar tooltip */
.avatar {
  position: relative;
}

.avatar::after {
  content: attr(data-name);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  margin-bottom: 8px;
  z-index: 10;
}

.avatar::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  margin-bottom: 0px;
  z-index: 10;
}

.avatar:hover::after,
.avatar:hover::before {
  opacity: 1;
}

/* ---------- Page header / content ---------- */
.page { padding: 16px 48px 80px; max-width: 1180px; width: 100%; margin: 0 auto; }
.page__head { display: flex; align-items: center; gap: 12px; margin: 16px 0 6px; }
.page__title { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; }
.page__icon { font-size: 30px; line-height: 1; }
.page__sub { color: var(--text-muted); font-size: 14px; margin-bottom: 18px; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  height: 45px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px; color: var(--text-muted);
}
/* Full-bleed breadcrumb bar at the top of a detail page; the negative margins
   cancel the page padding, so they must track it across breakpoints. */
.page-topbar { margin: -16px -48px 0; padding-left: 48px; }

/* ---------- View tabs (Table / Board / Calendar …) ---------- */
.viewtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.viewtabs a {
  padding: 6px 10px; font-size: 14px; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 4px 4px 0 0;
  display: flex; align-items: center; gap: 6px;
}
.viewtabs a:hover { background: var(--bg-hover); }
.viewtabs a.is-active { color: var(--text); border-bottom-color: var(--text); font-weight: 500; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--bg);
  color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .12s;
}
.btn:hover { background: var(--bg-hover); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #1b6fc4; }
.btn--sm { padding: 3px 8px; font-size: 13px; }
.btn--ghost { border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--bg-hover); }
.btn--danger { color: var(--c-red-t); border-color: var(--border-strong); }
.btn--danger:hover { background: var(--c-red); }

/* ---------- Badges / pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 4px;
  font-size: 12.5px; font-weight: 500; line-height: 1.4;
  background: var(--c-gray); color: var(--c-gray-t); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill--gray   { background: var(--c-gray);   color: var(--c-gray-t); }
.pill--brown  { background: var(--c-brown);  color: var(--c-brown-t); }
.pill--orange { background: var(--c-orange); color: var(--c-orange-t); }
.pill--yellow { background: var(--c-yellow); color: var(--c-yellow-t); }
.pill--green  { background: var(--c-green);  color: var(--c-green-t); }
.pill--blue   { background: var(--c-blue);   color: var(--c-blue-t); }
.pill--purple { background: var(--c-purple); color: var(--c-purple-t); }
.pill--pink   { background: var(--c-pink);   color: var(--c-pink-t); }
.pill--red    { background: var(--c-red);    color: var(--c-red-t); }

/* ---------- Tables ---------- */
.tbl {
  width: 100%; border-collapse: collapse; font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tbl th {
  text-align: left; font-weight: 500; color: var(--text-muted);
  font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}
.tbl td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.tbl tbody tr:last-child td {
  border-bottom: none;
}
.tbl tbody tr:hover { background: var(--bg-subtle); }
.tbl__group td { background: var(--bg-subtle); font-weight: 600; font-size: 13px; color: var(--text); }
.tbl a.cell-title { font-weight: 500; }
.tbl a.cell-title:hover { text-decoration: underline; }

/* Tags column - prevent wrapping and keep rows consistent height */
.tbl td.row.wrap {
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  flex-wrap: nowrap !important;
  max-height: 40px;
}

/* Wrapper that lets wide tables scroll sideways instead of hiding columns —
   so every field stays reachable when editing on a phone. */
.tbl-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 80px; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; }

/* assignees checkboxes */
.assignees-checkboxes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.checkbox-label:hover { background: var(--bg-hover); }
.checkbox-label input[type="checkbox"] { cursor: pointer; }
.checkbox-label span { font-size: 14px; }

/* tag input */
.tag-input { border: 1px solid var(--border); border-radius: 6px; padding: 8px; background: var(--bg); }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 24px; }
.tag-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); padding: 4px 8px; border-radius: 4px; font-size: 13px; }
.tag-chip-remove { background: none; border: none; cursor: pointer; font-size: 16px; padding: 0; color: var(--accent); }
.tag-chip-remove:hover { color: var(--c-red-t); }
.tag-input-field { border: none; padding: 6px 0; font-size: 14px; width: 100%; outline: none; background: transparent; }
.tag-input-field::placeholder { color: var(--text-muted); }

/* delete modal */
.delete-modal {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.delete-modal.hidden { display: none; }
.delete-modal-overlay {
  position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px);
}
.delete-modal-content {
  position: relative; background: var(--bg); border-radius: 12px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35), 0 0 1px rgba(0, 0, 0, 0.1);
  width: 100%; max-width: 440px; z-index: 1001; overflow: hidden;
  border: 1px solid var(--border);
}
.delete-modal-header {
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border);
}
.delete-modal-header h2 {
  margin: 0; font-size: 20px; font-weight: 700; color: var(--text);
}
.delete-modal-body {
  padding: 24px 32px;
}
.delete-modal-body p {
  margin: 0 0 12px; font-size: 15px; color: var(--text-muted); line-height: 1.5;
}
.delete-modal-task-title {
  font-size: 16px; font-weight: 600; color: var(--text);
  background: var(--bg-subtle); padding: 16px; border-radius: 8px;
  margin: 16px 0 !important; word-break: break-word; border-left: 4px solid var(--c-red-t);
}
.delete-modal-warning {
  font-size: 13px; color: var(--c-red-t); margin-top: 16px !important;
  display: flex; gap: 8px; align-items: flex-start;
}
.delete-modal-warning::before {
  content: "⚠️"; flex-shrink: 0;
}
.delete-modal-footer {
  display: flex; gap: 12px; padding: 20px 32px 28px;
  border-top: 1px solid var(--border); justify-content: flex-end;
}
.delete-modal-footer .btn {
  padding: 10px 20px; border-radius: 6px; font-weight: 500; font-size: 14px;
  cursor: pointer; border: none; transition: all 0.2s;
}
.delete-modal-footer .btn--ghost {
  background: var(--bg-subtle); color: var(--text); min-width: 100px;
}
.delete-modal-footer .btn--ghost:hover {
  background: var(--bg-hover);
}
.delete-modal-footer .btn--danger {
  background: var(--c-red-t); color: white; min-width: 120px;
}
.delete-modal-footer .btn--danger:hover {
  background: #d32f2f; box-shadow: 0 4px 12px rgba(211, 47, 47, 0.3);
}
.form-row { display: flex; gap: 14px; }
.form-row > .field { flex: 1; }

/* ---------- Cards / panels ---------- */
.card {
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--bg); padding: 16px;
}
.empty {
  text-align: center; color: var(--text-faint);
  padding: 48px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg);
}
.empty .ico { font-size: 32px; display: block; margin-bottom: 8px; }

/* ---------- Flash ---------- */
.flash { margin: 10px 16px 0; }
.flash__item {
  padding: 9px 14px; border-radius: var(--radius); font-size: 14px; margin-bottom: 8px;
  border: 1px solid var(--border-strong);
}
.flash__item--notice { background: var(--c-green); color: var(--c-green-t); border-color: transparent; }
.flash__item--alert  { background: var(--c-red);   color: var(--c-red-t);   border-color: transparent; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: var(--bg-sidebar); padding: 24px; }
.auth__card {
  width: 100%; max-width: 360px; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px 28px; box-shadow: var(--shadow-md);
}
.auth__logo {
  width: 40px; height: 40px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px; margin: 0 auto 16px;
}
.auth__card h1 { font-size: 21px; text-align: center; margin-bottom: 4px; }
.auth__card p.sub { text-align: center; color: var(--text-muted); font-size: 14px; margin: 0 0 22px; }
.auth__card .btn { width: 100%; justify-content: center; }
.auth__alt { text-align: center; font-size: 13px; color: var(--text-muted); margin-top: 16px; }
.auth__alt a { color: var(--accent); }

/* password visibility toggle */
.password-field { position: relative; display: flex; align-items: center; }
.password-field .input { flex: 1; padding-right: 40px; }
.password-toggle-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 18px;
  padding: 4px; color: var(--text-muted); transition: color 0.2s;
}
.password-toggle-btn:hover { color: var(--text); }

/* ---------- Utility ---------- */
.row { display: flex; align-items: center; }
.gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.ml-auto { margin-left: auto; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.hidden { display: none !important; }
.progress { height: 6px; border-radius: 3px; background: var(--bg-active); overflow: hidden; min-width: 60px; display: inline-block; vertical-align: middle; width: 80px; }
.progress > span { display: block; height: 100%; background: var(--c-green-t); opacity: .55; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters .select { width: auto; min-width: 120px; padding: 5px 26px 5px 8px; font-size: 13px; }

/* ---------- Kanban board ---------- */
.board { display: flex; gap: 14px; align-items: flex-start; overflow-x: auto; padding-bottom: 24px; }
.board__col { background: var(--bg-subtle); border-radius: 8px; width: 290px; flex-shrink: 0; padding: 8px; }
.board__col-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; }
.board__count { color: var(--text-faint); font-size: 13px; }
.board__cards { display: flex; flex-direction: column; gap: 8px; min-height: 24px; }
.board__add { display: block; padding: 6px; margin-top: 6px; font-size: 13px; color: var(--text-faint); border-radius: 6px; }
.board__add:hover { background: var(--bg-hover); color: var(--text-muted); }

.card-task {
  background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  padding: 10px 11px; box-shadow: var(--shadow-sm); cursor: grab; display: block;
}
.card-task:hover { border-color: var(--border-strong); }
.card-task__title { font-weight: 500; font-size: 14px; margin-bottom: 8px; color: var(--text); }
.card-task__meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: var(--shadow-md); }
.is-dragging { cursor: grabbing; }

/* ---------- Calendar ---------- */
.cal { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.cal__dow { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--bg-subtle); }
.cal__dow span { padding: 7px 8px; font-size: 12px; color: var(--text-muted); text-align: right; border-right: 1px solid var(--border); }
.cal__dow span:last-child { border-right: 0; }
.cal__week { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal__day { min-height: 104px; border-right: 1px solid var(--border); border-top: 1px solid var(--border); padding: 5px 6px; overflow: hidden; }
.cal__week .cal__day:last-child { border-right: 0; }
.cal__day.is-other { background: var(--bg-subtle); }
.cal__daynum { font-size: 12px; color: var(--text-muted); text-align: right; }
.cal__day.is-today .cal__daynum { color: #fff; background: var(--accent); border-radius: 50%; width: 20px; height: 20px; display: inline-grid; place-items: center; float: right; }
.cal__event {
  display: block; font-size: 12px; background: var(--bg); border: 1px solid var(--border);
  border-left: 3px solid var(--c-blue-t); border-radius: 4px; padding: 2px 5px; margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; clear: both;
}
.cal__event:hover { background: var(--bg-hover); }

/* ---------- Detail (task / project show) ---------- */
.detail { display: grid; grid-template-columns: 1fr 300px; gap: 36px; align-items: start; }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } }
.props { display: grid; grid-template-columns: 130px 1fr; gap: 10px 14px; align-items: center; font-size: 14px; }
.props dt { color: var(--text-muted); }
.props dd { margin: 0; }
.panel-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin: 22px 0 10px; }

/* ---------- Activity feed ---------- */
.feed { font-size: 13.5px; }
.feed__item { display: flex; gap: 9px; padding: 8px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.feed__item:last-child { border-bottom: 0; }
.feed__body { min-width: 0; }
.feed__time { color: var(--text-faint); font-size: 12px; }

/* ---------- Inline status select ---------- */
/* Renders as a colored status pill (the `pill pill--<color>` class supplies the
   color) so the status reads at a glance. Mirrors `.cell-priority`; must NOT
   reset background/color or it would wash out the pill. */
.status-select {
  -webkit-appearance: none; appearance: none; border: 0; cursor: pointer;
  font: inherit; padding: 2px 9px; border-radius: 4px; flex: 0 0 auto;
}
.status-select:hover { filter: brightness(0.96); }

/* ---------- Quick add ---------- */
.quick-add td { padding-top: 4px; }
.quick-add input { border: 0; background: transparent; font: inherit; width: 100%; padding: 5px 10px; color: var(--text); }
.quick-add input:focus { outline: none; }
.quick-add input::placeholder { color: var(--text-faint); }

/* ---------- Assignee chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-subtle); border-radius: 14px; padding: 2px 6px 2px 2px; font-size: 13px; }
.chip form { margin: 0; display: inline-flex; }
.chip__x { border: 0; background: transparent; cursor: pointer; color: var(--text-faint); font-size: 13px; padding: 0 2px; }
.chip__x:hover { color: var(--c-red-t); }

/* ---------- Docs list ---------- */
.doclist { display: flex; flex-direction: column; }
.doc-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border-bottom: 1px solid var(--border); border-radius: 4px;
}
.doc-row:hover { background: var(--bg-subtle); }
.doc-row__icon { font-size: 18px; width: 22px; text-align: center; }
.doc-row__title { font-weight: 500; flex: 1; min-width: 0; }
.doc-row__meta { color: var(--text-faint); font-size: 13px; white-space: nowrap; }

/* ---------- Document editor ---------- */
.editor { max-width: 760px; margin: 0 auto; }
.editor__icon {
  position: relative; display: inline-flex; font-size: 56px; line-height: 1;
  margin-bottom: 6px; padding: 4px; border: 0; border-radius: 10px;
  background: transparent; cursor: pointer; transition: background .12s ease;
}
.editor__icon:hover { background: var(--bg-hover); }
.editor__icon-glyph { pointer-events: none; }
.emoji-popover {
  position: absolute; top: 100%; left: 0; z-index: 30; margin-top: 4px;
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  width: 320px; max-width: 88vw; padding: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
}
.emoji-popover__item {
  font-size: 22px; line-height: 1; padding: 6px; border: 0; border-radius: 8px;
  background: transparent; cursor: pointer; transition: background .1s ease;
}
.emoji-popover__item:hover { background: var(--bg-hover); }
.doc-title {
  font-size: 38px; font-weight: 700; letter-spacing: -0.01em; border: 0; outline: none;
  width: 100%; padding: 2px 0 8px; font-family: inherit; color: var(--text); background: transparent;
}
.doc-title:empty::before { content: "Untitled"; color: var(--text-faint); }
.doc-meta { color: var(--text-faint); font-size: 13px; margin-bottom: 18px; display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }

#document_blocks { padding-bottom: 40px; counter-reset: ol; }
.block--numbered { counter-increment: ol; }
.block--numbered .block__marker--num::before { content: counter(ol) "."; }
.block:not(.block--numbered) { counter-reset: ol; }
.block {
  display: flex; align-items: flex-start; gap: 2px;
  margin: 1px 0; position: relative; border-radius: 4px;
}
.block__handle {
  opacity: 0; flex: 0 0 22px; width: 22px; height: 26px; cursor: grab;
  color: var(--text-faint); display: grid; place-items: center; font-size: 14px;
  border-radius: 4px; user-select: none; margin-top: 2px;
}
.block:hover .block__handle { opacity: 1; }
.block__handle:hover { background: var(--bg-hover); }
.block__body { flex: 1; min-width: 0; }
.block__content {
  outline: none; padding: 3px 4px; border-radius: 4px; line-height: 1.6;
  min-height: 1.6em; word-break: break-word; white-space: pre-wrap;
}
.block__content:empty::before { content: attr(data-placeholder); color: var(--text-faint); pointer-events: none; }
.block--heading .block__content { font-size: 26px; font-weight: 700; padding-top: 8px; }
.block--heading.lvl-2 .block__content { font-size: 21px; }
.block--heading.lvl-3 .block__content { font-size: 18px; }
.block--bullet .block__body, .block--numbered .block__body, .block--todo .block__body { display: flex; gap: 8px; align-items: baseline; }
.block__marker { color: var(--text-muted); flex-shrink: 0; padding-top: 3px; user-select: none; }
.block--todo .block__marker { padding-top: 5px; }
.block--todo input[type=checkbox] { width: 16px; height: 16px; }
.block--todo.is-checked .block__content { color: var(--text-faint); text-decoration: line-through; }
/* Whole-line strike-through, toggled from the block menu (marks a line done). */
.block.is-struck .block__content { color: var(--text-faint); text-decoration: line-through; }
.block.is-struck .block__marker { color: var(--text-faint); }
.block--divider { padding: 8px 0; }
.block--divider hr { border: 0; border-top: 1px solid var(--border-strong); margin: 0; }
.block--image figure { margin: 0; }
.block--image img { max-width: 100%; border-radius: 6px; }
.block__caption { font-size: 13px; color: var(--text-muted); font-style: italic; margin-top: 6px; outline: none; }
.block--code pre { background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; }
.block--code code { font-family: monospace; font-size: 13px; color: var(--text); }
.block__content b, .block__content strong { font-weight: 700; }
.block__content i, .block__content em { font-style: italic; }
.block__content code { background: var(--bg-subtle); padding: 2px 4px; border-radius: 3px; font-family: monospace; font-size: 0.9em; }
.block__content s, .block__content strike { text-decoration: line-through; color: var(--text-faint); }
.block__content a { color: var(--accent); text-decoration: underline; cursor: pointer; }
.block--callout { border-left: 3px solid var(--accent); background: var(--bg-subtle); padding: 12px; border-radius: 4px; }
.block--callout-content { margin: 0; }
.block--quote { border-left: 3px solid var(--text-muted); color: var(--text-muted); font-style: italic; padding-left: 12px; }
.block--quote-content { margin: 0; }
.block__upload { border: 1px dashed var(--border-strong); border-radius: 6px; padding: 14px; color: var(--text-muted); font-size: 14px; }

.add-block { color: var(--text-faint); padding: 6px 4px; font-size: 14px; cursor: pointer; border-radius: 4px; display: inline-flex; gap: 6px; }
.add-block:hover { background: var(--bg-hover); color: var(--text-muted); }

/* quick-add inline fields */
.quick-add-input { width: 100%; padding: 6px; border: 1px solid transparent; background: transparent; font-size: 13px; outline: none; }
.quick-add-input:focus { border-color: var(--accent); background: var(--bg-subtle); border-radius: 4px; }
.quick-add-input::placeholder { color: var(--text-faint); }

/* quick-add assignees */
.quick-add-status-select {
  border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px;
  font-size: 13px; background: var(--bg); color: var(--text); cursor: pointer;
  transition: all 0.2s;
}
.quick-add-status-select:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.quick-add-assignees-btn {
  background: var(--bg-subtle); border: 1px solid var(--border); border-radius: 4px;
  padding: 6px 10px; font-size: 13px; cursor: pointer; color: var(--text-muted);
  transition: all 0.2s; white-space: nowrap;
}
.quick-add-assignees-btn:hover { background: var(--bg-hover); color: var(--text); }

.quick-add-avatars-display {
  margin-bottom: 6px;
}

.quick-add-assignees-popup {
  position: absolute; top: calc(100% + 8px); right: 0; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); padding: 12px 0; min-width: 260px;
  z-index: 100;
}
.quick-add-assignees-popup.hidden { display: none; }

.quick-add-assignees-header {
  padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12px;
  color: var(--text-muted); font-weight: 500;
}

.quick-add-assignees-list {
  max-height: 320px; overflow-y: auto;
}

.quick-add-assignee-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 4px;
  cursor: pointer; font-size: 13px; transition: background 0.15s;
}
.quick-add-assignee-item:hover { background: var(--bg-subtle); }
.quick-add-assignee-item input[type="checkbox"] {
  cursor: pointer; flex-shrink: 0; width: 16px; height: 16px;
}
.quick-add-assignee-avatar {
  flex-shrink: 0; font-size: 11px; font-weight: 600;
}
.assignee-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* block type popover */
.block-menu { position: relative; }
.block-menu__pop {
  position: absolute; top: 26px; left: 0; z-index: 30; width: 190px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-md); padding: 6px;
}
.block-menu__pop button {
  display: flex; width: 100%; align-items: center; gap: 8px; padding: 6px 8px;
  border: 0; background: transparent; cursor: pointer; font: inherit; color: var(--text);
  border-radius: 5px; text-align: left;
}
.block-menu__pop button:hover { background: var(--bg-hover); }
.block-menu__pop hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }

/* slash command menu */
.block-slash-menu {
  position: absolute; top: 26px; left: 0; z-index: 30; width: 240px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-md); padding: 8px;
}
.block-slash-menu__input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px;
  font-size: 13px; margin-bottom: 8px;
}
.block-slash-menu__items { max-height: 200px; overflow-y: auto; }
.block-slash-menu__item {
  display: flex; width: 100%; padding: 6px 8px; border: 0; background: transparent;
  cursor: pointer; font: inherit; color: var(--text); border-radius: 5px; text-align: left;
  font-size: 13px;
}
.block-slash-menu__item:hover { background: var(--bg-hover); }
.block-slash-menu__item.hidden { display: none; }

/* comments */
.comment { display: flex; gap: 9px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.comment__body { min-width: 0; flex: 1; }
.comment__meta { font-size: 12px; color: var(--text-faint); }

/* ---------- Inline-editable task rows ---------- */
/* Project column is redundant in the grouped-by-project view. */
.tbl--grouped .col-project { display: none; }

/* Suggested-order rank: a CSS counter numbers the flat all-tasks view 1..n so
   it survives Turbo-Stream row replacement without server-side bookkeeping.
   The rank column is hidden in the grouped (by-project) view. */
.cell-rank {
  width: 34px; text-align: right; color: var(--text-faint);
  font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tbl--ranked tbody { counter-reset: rank; }
.tbl--ranked tbody > tr { counter-increment: rank; }
.tbl--ranked tbody > tr.quick-add { counter-increment: none; }
.tbl--ranked .cell-rank::before { content: counter(rank); }
.tbl--ranked tbody > tr.quick-add .cell-rank::before { content: ""; }
.tbl--grouped .cell-rank { display: none; }

/* Completed tasks sink to the bottom of the suggested order and read as done. */
.tbl tr.row--done .cell-input--title { text-decoration: line-through; color: var(--text-faint); }

/* "What to do next" legend above the flat all-tasks table. */
.order-legend {
  margin: 0 0 12px; font-size: 13px; color: var(--text-muted); line-height: 1.5;
}
.order-legend__title { font-weight: 600; color: var(--text); }
.order-legend a, .order-legend__link { color: var(--accent); }

.cell-task { display: flex; align-items: center; gap: 4px; }
.cell-open {
  flex: 0 0 auto; color: var(--text-muted); text-decoration: none; font-size: 13px;
  line-height: 1; padding: 2px 3px; border-radius: 4px; opacity: 0; transition: opacity .12s;
}
.tbl tbody tr:hover .cell-open { opacity: 1; }
.cell-open:hover { color: var(--text); background: var(--bg-hover); }

.cell-task__main { display: flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; margin: 0; }

/* Borderless inputs that read as plain text until hovered / focused. */
.cell-input {
  border: 1px solid transparent; background: transparent; font: inherit; color: inherit;
  padding: 3px 6px; border-radius: 5px; width: 100%; min-width: 0;
}
.cell-input:hover { background: var(--bg-hover); }
.cell-input:focus { outline: none; background: var(--bg); border-color: var(--border); }
.cell-input--title { font-weight: 500; }
.cell-input--date { width: auto; max-width: 150px; }
.cell-input--date.is-overdue { color: var(--c-red-t); font-weight: 500; }
.cell-input--tags { color: var(--text-muted); }

/* Blank due-date cell: a faint "—" overlaying a transparent, clickable date input. */
.cell-date-empty { position: relative; display: inline-flex; align-items: center; min-width: 24px; cursor: pointer; }
.cell-date-hidden { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer; }

.cell-priority {
  -webkit-appearance: none; appearance: none; border: 0; cursor: pointer; font: inherit;
  padding: 2px 9px; border-radius: 999px; flex: 0 0 auto;
}

/* Inline assignee popup */
.cell-assignees { position: relative; }
.cell-assignees__btn { border: 0; background: transparent; cursor: pointer; padding: 2px 4px; border-radius: 5px; }
.cell-assignees__btn:hover { background: var(--bg-hover); }
.cell-assignees__popup {
  position: absolute; z-index: 100; top: calc(100% + 4px); left: 0; min-width: 210px;
  max-height: 260px; overflow-y: auto; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-md); padding: 6px;
}
.cell-assignees__popup.hidden { display: none; }
.cell-assignees__item {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px;
  cursor: pointer; font-size: 13px; white-space: nowrap;
}
.cell-assignees__item:hover { background: var(--bg-subtle); }
.cell-assignees__item input[type="checkbox"] { cursor: pointer; flex-shrink: 0; }

/* ---------- Collapsible project sections (tasks view) ---------- */
.proj-group__head {
  margin: 22px 0 6px; padding: 4px 6px; border-radius: 6px;
  cursor: pointer; user-select: none; transition: background .12s ease;
}
.proj-group__head:hover { background: var(--bg-hover); }
.proj-group__head:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.proj-group__toggle {
  display: inline-flex; color: var(--text-faint); font-size: 13px; line-height: 1;
  transition: transform .15s ease; transform: rotate(90deg); /* expanded → caret points down */
}
.proj-group.is-collapsed .proj-group__toggle { transform: rotate(0deg); } /* collapsed → points right */
.proj-group.is-collapsed .proj-group__body { display: none; }

/* ============================================================
   Mobile / responsive
   ============================================================ */

/* Mobile top bar + off-canvas sidebar drawer — hidden on desktop. */
.mobile-bar { display: none; }
.nav-overlay { display: none; }

@media (max-width: 768px) {
  /* Fixed top bar with the hamburger; the sidebar slides in over content. */
  .mobile-bar {
    display: flex; align-items: center; gap: 10px;
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    height: 52px; padding: 0 12px;
    background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
  }
  .mobile-bar__btn {
    border: 0; background: transparent; font-size: 22px; line-height: 1;
    padding: 8px 10px; border-radius: var(--radius); cursor: pointer; color: var(--text);
  }
  .mobile-bar__btn:active { background: var(--bg-hover); }
  .mobile-bar__title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
  .mobile-bar__title .logo {
    width: 22px; height: 22px; border-radius: 5px; background: var(--accent); color: #fff;
    display: grid; place-items: center; font-size: 13px; font-weight: 700;
  }

  .app__main { padding-top: 52px; }

  /* No hover on touch: keep the block ⠿ handle visible so its menu (Strike
     through, change type, delete) is reachable on a phone. */
  .block__handle { opacity: .5; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1200;
    width: 270px; max-width: 84vw; height: 100dvh;
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--shadow-md);
  }
  .app.is-nav-open .sidebar { transform: translateX(0); }

  .nav-overlay {
    display: block; position: fixed; inset: 0; z-index: 1100;
    background: rgba(0, 0, 0, .4); opacity: 0; visibility: hidden; transition: opacity .2s;
  }
  .app.is-nav-open .nav-overlay { opacity: 1; visibility: visible; }
}

@media (max-width: 640px) {
  .page { padding: 12px 16px 56px; }
  .page__title { font-size: 24px; }
  .page__icon { font-size: 24px; }
  .page__head { gap: 8px; margin: 8px 0 6px; }
  .page-topbar { margin: -12px -16px 0; padding-left: 16px; }

  /* Full-width primary actions in page heads are easier to tap. */
  .page__head .btn.ml-auto { padding: 8px 12px; }

  /* Plain tables (admin, projects) keep a horizontal scroll. */
  .tbl-wrap .tbl:not(.tbl--ranked):not(.tbl--grouped) { min-width: 680px; }

  /* ---- Task tables become stacked, labeled cards on phones ---- */
  .tbl--ranked, .tbl--grouped,
  .tbl--ranked tbody, .tbl--grouped tbody,
  .tbl--ranked tr, .tbl--grouped tr,
  .tbl--ranked td, .tbl--grouped td { display: block; }
  .tbl--ranked thead, .tbl--grouped thead { display: none; }
  .tbl--ranked, .tbl--grouped {
    min-width: 0; border: 0; background: transparent; overflow: visible;
  }

  .tbl--ranked tbody tr, .tbl--grouped tbody tr {
    position: relative; background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    margin-bottom: 10px; padding: 10px 12px;
  }
  .tbl--ranked tbody td, .tbl--grouped tbody td { padding: 0; border: 0; }

  /* Headline: the task title, full width and prominent. */
  .tbl--ranked tbody td.tcell--task, .tbl--grouped tbody td.tcell--task { padding-right: 26px; }
  .tbl--ranked tbody td.tcell--task .cell-input--title,
  .tbl--grouped tbody td.tcell--task .cell-input--title { font-size: 16px; font-weight: 600; }

  /* Suggested-order rank as a small corner badge (flat view only). */
  .tbl--ranked tbody td.cell-rank {
    position: absolute; top: 11px; right: 12px; width: auto;
    color: var(--text-faint); font-size: 12px;
  }

  /* Each meta value gets a label so a bare pill/date has context. */
  .tbl--ranked tbody td.tcell--meta, .tbl--grouped tbody td.tcell--meta {
    display: flex; align-items: center; gap: 10px;
    min-height: 34px; padding: 4px 0; border-top: 1px solid var(--bg-subtle);
  }
  .tbl--ranked tbody td.tcell--meta::before,
  .tbl--grouped tbody td.tcell--meta::before {
    content: attr(data-label); flex: 0 0 78px;
    color: var(--text-faint); font-size: 12px; font-weight: 500;
  }
  /* Keep the project + rank columns hidden in the grouped (by-project) view. */
  .tbl--grouped tbody td.col-project, .tbl--grouped tbody td.cell-rank { display: none; }

  /* Stack two-up form rows and assignee grids on narrow screens. */
  .form-row { flex-direction: column; gap: 0; }
  .assignees-checkboxes { grid-template-columns: 1fr; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1; justify-content: center; }

  /* Tighter calendar so a month fits a phone width. */
  .cal__day { min-height: 64px; padding: 3px 4px; }
  .cal__event { font-size: 11px; }
  .cal__dow span { padding: 5px 4px; font-size: 11px; }

  /* Roomier modal on small screens. */
  .delete-modal-header { padding: 20px 20px 16px; }
  .delete-modal-body { padding: 18px 20px; }
  .delete-modal-footer { padding: 16px 20px 22px; flex-direction: column-reverse; }
  .delete-modal-footer .btn { width: 100%; }
}

/* Prevent iOS Safari from auto-zooming when focusing a sub-16px field. */
@media (max-width: 768px) {
  .input, .select, .textarea,
  .cell-input, .quick-add-input, .quick-add-status-select,
  .status-select, .cell-priority, .tag-input-field,
  input[type="date"], input[type="text"], input[type="email"],
  input[type="password"], input[type="search"], select, textarea {
    font-size: 16px;
  }
}
