/* public/styles.css
   Relay — internal enquiry & task dashboard.
   Strict dark palette from the brief; high-density Notion-style list view. */

/* ── Tokens ────────────────────────────────────────────────────────────────── */
:root {
  /* Brief palette */
  --bg: #0f172a;
  --sidebar: #111827;
  --card: #1e293b;
  --primary: #7c3aed;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text: #f8fafc;
  --muted: #94a3b8;

  /* Derived surfaces */
  --card-hover: #243449;
  --raised: #243449;
  --line: rgba(148, 163, 184, 0.16); /* muted @ low alpha → hairlines */
  --line-strong: rgba(148, 163, 184, 0.28);
  --primary-2: #8b5cf6;
  --primary-press: #6d28d9;
  --field-bg: #0e1626;
  --shadow-lg: 0 18px 50px -12px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 10px 30px -10px rgba(0, 0, 0, 0.55);

  /* Metrics */
  --side-w: 240px;
  --radius: 10px;
  --radius-sm: 7px;
  --radius-pill: 999px;

  /* Type */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono",
    monospace;

  /* High-density table columns (desktop). Falls back to horizontal scroll on
     narrow desktops; collapses to cards on mobile. */
  --grid: minmax(150px, 1.5fr) 116px 116px 116px 96px minmax(150px, 1.6fr) 92px 120px 84px 40px;
}

/* ── Reset / base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open {
  overflow: hidden;
}

body.drawer-open {
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.dim {
  color: var(--muted);
}

::selection {
  background: rgba(124, 58, 237, 0.4);
}

/* Scrollbars (WebKit) */
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.22);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.34);
  background-clip: padding-box;
}

/* ── Form controls (shared) ───────────────────────────────────────────────── */
input,
textarea,
select,
button {
  font: inherit;
  color: inherit;
}

input,
textarea,
select {
  width: 100%;
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: rgba(148, 163, 184, 0.7);
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary-2);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.25);
}

input:disabled,
textarea:disabled,
select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

textarea {
  resize: vertical;
  min-height: 84px;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% - 2px), calc(100% - 11px) calc(50% - 2px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--primary-2);
  outline-offset: 2px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease,
    transform 0.05s ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-2);
  border-color: var(--primary-2);
}
.btn-primary:active {
  background: var(--primary-press);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line-strong);
}
.btn-ghost:hover {
  background: rgba(148, 163, 184, 0.1);
}

.btn-ghost-danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}
.btn-ghost-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
}

.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12.5px;
  transition: color 0.15s ease, background 0.15s ease;
}
.link-btn:hover {
  color: var(--text);
  background: rgba(148, 163, 184, 0.1);
}

/* ── Fields ───────────────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.field-row.cols-2 {
  grid-template-columns: repeat(2, 1fr);
}
.req {
  color: var(--danger);
  font-weight: 700;
}

/* ── Auth screen ──────────────────────────────────────────────────────────── */
.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(124, 58, 237, 0.16), transparent 70%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px 28px 28px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.auth-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.auth-topbar .auth-brand {
  margin-bottom: 0;
}
.auth-topbar + .auth-title {
  margin-top: 20px;
}

/* Language switch (auth cards + sidebar) */
.lang-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.08);
}
.lang-switch button {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.lang-switch button:hover {
  color: var(--text);
}
.lang-switch button.active {
  background: var(--primary);
  color: #fff;
}
.sidebar-foot .lang-switch {
  margin: 2px 6px 8px;
}
.auth-mark,
.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--primary-2), var(--primary-press));
  box-shadow: 0 4px 14px -4px rgba(124, 58, 237, 0.7);
  flex: none;
}
.auth-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.auth-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-sub {
  margin: 4px 0 22px;
  color: var(--muted);
  font-size: 13px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form .btn {
  margin-top: 4px;
  padding: 10px 14px;
}
.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 0;
}
.auth-error:not(:empty) {
  min-height: 18px;
}
.auth-switch {
  margin: 16px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.auth-switch .link-btn {
  font-size: 13px;
}
.auth-form .field-row {
  gap: 12px;
}

/* ── Attachments (enquiry modal) ──────────────────────────────────────────── */
.file-input {
  font-size: 12.5px;
  color: var(--muted);
}
.file-input::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.file-input::file-selector-button:hover {
  background: rgba(148, 163, 184, 0.2);
}
.field-hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.08);
  font-size: 12px;
}
.attach-chip a {
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}
.attach-chip a:hover {
  text-decoration: underline;
}
.attach-chip .attach-size {
  color: var(--muted);
}
.attach-chip .attach-del {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
}
.attach-chip .attach-del:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.12);
}

