:root {
  --bg: #f6f3ec;
  --ink: #16202e;
  --ink-mid: #4c5663;
  --ink-muted: #8a8d93;
  --rule: #ddd7ca;
  --rule-soft: #ebe7dd;
  --card: #fff;
  --accent: #b06036;
  --accent-ink: #fff;
  --lime: #c2703f;
  --danger: #a23b3b;
  --today: #f4ece0;

  /* Event type palette — muted, print-friendly */
  --c-visit:      #5b7a4a;
  --c-delivery:   #6e5a8a;
  --c-trade_day:  #b88a2b;
  --c-inspection: #3a6b85;
  --c-decision:   #4a7676;
  --c-snag:       #a64646;
  --c-payment:    #3d7558;
  --c-milestone:  #16202e;
  --c-doc:        #75695a;
  --c-note:       #8a8478;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.muted { color: var(--ink-muted); font-size: 0.9em; }
.hidden { display: none !important; }

/* ── Top bar ── */
/* Desktop: [brand] [actions →] [user]. Mobile: row1 brand+user, row2 actions (scrollable). */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: var(--card); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 10;
}
.topbar-actions {
  display: flex; gap: 0.45rem; align-items: center; margin-left: auto;
  order: 2;
}
.topbar-user { display: flex; gap: 0.45rem; align-items: center; order: 3; }
.topbar-user .who { color: var(--ink-muted); font-size: 0.85em; }
.brand { order: 1; font-weight: 600; letter-spacing: 0.01em; display: flex; align-items: center; gap: 0.55rem; min-width: 0; flex: 1 1 0; }
.brand-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 6px;
  text-decoration: none; color: var(--ink-mid); font-size: 1rem;
  transition: background .12s, color .12s;
}
.back-link:hover { background: var(--rule-soft); color: var(--ink); }
.topbar-tools { display: flex; gap: 0.7rem; align-items: center; margin-left: auto; order: 3; }
.topbar-tools .who { color: var(--ink-muted); font-size: 0.85em; }
#search {
  padding: 0.4rem 0.7rem; border: 1px solid transparent; border-radius: 6px;
  background: var(--bg); font: inherit; min-width: 180px;
  transition: border-color .12s, background .12s;
}
.pill-toggle {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.32rem 0.7rem; border: 1px solid var(--rule); border-radius: 999px;
  font-size: 0.85em; color: var(--ink-mid); cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
  user-select: none;
}
.pill-toggle input { display: none; }
.pill-toggle:hover { background: var(--rule-soft); color: var(--ink); }
.pill-toggle:has(input:checked) {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.chip-outline {
  display: inline-block; padding: 0.08rem 0.55rem; border-radius: 999px;
  font-size: 0.72em; color: var(--ink-mid);
  background: transparent; border: 1px solid var(--rule);
}
button.pill-toggle { font: inherit; background: transparent; }
.invite-row { display: flex; gap: 0.5rem; margin: 0.6rem 0 0.3rem; }
.invite-row input {
  flex: 1; padding: 0.55rem 0.7rem; border: 1px solid var(--rule); border-radius: 6px;
  font: inherit; font-size: 0.85em; color: var(--ink); background: var(--bg);
}
.invite-row button {
  padding: 0.5rem 0.9rem; border-radius: 6px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; white-space: nowrap;
}
.members-section { margin-top: 1rem; border-top: 1px solid var(--rule-soft); padding-top: 0.7rem; }
.members-section h3 { margin: 0 0 0.15rem; font-size: 0.95em; }
.members-pm-note { margin: 0 0 0.5rem; font-size: 0.82em; }
.member-list { display: flex; flex-direction: column; gap: 0.15rem; max-height: 200px; overflow-y: auto; }
.member-row {
  display: flex; align-items: baseline; gap: 0.5rem;
  padding: 0.35rem 0.2rem; border-radius: 6px; font-size: 0.92em;
}
.member-row:hover { background: var(--rule-soft); }
.member-name { font-weight: 500; }
.member-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85em; }
.member-remove {
  background: none; border: 0; color: var(--ink-muted); cursor: pointer;
  padding: 0.25rem 0.45rem; border-radius: 4px; font-size: 0.85em;
}
.member-remove:hover { color: var(--danger); background: #fbeaea; }
.member-empty { padding: 0.3rem 0.2rem; font-size: 0.88em; }
#search:hover { border-color: var(--rule); }
#search:focus { outline: none; background: var(--card); border-color: var(--lime); }
.logout-form { margin: 0; }
button.link, button.icon {
  background: none; border: 0; color: var(--ink-mid); cursor: pointer;
  padding: 0.3rem 0.5rem; border-radius: 4px; font: inherit;
}
button.link:hover, button.icon:hover { background: var(--bg); color: var(--ink); }

main { padding: 0.75rem; max-width: 1280px; margin: 0 auto; }

/* ── Dashboard ── */
.dash { padding: 1.5rem 1rem; max-width: 1100px; }
.dash-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem;
}
.dash-head h1 { margin: 0; font-size: 1.4rem; font-weight: 600; letter-spacing: 0.01em; }
button.primary {
  background: var(--accent); color: #fff; border: 0;
  padding: 0.5rem 0.95rem; border-radius: 6px; font: inherit; font-weight: 500;
  cursor: pointer;
}
button.primary:hover { background: #8f4c2b; }
.tiles {
  display: grid; gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.tile {
  position: relative;
  display: block; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px;
  padding: 1rem 1.1rem;
  transition: border-color .12s, transform .12s, box-shadow .12s;
}
.tile:hover { border-color: var(--accent); box-shadow: 0 4px 14px rgba(0,0,0,.06); transform: translateY(-1px); }
.tile-name { font-size: 1.05rem; font-weight: 600; margin-bottom: 0.35rem; }
.tile-meta { font-size: 0.85em; color: var(--ink-mid); display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tile-cost { color: var(--accent); font-weight: 600; }
.tile-edit {
  position: absolute; top: 0.5rem; right: 0.5rem;
  width: 28px; height: 28px; border-radius: 6px;
  background: transparent; border: 0; color: var(--ink-muted);
  font-size: 0.85rem; cursor: pointer;
  opacity: 0; transition: opacity .12s, background .12s;
}
.tile:hover .tile-edit { opacity: 1; }
.tile-edit:hover { background: var(--rule-soft); color: var(--ink); }
.empty {
  background: var(--card); border: 1px dashed var(--rule); border-radius: 10px;
  padding: 2.5rem 1.5rem; text-align: center; color: var(--ink-mid);
}
@media (max-width: 700px) {
  .dash { padding: 1rem 0.7rem; }
  .tile-edit { opacity: 1; }
}

/* ── Auth ── */
body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.card {
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px;
  padding: 2rem; width: 100%; max-width: 380px;
  box-shadow: 0 1px 2px rgba(0,0,0,.02);
}
.card h1 { margin: 0 0 0.25rem; }
form label { display: block; margin: 0.7rem 0; font-size: 0.85em; color: var(--ink-mid); }
form label > span { display: block; margin-bottom: 0.2rem; }
form input, form select, form textarea {
  display: block; width: 100%; padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule); border-radius: 6px; background: var(--card);
  font: inherit; color: var(--ink);
}
form input:focus, form select:focus, form textarea:focus {
  outline: none; border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(176, 96, 54, 0.18);
}
form button[type=submit] {
  display: block; width: 100%; padding: 0.65rem;
  background: var(--accent); color: var(--accent-ink); border: 0;
  border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer;
  margin-top: 1rem;
}
.error {
  background: #fbeaea; border: 1px solid #e7c0c0; color: var(--danger);
  padding: 0.5rem 0.7rem; border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9em;
}

/* ── Modal ── */
.modal {
  position: fixed; inset: 0; background: rgba(20, 25, 22, 0.4);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 90;
  backdrop-filter: blur(3px);
}
.modal-card {
  background: var(--card); border-radius: 12px; padding: 1.1rem 1.35rem 1.25rem;
  width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  box-shadow: 0 14px 40px rgba(0,0,0,.18);
  animation: pop-in .12s ease-out;
}
@keyframes pop-in { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.modal-head h2 { margin: 0; font-size: 1rem; font-weight: 600; }
.modal-card .row { display: flex; gap: 0.5rem; }
.modal-card .row > label { flex: 1; }
.modal-card label.big input { font-size: 1.05rem; padding: 0.65rem 0.8rem; }
.checkbox-row {
  display: flex !important; flex-direction: row !important; align-items: center;
  gap: 0.4rem; align-self: flex-end; padding-bottom: 0.55rem;
}
.checkbox-row input { width: auto !important; margin: 0 !important; }
.checkbox-row span { margin: 0 !important; color: var(--ink); }
.assignee-group { margin: 0.7rem 0; }
.assignee-group .field-label { display: block; font-size: 0.85em; color: var(--ink-mid); margin-bottom: 0.3rem; }
.assignee-checks { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.assignee-checks .check {
  display: inline-flex; align-items: center; gap: 0.35rem; margin: 0;
  padding: 0.35rem 0.7rem; border: 1px solid var(--rule); border-radius: 999px;
  cursor: pointer; font-size: 0.88em; color: var(--ink-mid); user-select: none;
  transition: background .12s, color .12s, border-color .12s;
}
.assignee-checks .check input { display: none; }
.assignee-checks .check:hover { background: var(--rule-soft); }
.assignee-checks .check:has(input:checked) {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.modal-card .actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem;
}
.modal-card .actions button {
  padding: 0.5rem 1rem; border-radius: 6px; border: 0; font: inherit; cursor: pointer;
}
.modal-card .actions button[type=submit] { background: var(--accent); color: #fff; font-weight: 600; }
.modal-card .actions button.ghost { background: var(--rule-soft); color: var(--ink-mid); }
.modal-card .actions button.danger { background: var(--danger); color: #fff; margin-right: auto; }

/* ── Popover ── */
.popover {
  position: fixed; inset: 0; background: rgba(20,25,22,0.15);
  display: flex; align-items: center; justify-content: center; z-index: 80;
}
.popover-card {
  background: var(--card); border-radius: 10px; padding: 0.85rem 1rem;
  width: 400px; max-width: 92vw;
  max-height: 85vh; overflow-y: auto;
  box-shadow: 0 10px 28px rgba(0,0,0,.18);
  border: 1px solid var(--rule);
}
.popover-head { display: flex; align-items: center; gap: 0.5rem; }
.popover-head strong { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.popover-meta { display: flex; gap: 0.5rem; align-items: center; margin: 0.35rem 0 0.5rem; flex-wrap: wrap; }
.popover-meta span:first-child { color: var(--ink-mid); font-size: 0.88em; }
.popover-notes {
  white-space: pre-wrap; color: var(--ink-mid); font-size: 0.9em;
  margin: 0.3rem 0 0.7rem; max-height: 120px; overflow: auto;
}
.popover-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
.popover-actions button { padding: 0.4rem 0.85rem; border-radius: 5px; border: 0; cursor: pointer; font: inherit; }
.popover-actions button#pop-edit { background: var(--accent); color: #fff; }
.popover-actions button.ghost { background: var(--rule-soft); color: var(--ink-mid); }
.popover-actions button.ghost.danger { background: transparent; color: var(--danger); }
.chip {
  display: inline-block; padding: 0.08rem 0.55rem; border-radius: 999px;
  font-size: 0.72em; text-transform: lowercase; letter-spacing: 0.02em;
  color: #fff; background: var(--c-note);
}
.ev-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--c-note); display: inline-block; }

/* ── People / human resources ── */
.topnav-link {
  color: var(--ink-mid); text-decoration: none; font-size: 0.9rem;
  padding: 0.3rem 0.55rem; border-radius: 6px;
}
.topnav-link:hover { background: var(--rule-soft); color: var(--ink); }
.people-intro { margin: -0.3rem 0 1.1rem; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1.1rem; }
.filter-chip {
  padding: 0.3rem 0.8rem; border-radius: 999px; border: 1px solid var(--rule);
  background: var(--card); color: var(--ink-mid); cursor: pointer;
  font: inherit; font-size: 0.85em; text-transform: lowercase;
}
.filter-chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.people-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.9rem;
}
.person-card {
  background: var(--card); border: 1px solid var(--rule); border-radius: 12px;
  padding: 0.9rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.55rem;
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.person-card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.person-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.person-name { font-weight: 600; }
.person-email { color: var(--ink-mid); font-size: 0.85em; text-decoration: none; }
.person-email:hover { text-decoration: underline; }
.person-edit { position: static; opacity: 0.55; flex: none; }
.person-card:hover .person-edit { opacity: 1; }
.person-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.person-notes { white-space: pre-wrap; color: var(--ink-mid); font-size: 0.9em; }
.person-projects { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.1rem; }
.proj-tag {
  font-size: 0.75em; color: var(--ink-mid); border: 1px solid var(--rule);
  border-radius: 6px; padding: 0.05rem 0.4rem; text-decoration: none;
}
.proj-tag:hover { background: var(--rule-soft); }
.small { font-size: 0.85em; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.4rem; }
.chip.removable {
  background: var(--accent); display: inline-flex; align-items: center; gap: 0.2rem;
  text-transform: none;
}
.chip.removable button {
  background: none; border: 0; color: #fff; cursor: pointer;
  font-size: 1.05em; line-height: 1; padding: 0;
}
.tag-suggest { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.5rem; }
.tag-sugg {
  background: var(--rule-soft); border: 0; border-radius: 999px;
  padding: 0.2rem 0.6rem; font: inherit; font-size: 0.8em; color: var(--ink-mid); cursor: pointer;
}
.tag-sugg:hover { color: var(--ink); }

/* Event type colours — applied to chip, dot, and FC events */
.ev-type-visit      { background-color: var(--c-visit); }
.ev-type-delivery   { background-color: var(--c-delivery); }
.ev-type-trade_day  { background-color: var(--c-trade_day); }
.ev-type-inspection { background-color: var(--c-inspection); }
.ev-type-decision   { background-color: var(--c-decision); }
.ev-type-snag       { background-color: var(--c-snag); }
.ev-type-payment    { background-color: var(--c-payment); }
.ev-type-milestone  { background-color: var(--c-milestone); }
.ev-type-doc        { background-color: var(--c-doc); }
.ev-type-note       { background-color: var(--c-note); }

/* ── FAB ── */
#fab {
  position: fixed; right: 1.1rem; bottom: 1.1rem; width: 54px; height: 54px;
  border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 26px; line-height: 1;
  box-shadow: 0 6px 14px rgba(0,0,0,.22); z-index: 70;
  transition: transform .12s, background .12s;
}
#fab:hover { background: #8f4c2b; transform: translateY(-1px); }

/* ── Calendar surface ── */
#calendar {
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px;
  padding: 0.5rem 0.75rem 0.75rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.02);
}

/* FullCalendar theme override — quiet, clean */
.fc { font-size: 0.9em; --fc-border-color: var(--rule-soft); --fc-page-bg-color: var(--card);
      --fc-neutral-bg-color: var(--bg); --fc-list-event-hover-bg-color: var(--rule-soft);
      --fc-today-bg-color: var(--today); }
.fc .fc-toolbar { margin-bottom: 0.6rem; }
.fc .fc-toolbar-title { font-size: 1.05rem; font-weight: 600; letter-spacing: 0.01em; }

/* Toolbar buttons */
.fc .fc-button {
  background: transparent !important; color: var(--ink-mid) !important;
  border: 1px solid var(--rule) !important; padding: 0.3rem 0.65rem !important;
  font-weight: 500 !important; font-size: 0.85em !important;
  text-transform: none !important; letter-spacing: 0 !important;
  box-shadow: none !important; border-radius: 6px !important;
}
.fc .fc-button:focus { outline: none !important; box-shadow: 0 0 0 3px rgba(176,96,54,.22) !important; }
.fc .fc-button:hover { color: var(--ink) !important; background: var(--rule-soft) !important; }
.fc .fc-button-group .fc-button { border-radius: 0 !important; margin: 0 !important; }
.fc .fc-button-group .fc-button:first-child { border-top-left-radius: 6px !important; border-bottom-left-radius: 6px !important; }
.fc .fc-button-group .fc-button:last-child  { border-top-right-radius: 6px !important; border-bottom-right-radius: 6px !important; }
.fc .fc-button-group .fc-button + .fc-button { border-left: 0 !important; }
.fc .fc-button-primary:not(:disabled).fc-button-active,
.fc .fc-button-primary:not(:disabled):active {
  background: var(--ink) !important; color: #fff !important; border-color: var(--ink) !important;
}
.fc .fc-today-button:disabled { opacity: 0.5; }

/* Headers and days */
.fc th { font-weight: 500; }
.fc .fc-col-header-cell-cushion,
.fc .fc-daygrid-day-number {
  color: var(--ink-mid); text-decoration: none; padding: 4px 6px; font-size: 0.85em;
}
.fc .fc-col-header-cell-cushion { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.72em; }
.fc .fc-day-today .fc-daygrid-day-number { color: var(--accent); font-weight: 600; }
.fc .fc-day-today { background: var(--today) !important; }

/* Time grid */
.fc .fc-timegrid-slot { height: 2.3em; border-color: var(--rule-soft) !important; }
.fc .fc-timegrid-slot-label-cushion { color: var(--ink-muted); font-size: 0.75em; padding-right: 6px; }
.fc .fc-timegrid-axis-cushion { color: var(--ink-muted); font-size: 0.7em; }
.fc .fc-timegrid-now-indicator-line { border-color: var(--danger); }
.fc .fc-timegrid-now-indicator-arrow { border-color: var(--danger); color: var(--danger); }
.fc .fc-scrollgrid { border-color: var(--rule-soft) !important; }
.fc .fc-scrollgrid td, .fc .fc-scrollgrid th { border-color: var(--rule-soft) !important; }

/* Events */
.fc .fc-event {
  border: 0; padding: 2px 6px; font-size: 0.85em; cursor: pointer;
  border-radius: 4px; box-shadow: inset 3px 0 0 rgba(0,0,0,.18);
}
.fc-event.ev-type-visit      { background: var(--c-visit) !important; }
.fc-event.ev-type-delivery   { background: var(--c-delivery) !important; }
.fc-event.ev-type-trade_day  { background: var(--c-trade_day) !important; }
.fc-event.ev-type-inspection { background: var(--c-inspection) !important; }
.fc-event.ev-type-decision   { background: var(--c-decision) !important; }
.fc-event.ev-type-snag       { background: var(--c-snag) !important; }
.fc-event.ev-type-payment    { background: var(--c-payment) !important; }
.fc-event.ev-type-milestone  { background: var(--c-milestone) !important; }
.fc-event.ev-type-doc        { background: var(--c-doc) !important; }
.fc-event.ev-type-note       { background: var(--c-note) !important; }
.fc-event .fc-event-main, .fc-event .fc-event-title, .fc-event .fc-event-time { color: #fff; }
.fc-event:hover { filter: brightness(1.05); }

/* All-day slot */
.fc .fc-timegrid-axis-cushion.fc-scrollgrid-shrink-cushion { font-size: 0.7em; color: var(--ink-muted); }

/* ── Done state + photos ── */
.fc-event.ev-done { opacity: 0.55; }
.fc-event.ev-done .fc-event-title { text-decoration: line-through; }
/* Cancelled: kept on the calendar but visibly struck out */
.fc-event.ev-cancelled { opacity: 0.5; }
.fc-event.ev-cancelled .fc-event-title,
.fc-event.ev-cancelled .fc-event-time { text-decoration: line-through; }
.fc-event.ev-cancelled .fc-event-main { font-style: italic; }
.chip-cancelled { color: var(--danger); border-color: var(--danger); }
#pop-cancel.is-cancelled { background: var(--danger) !important; color: #fff !important; }
.done-btn {
  background: var(--rule-soft) !important; color: var(--accent) !important;
  font-weight: 600;
}
.done-btn.is-done { background: var(--accent) !important; color: #fff !important; }
.pop-photos { margin: 0.4rem 0 0.6rem; }
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 0.35rem; margin-bottom: 0.45rem;
}
.photo-thumb {
  display: block; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--rule);
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.add-photo {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.35rem 0.75rem; border: 1px dashed var(--rule); border-radius: 6px;
  color: var(--ink-mid); font-size: 0.85em; cursor: pointer;
}
.add-photo:hover { border-color: var(--accent); color: var(--accent); }
.add-photo.disabled { opacity: 0.45; pointer-events: none; }
#photo-status { display: block; margin-top: 0.25rem; font-size: 0.8em; }

/* ── Comments ── */
.pop-comments { margin: 0.5rem 0 0.6rem; border-top: 1px solid var(--rule-soft); padding-top: 0.5rem; }
.comment-list { max-height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.45rem; margin-bottom: 0.5rem; }
.comment { font-size: 0.88em; }
.comment-head { display: flex; align-items: baseline; gap: 0.45rem; }
.comment-head strong { font-size: 0.92em; }
.comment-head .muted { font-size: 0.8em; }
.comment-del {
  margin-left: auto; background: none; border: 0; color: var(--ink-muted);
  cursor: pointer; font-size: 0.75em; padding: 0 0.2rem;
}
.comment-del:hover { color: var(--danger); }
.comment-body { color: var(--ink-mid); white-space: pre-wrap; word-break: break-word; }
.comment-form { display: flex; gap: 0.4rem; }
.comment-form input {
  flex: 1; min-width: 0; width: auto; display: inline-block;
  padding: 0.45rem 0.65rem; border: 1px solid var(--rule); border-radius: 6px;
  font: inherit; font-size: 0.88em; background: var(--bg);
}
.comment-form button[type=submit] {
  display: inline-block; width: auto; flex-shrink: 0; margin-top: 0;
}
.comment-form input:focus { outline: none; border-color: var(--lime); background: var(--card); }
.comment-form button {
  padding: 0.45rem 0.8rem; border: 0; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-size: 0.85em;
}

/* ── Files page ── */
a.pill-toggle { text-decoration: none; }
.files-page { max-width: 900px; }
.files-head {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  flex-wrap: wrap; margin-bottom: 0.75rem;
}
.folder-tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.folder-tab {
  padding: 0.35rem 0.8rem; border: 1px solid var(--rule); border-radius: 999px;
  background: transparent; color: var(--ink-mid); font: inherit; font-size: 0.85em;
  cursor: pointer;
}
.folder-tab:hover { background: var(--rule-soft); }
.folder-tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.files-actions { display: flex; gap: 0.5rem; align-items: center; }
.files-actions input[type=text] {
  padding: 0.45rem 0.7rem; border: 1px solid var(--rule); border-radius: 6px;
  font: inherit; font-size: 0.88em; background: var(--card); width: 160px;
}
.upload-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.45rem 0.95rem; border-radius: 6px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 0.9em; white-space: nowrap;
}
.upload-btn:hover { background: #8f4c2b; }
.file-list { display: flex; flex-direction: column; }
.file-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.65rem; background: var(--card);
  border: 1px solid var(--rule); border-top-width: 0;
}
.file-row:first-child { border-top-width: 1px; border-radius: 8px 8px 0 0; }
.file-row:last-child { border-radius: 0 0 8px 8px; }
.file-row:only-child { border-radius: 8px; }
/* Sections as drop areas (grouped All view) */
.file-section { margin-bottom: 1rem; border-radius: 10px; }
.file-section.drop-over { outline: 2px dashed var(--accent); outline-offset: 3px; background: var(--rule-soft); }
.file-section-head {
  display: flex; align-items: baseline; gap: 0.1rem;
  font-weight: 600; font-size: 0.9em; color: var(--ink);
  margin: 0 0 0.4rem; padding: 0 0.15rem;
}
.file-section-head .sec-act {
  background: none; border: 0; cursor: pointer; color: var(--ink-muted);
  font-size: 0.85em; padding: 0 0.15rem; opacity: 0; transition: opacity .12s;
}
.file-section:hover .sec-act { opacity: 0.75; }
.file-section-head .sec-act:first-of-type { margin-left: 0.5rem; }
.file-section-head .sec-act:hover { color: var(--ink); }
.ghost-btn {
  background: var(--rule-soft); border: 0; border-radius: 6px;
  padding: 0 0.7rem; font: inherit; font-size: 0.85em; color: var(--ink-mid);
  cursor: pointer;
}
.ghost-btn:hover { color: var(--ink); }
.file-section-body { display: flex; flex-direction: column; }
.file-dropzone {
  border: 1px dashed var(--rule); border-radius: 8px; padding: 0.9rem;
  text-align: center; color: var(--ink-muted); font-size: 0.82em; background: var(--card);
}
.file-row[draggable="true"] { cursor: grab; }
.file-row.dragging { opacity: 0.4; }
.folder-tab.drop-over { outline: 2px dashed var(--accent); background: var(--rule-soft); }
.file-icon { font-size: 1.1em; }
.file-name {
  color: var(--ink); text-decoration: none; font-size: 0.92em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%;
}
.file-name:hover { text-decoration: underline; }
.file-meta { font-size: 0.78em; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 0.15rem; }
.file-actions button {
  background: none; border: 0; cursor: pointer; padding: 0.25rem 0.35rem;
  border-radius: 4px; font-size: 0.9em; opacity: 0.55;
}
.file-actions button:hover { opacity: 1; background: var(--rule-soft); }
@media (max-width: 700px) {
  .file-name { max-width: none; flex: 1; }
  .file-meta { display: none; }
  .files-actions input[type=text] { width: 120px; }
}

/* ── Assistant chat ── */
.pill-ai { border-color: var(--accent); color: var(--accent); }
.pill-ai:hover { background: var(--accent); color: #fff; }
body.chat-page { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.chat-main { flex: 1; overflow-y: auto; padding: 1rem; max-width: 820px; width: 100%; margin: 0 auto; }
.chat-log { display: flex; flex-direction: column; gap: 0.7rem; }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 85%; padding: 0.65rem 0.9rem; border-radius: 12px;
  white-space: pre-wrap; word-break: break-word; font-size: 0.95em; line-height: 1.5;
}
.chat-msg.assistant .chat-bubble {
  background: var(--card); border: 1px solid var(--rule); border-bottom-left-radius: 4px;
}
.chat-msg.user .chat-bubble {
  background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}
.chat-bubble.thinking { color: var(--ink-muted); }
/* markdown-rendered assistant replies */
.chat-bubble.md { white-space: normal; }
.chat-bubble.md > :first-child { margin-top: 0; }
.chat-bubble.md > :last-child { margin-bottom: 0; }
.chat-bubble.md h1, .chat-bubble.md h2, .chat-bubble.md h3 {
  font-size: 1.02em; margin: 0.8em 0 0.35em; line-height: 1.3;
}
.chat-bubble.md p, .chat-bubble.md ul, .chat-bubble.md ol { margin: 0.45em 0; }
.chat-bubble.md ul, .chat-bubble.md ol { padding-left: 1.3em; }
.chat-bubble.md li { margin: 0.2em 0; }
.chat-bubble.md code {
  background: var(--rule-soft); padding: 0.05em 0.35em; border-radius: 4px; font-size: 0.88em;
}
.chat-bubble.md pre {
  background: var(--rule-soft); padding: 0.6em 0.8em; border-radius: 8px;
  overflow-x: auto; font-size: 0.85em;
}
.chat-bubble.md pre code { background: none; padding: 0; }
.chat-bubble.md table {
  border-collapse: collapse; margin: 0.5em 0; display: block;
  overflow-x: auto; max-width: 100%; font-size: 0.88em;
}
.chat-bubble.md th, .chat-bubble.md td {
  border: 1px solid var(--rule); padding: 0.3em 0.55em; text-align: left;
}
.chat-bubble.md th { background: var(--rule-soft); }
.chat-bubble.md hr { border: 0; border-top: 1px solid var(--rule); margin: 0.7em 0; }
.chat-bubble.md blockquote {
  margin: 0.45em 0; padding-left: 0.8em; border-left: 3px solid var(--lime); color: var(--ink-mid);
}
.chat-bubble.error-bubble { background: #fbeaea; border-color: #e7c0c0; color: var(--danger); }
.chat-tool-note {
  align-self: flex-start; font-size: 0.78em; color: var(--ink-muted);
  padding: 0.1rem 0.9rem; font-style: italic;
}
.chat-input-bar {
  border-top: 1px solid var(--rule); background: var(--card);
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom));
}
.chat-input-bar form {
  display: flex; gap: 0.5rem; max-width: 820px; margin: 0 auto; align-items: flex-end;
}
.chat-input-bar textarea {
  flex: 1; resize: none; padding: 0.6rem 0.8rem; border: 1px solid var(--rule);
  border-radius: 10px; font: inherit; background: var(--bg); max-height: 140px;
}
.chat-input-bar textarea:focus { outline: none; border-color: var(--lime); background: var(--card); }
.chat-input-bar button[type=submit] {
  width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 1.1em; flex-shrink: 0;
}
.chat-input-bar button[type=submit]:disabled { opacity: 0.4; cursor: default; }

/* ── Team feed ── */
.feed-main { max-width: 640px; padding: 0.9rem 0.8rem; }
.feed { display: flex; flex-direction: column; gap: 0.55rem; }
.feed-day {
  font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-muted); margin: 0.9rem 0 0.2rem; padding-left: 0.2rem;
}
.feed-day:first-child { margin-top: 0; }
.feed-item {
  display: flex; gap: 0.65rem; align-items: center;
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px;
  padding: 0.7rem 0.8rem;
  text-decoration: none; color: var(--ink);
  transition: border-color .12s, background .12s;
}
.feed-item:hover { border-color: var(--accent); text-decoration: none; }
.feed-item:active { background: var(--rule-soft); }
.feed-thumb {
  width: 64px; height: 64px; flex-shrink: 0;
  border-radius: 8px; overflow: hidden; border: 1px solid var(--rule);
}
.feed-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.feed-chev { color: var(--ink-muted); font-size: 1.2em; flex-shrink: 0; padding-left: 0.1rem; }
.feed-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 0.78em; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.feed-body { min-width: 0; flex: 1; }
.feed-head { font-size: 0.88em; line-height: 1.4; }
.feed-head em { font-style: normal; font-weight: 600; }
.feed-when { display: block; font-size: 0.82em; margin-top: 0.1rem; }
.feed-text {
  margin-top: 0.35rem; color: var(--ink-mid); font-size: 0.92em;
  white-space: pre-wrap; word-break: break-word;
}

/* Mobile ----------------------------------- */
@media (max-width: 700px) {
  /* — topbar: two rows; actions become a horizontally-scrollable pill rail — */
  .topbar { padding: 0.5rem 0.7rem 0.45rem; row-gap: 0.45rem; }
  .topbar-user { margin-left: auto; }
  .topbar-actions {
    order: 4; flex-basis: 100%; margin-left: 0;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 1px;
  }
  .topbar-actions::-webkit-scrollbar { display: none; }
  .topbar-actions .pill-toggle { flex-shrink: 0; padding: 0.45rem 0.85rem; }
  #search { min-width: 150px; flex-shrink: 0; padding: 0.45rem 0.75rem; }

  main { padding: 0.4rem; }

  /* — prevent iOS focus-zoom: inputs must be ≥16px — */
  input, select, textarea { font-size: 16px !important; }

  /* — comfortable touch targets — */
  .modal-card .actions button,
  .popover-actions button,
  form button[type=submit],
  .upload-btn, .folder-tab { min-height: 44px; }
  .file-actions button { font-size: 1.05em; padding: 0.5rem 0.55rem; opacity: 0.8; }
  .back-link { width: 38px; height: 38px; font-size: 1.15rem; }
  button.link { padding: 0.5rem 0.6rem; }

  /* — calendar — */
  .fc .fc-toolbar.fc-header-toolbar {
    flex-direction: column; gap: 0.4rem; margin-bottom: 0.4rem;
  }
  .fc .fc-toolbar-chunk { display: flex; gap: 0.3rem; flex-wrap: wrap; justify-content: center; }
  .fc .fc-button { padding: 0.45rem 0.7rem !important; font-size: 0.85em !important; }
  .fc .fc-timegrid-slot { height: 2.6em; }
  .fc .fc-event { font-size: 0.9em; }

  /* — modal & popover become bottom sheets — */
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none; width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 92dvh;
    padding: 1rem 1.1rem calc(1rem + env(safe-area-inset-bottom));
    animation: sheet-up .18s ease-out;
  }
  .modal-card .row { flex-direction: column; gap: 0; }
  .checkbox-row { align-self: flex-start; padding: 0.5rem 0 0; }
  .popover { align-items: flex-end; padding: 0; }
  .popover-card {
    width: 100%; max-width: none;
    border-radius: 16px 16px 0 0; border-left: 0; border-right: 0; border-bottom: 0;
    padding: 1rem 1.1rem calc(1rem + env(safe-area-inset-bottom));
    animation: sheet-up .18s ease-out;
    max-height: 88dvh; overflow-y: auto;
  }
  .popover-notes { max-height: 30dvh; }
  .comment-list { max-height: 28dvh; }

  /* — FAB clears the home indicator — */
  #fab {
    right: 0.9rem; bottom: calc(0.9rem + env(safe-area-inset-bottom));
    width: 56px; height: 56px; font-size: 26px;
  }

  /* — files page — */
  .files-head { flex-direction: column; align-items: stretch; }
  .folder-tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 2px; }
  .folder-tabs::-webkit-scrollbar { display: none; }
  .folder-tab { flex-shrink: 0; }
  .files-actions { justify-content: stretch; }
  .files-actions input[type=text] { flex: 1; width: auto; }
  .file-row { padding: 0.7rem 0.65rem; }

  /* — dashboard — */
  .dash { padding: 0.9rem 0.7rem; }
  .tile { padding: 1.05rem 1rem; }
  .tile:active { transform: scale(0.99); }
  button.primary { min-height: 44px; }

  /* — assistant chat — */
  .chat-bubble { max-width: 92%; }
  .chat-input-bar textarea { font-size: 16px !important; }
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

.ok-banner { background:#e8f0e6; border:1px solid #bcd3b4; color:#3d6b35; padding:0.5rem 0.7rem; border-radius:6px; margin-bottom:0.6rem; font-size:0.9em; }