/* ── App layout ───────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  min-width: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 16px;
}
/*.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 6px; 
  object-fit: contain; 
  margin-right: 12px; 
}*/
.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sidebar-close {
  display: none;
  margin-left: auto;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover {
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
}
.nav-item.active {
  background: rgba(124, 58, 237, 0.16);
  color: var(--text);
}
.nav-item.active .nav-ico {
  color: var(--primary-2);
}
.nav-ico {
  font-size: 14px;
  width: 16px;
  text-align: center;
  color: var(--muted);
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.who {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 10px;
}
.who-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--primary-2), var(--primary-press));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}
.who-meta {
  min-width: 0;
}
.who-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who-role {
  font-size: 11.5px;
  color: var(--muted);
}
.foot-actions {
  display: flex;
  gap: 6px;
}

/* ── Scrim (mobile drawer backdrop) ───────────────────────────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  z-index: 40;
  border: none;
  padding: 0;
}

/* ── Main / topbar ────────────────────────────────────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.menu-toggle {
  display: none;
}
.title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.page-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.new-btn {
  margin-left: auto;
}

.conn {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5);
  flex: none;
}
.conn.live {
  background: var(--success);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

/* ── Summary chips ────────────────────────────────────────────────────────── */
.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: var(--radius-pill);
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}
.chip-active {
  background: var(--raised);
  border-color: var(--primary-2);
  color: var(--text);
}
.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.chip-count {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

/* ── Controls ─────────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  flex-wrap: wrap;
}
.search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 420px;
}
.search-ico {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}
.search input {
  padding-left: 32px;
}
.control-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.mobile-filter-toggle {
  display: none;
}
.filter-count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--primary);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
}
.ctl {
  display: flex;
  align-items: center;
  gap: 7px;
}
.ctl-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.ctl select {
  width: auto;
  min-width: 116px;
  padding-top: 7px;
  padding-bottom: 7px;
}

.seg {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.seg-label {
  padding: 0 6px 0 4px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn:hover {
  color: var(--text);
}
.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

/* ── List / table ─────────────────────────────────────────────────────────── */
.list-wrap {
  flex: 1;
  overflow: auto;
  padding: 6px 20px 28px;
}
.table {
  min-width: 1080px; /* keep columns aligned; horizontal scroll if narrower */
}

.thead {
  display: grid;
  grid-template-columns: var(--grid);
  gap: 0 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line-strong);
}
.thead .cell {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.group {
  margin-top: 10px;
}
.group-head {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.group-head:hover {
  background: rgba(148, 163, 184, 0.06);
}
.caret {
  font-size: 11px;
  color: var(--muted);
  transition: transform 0.15s ease;
  width: 12px;
}
.caret.is-collapsed {
  transform: rotate(-90deg);
}
.group-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.group-label {
  font-size: 13px;
  font-weight: 600;
}
.group-count {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
}

.group-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.trow {
  display: grid;
  grid-template-columns: var(--grid);
  gap: 0 10px;
  align-items: center;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background-color: var(--card);
  background-image: linear-gradient(var(--tint, transparent), var(--tint, transparent));
  box-shadow: inset 3px 0 0 0 var(--edge, transparent);
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.trow:hover {
  background-color: var(--card-hover);
}
.trow.is-canceled .tname,
.trow.is-canceled .desc {
  text-decoration: line-through;
  text-decoration-color: rgba(148, 163, 184, 0.5);
  color: var(--muted);
}

.mobile-card-badges {
  display: none;
}

.cell {
  min-width: 0;
}

.c-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.tname {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcode {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.copy-link-btn {
  width: 20px;
  height: 20px;
  min-width: 20px;
  font-size: 11px;
  margin-left: 2px;
  vertical-align: -3px;
  opacity: 0.7;
}
.copy-link-btn:hover {
  opacity: 1;
}

.tag {
  display: inline-block;
  font-size: 11.5px;
  color: var(--text);
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 8px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.c-contact,
.c-assignee,
.c-from {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.c-project {
  min-width: 0;
}
.attach-badge {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

/* Queue position ("N ahead" of the filer in the assignee's queue) */
.queue-pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
  color: var(--warning);
  background: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.32);
}
.queue-pill.queue-next {
  color: var(--success);
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.32);
}
.queue-pill.queue-active {
  color: var(--primary);
  background: rgba(124, 58, 237, 0.16);
  border-color: rgba(124, 58, 237, 0.35);
}

/* ── Team management modal ────────────────────────────────────────────────── */
.team-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 52vh;
  overflow: auto;
}
.team-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
}
.team-toolbar input {
  min-width: 0;
  flex: 1;
}
.team-count {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.team-row {
  display: grid;
  grid-template-columns: 1fr 128px 36px 36px;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--line);
}
.team-who {
  min-width: 0;
}
.team-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.team-sub {
  font-size: 11px;
  color: var(--muted);
}
.team-activity {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
}
.team-activity.is-online {
  color: var(--success);
}
.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.65;
}
.team-activity.is-online .presence-dot {
  opacity: 1;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.14);
}
.team-credentials:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.org-card {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.org-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}
.org-card .field-row {
  margin-bottom: 6px;
}
.org-card .team-row {
  grid-template-columns: 1fr 128px 36px;
}

.org-index-card {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.org-index-card:hover { border-color: var(--accent); }
.org-index-card + .org-index-card { margin-top: 10px; }
.org-index-card > span:first-child { min-width: 0; }
.org-index-name { display: block; font-weight: 700; overflow-wrap: anywhere; }
.org-index-meta { display: block; margin-top: 3px; color: var(--muted); font-size: .84rem; }
.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--accent);
  font-size: .8rem;
}
.team-del:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.c-project .tag {
  vertical-align: middle;
}

.desc {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.c-due {
  font-size: 12.5px;
  color: var(--text);
  white-space: nowrap;
}
.c-due.overdue {
  color: var(--danger);
}
.overdue-flag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--danger);
  background: rgba(239, 68, 68, 0.14);
  border-radius: 4px;
  padding: 0 5px;
  margin-left: 4px;
  vertical-align: 1px;
}

.c-updated {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.c-actions {
  display: flex;
  justify-content: flex-end;
}
.row-more {
  width: 28px;
  height: 28px;
  font-size: 16px;
}

/* Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  white-space: nowrap;
  max-width: 100%;
}
.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill-btn {
  cursor: pointer;
  transition: filter 0.15s ease;
}
.pill-btn:hover {
  filter: brightness(1.15);
}
.pill-caret {
  font-size: 9px;
  opacity: 0.8;
  margin-left: 1px;
}

/* Empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding: 64px 20px;
  color: var(--muted);
}
.empty-mark {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  position: relative;
}
.empty-mark::before {
  content: "▤";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 20px;
}
.empty-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.empty-body {
  font-size: 13px;
  max-width: 320px;
}
.empty .btn {
  margin-top: 6px;
}

/* Row flash on live update */
.trow.flash {
  animation: rowflash 1.4s ease-out;
}
@keyframes rowflash {
  0% {
    background-color: rgba(124, 58, 237, 0.32);
  }
  100% {
    background-color: var(--card);
  }
}

/* ── Popover menus ────────────────────────────────────────────────────────── */
.popover {
  position: fixed;
  z-index: 60;
  min-width: 184px;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 5px;
  animation: pop 0.12s ease-out;
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.pop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  text-align: left;
}
.pop-item:hover {
  background: rgba(148, 163, 184, 0.12);
}
.pop-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.pop-check {
  margin-left: auto;
  color: var(--primary-2);
  font-size: 12px;
}
.pop-item.is-current {
  color: var(--text);
}
.pop-danger {
  color: var(--danger);
}
.pop-danger:hover {
  background: rgba(239, 68, 68, 0.12);
}

/* ── Modals ───────────────────────────────────────────────────────────────── */
#modal-root {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.66);
  backdrop-filter: blur(2px);
}
.modal {
  position: relative;
  width: 100%;
  max-width: 600px;
  max-height: calc(100dvh - 40px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  animation: modalin 0.16s ease-out;
}
.modal-sm {
  max-width: 420px;
}
@keyframes modalin {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}
.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.modal-sub {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}
.modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 20px;
}
.modal-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 0;
}
.modal-error:not(:empty) {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 7px;
  padding: 8px 10px;
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}
.foot-right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ── Toasts ───────────────────────────────────────────────────────────────── */
.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 36px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 11px 14px 11px 12px;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  opacity: 0;
  transform: translateX(16px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast.show {
  opacity: 1;
  transform: translateX(0);
}
.toast-bar {
  width: 3px;
  align-self: stretch;
  border-radius: 3px;
  flex: none;
}

/* ── Responsive: tablet ───────────────────────────────────────────────────── */
@media (max-width: 1040px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── Responsive: mobile (drawer + card rows) ──────────────────────────────── */
@media (max-width: 880px) {
  :root {
    --mobile-gutter: 14px;
  }

  html,
  body {
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    font-size: 14px;
  }

  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 310px;
    max-width: 88vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: var(--shadow-lg);
    padding: max(16px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
    border-radius: 0 18px 18px 0;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: inline-flex;
    width: 40px;
    height: 40px;
  }

  .brand {
    min-height: 50px;
    padding-bottom: 14px;
  }

  .nav {
    gap: 6px;
  }

  .nav-item {
    min-height: 46px;
    padding: 11px 12px;
    border-radius: 10px;
  }

  .who {
    padding-top: 8px;
  }

  .foot-actions .link-btn {
    min-height: 42px;
    padding-inline: 10px;
  }

  .scrim {
    background: rgba(2, 6, 23, 0.72);
    backdrop-filter: blur(3px);
  }

  .menu-toggle {
    display: inline-flex;
    width: 40px;
    height: 40px;
    color: var(--text);
    background: rgba(148, 163, 184, 0.08);
    border-color: var(--line);
  }

  .topbar {
    min-height: calc(64px + env(safe-area-inset-top));
    padding: calc(10px + env(safe-area-inset-top)) var(--mobile-gutter) 10px;
    gap: 10px;
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(14px);
    z-index: 20;
  }

  .title-wrap {
    gap: 8px;
  }

  .page-title {
    font-size: 16px;
  }

  .new-btn {
    min-height: 40px;
    padding: 8px 12px;
    border-radius: 9px;
  }

  .summary {
    flex-wrap: nowrap;
    gap: 7px;
    padding: 12px var(--mobile-gutter) 4px;
    overflow-x: auto;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .summary::-webkit-scrollbar {
    display: none;
  }

  .chip {
    min-height: 36px;
    flex: none;
    scroll-snap-align: start;
    padding-inline: 12px;
  }

  .controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 10px var(--mobile-gutter) 12px;
  }

  .search {
    min-width: 0;
    max-width: none;
  }

  .search input {
    height: 42px;
    font-size: 16px;
  }

  .mobile-filter-toggle {
    display: inline-flex;
    min-height: 42px;
    padding-inline: 12px;
  }

  .control-group {
    display: none;
    grid-column: 1 / -1;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
  }

  .controls.filters-open .control-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    animation: filtersin 0.15s ease-out;
  }

  @keyframes filtersin {
    from {
      opacity: 0;
      transform: translateY(-4px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .ctl {
    min-width: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 5px;
  }

  .ctl select {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    font-size: 16px;
  }

  .seg {
    grid-column: 1 / -1;
    min-height: 42px;
    justify-content: stretch;
  }

  .seg-label {
    padding-left: 8px;
  }

  .seg-btn {
    min-height: 34px;
    flex: 1;
  }

  .list-wrap {
    padding: 0 var(--mobile-gutter) calc(30px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* Table → stacked cards */
  .table {
    min-width: 0;
  }
  .thead {
    display: none;
  }
  .group-rows {
    gap: 10px;
  }

  .group {
    margin-top: 8px;
  }

  .group-head {
    min-height: 42px;
    padding: 8px 4px;
  }

  .trow {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    position: relative;
    padding: 14px 14px 13px 16px;
    box-shadow: inset 3px 0 0 0 var(--edge, transparent), 0 8px 24px -20px rgba(0, 0, 0, 0.8);
    border: 1px solid var(--line);
    border-radius: 12px;
    background-image: linear-gradient(110deg, var(--tint, transparent), transparent 54%);
    -webkit-tap-highlight-color: transparent;
  }

  .trow:active {
    background-color: var(--card-hover);
  }

  .cell {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 4px 0;
  }
  .cell[data-label]::before {
    content: attr(data-label);
    flex: none;
    width: 78px;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.7;
  }

  /* Name becomes the card title (no label, full width) */
  .c-name {
    display: block;
    padding: 0 40px 0 0;
    margin-bottom: 8px;
  }
  .tname {
    white-space: normal;
    font-size: 15.5px;
    line-height: 1.35;
  }
  .tcode {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 3px;
    white-space: normal;
  }

  .copy-link-btn {
    width: 28px;
    height: 28px;
    margin-block: -5px;
  }

  .mobile-card-badges {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 7px;
    padding-bottom: 9px;
    margin-bottom: 5px;
    border-bottom: 1px solid var(--line);
  }

  .c-contact,
  .c-assignee,
  .c-from,
  .c-queue,
  .c-project,
  .desc {
    white-space: normal;
  }
  .desc {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .c-prio,
  .c-status {
    display: none;
  }

  .c-desc {
    margin-top: 2px;
  }

  .c-updated {
    padding-top: 8px;
    margin-top: 5px;
    border-top: 1px solid var(--line);
  }

  /* Actions pinned to the card corner */
  .c-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 0;
  }

  .row-more {
    width: 38px;
    height: 38px;
  }

  .field-row,
  .field-row.cols-2 {
    grid-template-columns: 1fr;
  }

  .toast-root {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: none;
  }

  #modal-root {
    align-items: end;
    padding: 0;
  }

  .modal-scrim {
    background: rgba(2, 6, 23, 0.74);
    backdrop-filter: blur(4px);
  }

  .modal,
  .modal-sm {
    max-width: none;
    max-height: min(92dvh, 820px);
    border-width: 1px 0 0;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation-name: sheetin;
  }

  @keyframes sheetin {
    from {
      opacity: 0;
      transform: translateY(28px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .modal::before {
    content: "";
    display: block;
    position: sticky;
    top: 0;
    z-index: 3;
    width: 42px;
    height: 4px;
    margin: 8px auto -4px;
    border-radius: var(--radius-pill);
    background: rgba(148, 163, 184, 0.42);
  }

  .modal-head {
    padding: 17px var(--mobile-gutter) 12px;
  }

  .modal-head > .icon-btn {
    width: 38px;
    height: 38px;
  }

  .modal-body {
    gap: 16px;
    padding: 16px var(--mobile-gutter) calc(18px + env(safe-area-inset-bottom));
  }

  .modal input,
  .modal textarea,
  .modal select {
    font-size: 16px;
    min-height: 44px;
  }

  .modal-foot {
    position: sticky;
    bottom: calc(-18px - env(safe-area-inset-bottom));
    z-index: 2;
    margin: 2px calc(-1 * var(--mobile-gutter)) calc(-18px - env(safe-area-inset-bottom));
    padding: 12px var(--mobile-gutter) calc(12px + env(safe-area-inset-bottom));
    background: rgba(30, 41, 59, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }

  .modal-foot .btn {
    min-height: 44px;
  }

  .popover-mobile {
    inset: auto 0 0 !important;
    min-width: 0;
    width: 100%;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    animation: sheetin 0.16s ease-out;
  }

  .popover-mobile::before {
    content: "";
    display: block;
    width: 38px;
    height: 4px;
    margin: 0 auto 8px;
    border-radius: var(--radius-pill);
    background: rgba(148, 163, 184, 0.42);
  }

  .popover-mobile .pop-item {
    min-height: 48px;
    padding-inline: 14px;
    font-size: 14px;
  }

  .team-list {
    max-height: none;
  }

  .team-row {
    grid-template-columns: minmax(0, 1fr) 40px 40px;
    gap: 8px;
    padding-block: 10px;
  }

  .team-row select {
    grid-column: 1 / 4;
    grid-row: 2;
  }

  .team-credentials {
    grid-column: 2;
    grid-row: 1;
    width: 40px;
    height: 40px;
  }

  .team-del {
    grid-column: 3;
    grid-row: 1;
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 420px) {
  :root {
    --mobile-gutter: 12px;
  }

  .new-btn {
    width: 40px;
    padding: 0;
  }

  .new-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .new-plus {
    font-size: 18px;
  }

  .mobile-filter-toggle > span:nth-child(2) {
    display: none;
  }

  .controls.filters-open .control-group {
    grid-template-columns: 1fr;
  }

  .seg {
    grid-column: 1;
  }

  .cell[data-label]::before {
    width: 72px;
  }

  .modal-foot {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .modal-foot .foot-left,
  .modal-foot .foot-right,
  .modal-foot .btn {
    width: 100%;
  }

  .modal-foot .foot-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal-foot .foot-right:only-child {
    margin-left: 0;
  }

  .auth {
    place-items: start center;
    padding: max(18px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom));
  }

  .auth-card {
    margin-block: auto;
    padding: 24px 18px 22px;
    border-radius: 14px;
  }

  .auth input,
  .auth button.btn {
    min-height: 44px;
    font-size: 16px;
  }
}

/* ── Reduced motion ───────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .conn.live {
    animation: none;
  }
}
