/* =========================================================================
   ProLife Workspace — Design System (Phase 2)
   One stylesheet. Every colour, radius and shadow is a CSS variable so that
   company branding (--brand, --accent) and light/dark mode restyle the whole
   app without code changes. Brand tints are derived with color-mix().
   ========================================================================= */

/* ---------- 1. Tokens ---------- */
:root {
  /* Brand (overridden per company by /theme.css) */
  --brand: #0f766e;
  --accent: #d97706;

  /* Derived brand shades */
  --brand-strong: color-mix(in srgb, var(--brand) 82%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 10%, var(--surface));
  --brand-softer: color-mix(in srgb, var(--brand) 5%, var(--surface));
  --brand-line: color-mix(in srgb, var(--brand) 28%, var(--surface));
  --accent-soft: color-mix(in srgb, var(--accent) 14%, var(--surface));
  --on-brand: #ffffff;

  /* Neutrals */
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --surface-3: #eef1f4;
  --border: #e2e7ec;
  --border-strong: #cfd6dd;
  --text: #0f1b2a;
  --text-2: #4a5868;
  --text-3: #8492a2;

  /* Status */
  --s-pending: #64748b;
  --s-progress: #2563eb;
  --s-review: #7c3aed;
  --s-revision: #d97706;
  --s-completed: #059669;
  --s-overdue: #dc2626;
  --s-cancelled: #94a3b8;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --info: #2563eb;

  /* Shape */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 27, 42, .06);
  --shadow: 0 1px 3px rgba(15, 27, 42, .06), 0 4px 14px rgba(15, 27, 42, .05);
  --shadow-lg: 0 10px 40px rgba(15, 27, 42, .16);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs: 14px;
  --fs-md: 16px;
  --fs-lg: 20px;
  --fs-xl: 26px;

  /* Layout */
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 64px;
  --bottomnav-h: 64px;
  --content-max: 1320px;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d141c;
  --surface: #131c26;
  --surface-2: #17212c;
  --surface-3: #1e2a37;
  --border: #253241;
  --border-strong: #324254;
  --text: #e8eef4;
  --text-2: #a7b4c2;
  --text-3: #6f8090;
  --brand-strong: color-mix(in srgb, var(--brand) 70%, #fff);
  --brand-soft: color-mix(in srgb, var(--brand) 20%, var(--surface));
  --brand-softer: color-mix(in srgb, var(--brand) 10%, var(--surface));
  --brand-line: color-mix(in srgb, var(--brand) 40%, var(--surface));
  --accent-soft: color-mix(in srgb, var(--accent) 20%, var(--surface));
  --shadow-sm: none;
  --shadow: 0 1px 0 rgba(255, 255, 255, .02);
  --shadow-lg: 0 14px 44px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); font-size: var(--fs-sm); }
.mono { font-family: var(--mono); }

/* ---------- 3. App shell ---------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  transition: grid-template-columns .2s ease;
}
.app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* Sidebar */
.sidebar {
  position: sticky; top: 0; height: 100vh; align-self: start;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar__brand {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--brand); color: var(--on-brand);
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  flex: none; overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.15; white-space: nowrap; }
.brand-name small { display: block; font-weight: 500; font-size: 11.5px; color: var(--text-3); }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 10px 20px; scrollbar-width: thin; }
.nav-section { margin-top: 14px; }
.nav-section:first-child { margin-top: 0; }
.nav-section__title {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); padding: 6px 12px; white-space: nowrap;
}
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin: 1px 0;
  border-radius: var(--r);
  color: var(--text-2); font-weight: 520; white-space: nowrap;
  position: relative;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link.is-active { background: var(--brand-soft); color: var(--brand-strong); }
.nav-link.is-active::before {
  content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--brand);
}
.nav-link .count {
  margin-left: auto; font-size: 11px; font-weight: 650;
  background: var(--surface-3); color: var(--text-2);
  padding: 1px 7px; border-radius: 99px;
}
.nav-link.is-active .count { background: var(--brand); color: var(--on-brand); }
.sidebar__foot { border-top: 1px solid var(--border); padding: 10px; flex: none; }

.is-collapsed .brand-name,
.is-collapsed .nav-section__title,
.is-collapsed .nav-link span,
.is-collapsed .nav-link .count,
.is-collapsed .sidebar__foot span { display: none; }
.is-collapsed .nav-link { justify-content: center; padding: 10px; }
.is-collapsed .sidebar__brand { justify-content: center; padding: 0; }
.is-collapsed .nav-section { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 8px; }
.is-collapsed .nav-section:first-child { border-top: 0; padding-top: 0; }

/* Main column */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 24px;
}
.topbar__search {
  flex: 1; max-width: 520px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r); padding: 0 12px; height: 40px; color: var(--text-3);
}
.topbar__search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; color: var(--text); }
.topbar__search kbd {
  font-family: var(--font); font-size: 11px; color: var(--text-3);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; background: var(--surface);
}
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar__title { display: none; font-weight: 650; font-size: 16px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r);
  display: inline-grid; place-items: center;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  position: relative;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 8px; right: 9px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--danger); border: 2px solid var(--surface);
}
.switcher {
  display: inline-flex; align-items: center; gap: 8px; height: 40px;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--r);
  padding: 0 10px 0 12px; cursor: pointer; color: var(--text); font-weight: 550; white-space: nowrap;
}
.switcher:hover { border-color: var(--border-strong); }
.switcher .label { font-size: 11px; color: var(--text-3); font-weight: 500; display: block; line-height: 1; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 75%, var(--text));
  display: inline-grid; place-items: center;
  font-size: 13px; font-weight: 650; flex: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-xs { width: 22px; height: 22px; font-size: 9.5px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }
.profile-btn { display: flex; align-items: center; gap: 10px; border: 0; background: none; cursor: pointer; padding: 4px 6px 4px 4px; border-radius: 99px; }
.profile-btn:hover { background: var(--surface-3); }
.profile-btn .who { text-align: left; line-height: 1.2; }
.profile-btn .who b { display: block; font-size: 13px; font-weight: 600; }
.profile-btn .who small { font-size: 11.5px; color: var(--text-3); }

.content {
  width: 100%; max-width: var(--content-max);
  margin: 0 auto; padding: 28px 24px 48px;
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumb { display: flex; gap: 6px; align-items: center; font-size: var(--fs-sm); color: var(--text-3); margin-bottom: 6px; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-2); }

/* Prototype ribbon */
.proto-ribbon {
  background: var(--accent-soft); color: color-mix(in srgb, var(--accent) 70%, var(--text));
  font-size: 12px; text-align: center; padding: 6px 12px; border-bottom: 1px solid var(--border);
}

/* Bottom nav (phones) */
.bottom-nav { display: none; }
.more-sheet { display: none; }

/* ---------- 4. Components ---------- */
/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 600; font-size: var(--fs); cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-soft { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--surface)); }
.btn-sm { height: 32px; padding: 0 12px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 22px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card__head h3 { font-size: 15px; }
.card__head .subtle { margin-top: 2px; }
.card__body { padding: 20px; }
.card__foot { flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.card--flush .card__body { padding: 0; }

/* Grid helpers */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.wrap { flex-wrap: wrap; }

/* Stat tiles */
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px 18px 16px; box-shadow: var(--shadow); display: block; color: inherit;
}
a.stat:hover { border-color: var(--brand-line); text-decoration: none; }
.stat__top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); font-weight: 550; font-size: var(--fs-sm); }
.stat__icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); }
.stat__icon.is-red { background: color-mix(in srgb, var(--s-overdue) 12%, var(--surface)); color: var(--s-overdue); }
.stat__icon.is-violet { background: color-mix(in srgb, var(--s-review) 12%, var(--surface)); color: var(--s-review); }
.stat__icon.is-green { background: color-mix(in srgb, var(--s-completed) 12%, var(--surface)); color: var(--s-completed); }
.stat__icon.is-amber { background: color-mix(in srgb, var(--s-revision) 14%, var(--surface)); color: var(--s-revision); }
.stat__value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 10px; line-height: 1.1; }
.stat__meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 4px; }

/* Badges / status */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.st-pending   { color: var(--s-pending);   background: color-mix(in srgb, var(--s-pending) 12%, var(--surface)); }
.st-progress  { color: var(--s-progress);  background: color-mix(in srgb, var(--s-progress) 11%, var(--surface)); }
.st-review    { color: var(--s-review);    background: color-mix(in srgb, var(--s-review) 11%, var(--surface)); }
.st-revision  { color: var(--s-revision);  background: color-mix(in srgb, var(--s-revision) 13%, var(--surface)); }
.st-completed { color: var(--s-completed); background: color-mix(in srgb, var(--s-completed) 12%, var(--surface)); }
.st-overdue   { color: var(--s-overdue);   background: color-mix(in srgb, var(--s-overdue) 11%, var(--surface)); }
.st-cancelled { color: var(--s-cancelled); background: color-mix(in srgb, var(--s-cancelled) 14%, var(--surface)); }
.flag-overdue {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650;
  color: var(--s-overdue);
}
.prio { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.prio i { width: 8px; height: 8px; border-radius: 2px; background: var(--s-pending); }
.prio-low i { background: var(--s-cancelled); }
.prio-normal i { background: var(--s-progress); }
.prio-high i { background: var(--s-revision); }
.prio-urgent { color: var(--s-overdue); }
.prio-urgent i { background: var(--s-overdue); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; font-weight: 550; color: var(--text-2); white-space: nowrap;
}
.chip .x { cursor: pointer; color: var(--text-3); }
.tag { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-weight: 550; }

/* Progress */
.progress { height: 6px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress-stack { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--surface-3); gap: 2px; }
.progress-stack > i { display: block; height: 100%; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 16px; }
.label { font-weight: 600; font-size: var(--fs-sm); color: var(--text); }
.label .req { color: var(--danger); }
.hint { font-size: var(--fs-xs); color: var(--text-3); }
.error-text { font-size: var(--fs-xs); color: var(--danger); }
.input, .select, .textarea {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 110px; padding: 10px 12px; resize: vertical; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%); background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input.is-invalid { border-color: var(--danger); }
.input-group { position: relative; }
.input-group .icon { position: absolute; left: 12px; top: 11px; color: var(--text-3); }
.input-group .input { padding-left: 40px; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--brand); flex: none; }
.switch { position: relative; width: 40px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: var(--shadow-sm); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }
.segmented { display: inline-flex; background: var(--surface-3); border-radius: var(--r); padding: 3px; gap: 2px; }
.segmented button { border: 0; background: none; height: 32px; padding: 0 12px; border-radius: 8px; font-weight: 600; font-size: var(--fs-sm); color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* Dropzone */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-lg);
  padding: 26px 16px; text-align: center; color: var(--text-2);
  background: var(--surface-2); cursor: pointer; transition: .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand); background: var(--brand-softer); }
.dropzone .icon { margin: 0 auto 8px; width: 28px; height: 28px; color: var(--brand); }
.upload-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.upload-item + .upload-item { margin-top: 8px; }

/* File type icon */
.ftype {
  width: 36px; height: 40px; border-radius: 7px; flex: none;
  display: grid; place-items: end center; padding-bottom: 6px;
  font-size: 9.5px; font-weight: 750; color: #fff; letter-spacing: .02em;
  position: relative; background: var(--text-3);
}
.ftype::after { content: ""; position: absolute; top: 0; right: 0; width: 10px; height: 10px; background: color-mix(in srgb, #fff 45%, transparent); border-bottom-left-radius: 4px; }
.ftype.pdf { background: #dc2626; } .ftype.doc { background: #2563eb; } .ftype.xls { background: #059669; }
.ftype.ppt { background: #ea580c; } .ftype.img { background: #7c3aed; }
.folder-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); flex: none; }

/* Tables (become cards on phones) */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs); }
.table th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--brand-softer); }
.table .cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.table .cell-main b { font-weight: 600; display: block; }
.table .cell-main a { color: var(--text); }
.table .actions { text-align: right; white-space: nowrap; }

/* List rows (tasks, notifications, activity) */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; color: var(--text); display: block; }
.list-item .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: var(--fs-sm); color: var(--text-3); margin-top: 3px; align-items: center; }
.list-item.is-unread { background: var(--brand-softer); }
.list-item.is-unread .title::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-left: 8px; vertical-align: middle; }

/* Task card (used on phones and in boards) */
.task-card { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); color: inherit; box-shadow: var(--shadow-sm); }
.task-card:hover { border-color: var(--brand-line); text-decoration: none; }
.task-card + .task-card { margin-top: 10px; }
.task-card .title { font-weight: 600; margin: 8px 0 4px; }
.task-card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: var(--fs-sm); color: var(--text-2); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; cursor: pointer; white-space: nowrap;
  padding: 10px 12px; font-weight: 600; color: var(--text-2); position: relative;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab .count { font-size: 11px; background: var(--surface-3); padding: 0 7px; border-radius: 99px; }
.tab.is-active { color: var(--brand-strong); }
.tab.is-active::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--brand); border-radius: 2px; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* Filter bar */
.filterbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.filterbar .input-group { flex: 1; min-width: 220px; max-width: 360px; }
.filterbar .select { width: auto; min-width: 140px; height: 38px; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2); }
.pagination .pages { display: flex; gap: 4px; }
.pagination .pages a, .pagination .pages span { min-width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: var(--text-2); font-weight: 600; }
.pagination .pages a:hover { background: var(--surface-3); text-decoration: none; }
.pagination .pages .is-current { background: var(--brand); color: var(--on-brand); }

/* Alerts */
.alert { display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--r); border: 1px solid; font-size: var(--fs); }
.alert .icon { margin-top: 1px; }
.alert-info { background: color-mix(in srgb, var(--info) 8%, var(--surface)); border-color: color-mix(in srgb, var(--info) 25%, var(--surface)); }
.alert-info .icon { color: var(--info); }
.alert-warning { background: color-mix(in srgb, var(--warning) 10%, var(--surface)); border-color: color-mix(in srgb, var(--warning) 30%, var(--surface)); }
.alert-warning .icon { color: var(--warning); }
.alert-danger { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 25%, var(--surface)); }
.alert-danger .icon { color: var(--danger); }
.alert-success { background: color-mix(in srgb, var(--success) 9%, var(--surface)); border-color: color-mix(in srgb, var(--success) 25%, var(--surface)); }
.alert-success .icon { color: var(--success); }

/* Empty state */
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); }
.empty .empty-ico { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); }
.empty h3 { margin-bottom: 4px; color: var(--text); }

/* Timeline (task history) */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 20px 28px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 18px; bottom: -2px; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .tl-dot { position: absolute; left: 0; top: 3px; width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--surface); background: var(--text-3); box-shadow: 0 0 0 1px var(--border); }
.timeline .tl-dot.is-brand { background: var(--brand); }
.timeline .tl-dot.is-green { background: var(--s-completed); }
.timeline .tl-dot.is-amber { background: var(--s-revision); }
.timeline .tl-dot.is-violet { background: var(--s-review); }
.timeline .tl-title { font-weight: 600; }
.timeline .tl-time { font-size: var(--fs-xs); color: var(--text-3); }
.timeline .tl-body { margin-top: 6px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); color: var(--text-2); }

/* Key-value list */
.kv { margin: 0; display: grid; grid-template-columns: 120px 1fr; gap: 10px 12px; font-size: var(--fs); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 550; }

/* Dropdown / popover */
.dropdown { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  width: 360px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); display: none; overflow: hidden;
}
.popover.is-open { display: block; animation: pop .14s ease; }
.popover--menu { width: 240px; padding: 6px; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); cursor: pointer; border: 0; background: none; width: 100%; text-align: left; font-weight: 500; }
.menu-item:hover { background: var(--surface-3); text-decoration: none; }
.menu-item.is-danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Modal (dialog on desktop, bottom sheet on phones) */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 18, 28, .45);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.is-open { display: flex; animation: fade .15s ease; }
.modal {
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px);
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-lg { max-width: 760px; }
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal__body { padding: 22px; overflow-y: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Toast */
.toast-host { position: fixed; z-index: 200; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; background: var(--text); color: var(--surface); padding: 12px 16px; border-radius: var(--r); box-shadow: var(--shadow-lg); font-weight: 550; animation: pop .2s ease; max-width: 360px; }
.toast .icon { color: #34d399; }

/* Share recipients */
.recipient { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.recipient:last-child { border-bottom: 0; }
.recipient .grow { flex: 1; min-width: 0; }
.recipient .select { width: auto; height: 34px; font-size: var(--fs-sm); }

/* Mini bar chart (pure CSS, values from data attributes in PHP) */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 48px; gap: 12px; align-items: center; font-size: var(--fs-sm); }
.bar-row .name { color: var(--text-2); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .val { text-align: right; font-weight: 650; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: var(--fs-xs); color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Calendar strip (upcoming deadlines) */
.deadline { display: flex; gap: 14px; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.deadline:last-child { border-bottom: 0; }
.datebox { width: 46px; flex: none; text-align: center; border-radius: 10px; border: 1px solid var(--border); overflow: hidden; }
.datebox small { display: block; background: var(--brand); color: var(--on-brand); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 0; }
.datebox b { display: block; font-size: 17px; padding: 3px 0 4px; }
.datebox.is-urgent small { background: var(--s-overdue); }

/* Announcement */
.announce { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.announce:last-child { border-bottom: 0; }
.announce .pin { color: var(--accent); }

/* Auth pages */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface);
}
.auth__aside {
  position: relative; overflow: hidden; color: #fff; padding: 48px;
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(1200px 600px at -10% 110%, color-mix(in srgb, var(--accent) 55%, transparent), transparent 60%),
    linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
}
.auth__aside .brand-mark { background: rgba(255, 255, 255, .16); color: #fff; width: 44px; height: 44px; }
.auth__aside h1 { font-size: 34px; line-height: 1.15; max-width: 460px; }
.auth__aside p { color: rgba(255, 255, 255, .82); max-width: 440px; margin-top: 14px; font-size: 15px; }
.auth__points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth__points li { display: flex; gap: 10px; align-items: center; color: rgba(255, 255, 255, .92); }
.auth__points .icon { width: 18px; height: 18px; }
.auth__pattern { position: absolute; right: -80px; top: -80px; width: 360px; height: 360px; border-radius: 50%; border: 60px solid rgba(255, 255, 255, .06); }
.auth__main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.auth__card { width: 100%; max-width: 400px; }
.auth__card h2 { font-size: 24px; }
.auth__card .lead { color: var(--text-2); margin: 6px 0 26px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-3); font-size: var(--fs-xs); margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.code-input { display: flex; gap: 8px; }
.code-input input { width: 100%; height: 52px; text-align: center; font-size: 20px; font-weight: 700; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); }
.code-input input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }

/* Theme editor */
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.swatch { border: 2px solid transparent; border-radius: 12px; padding: 4px; cursor: pointer; background: none; }
.swatch.is-active { border-color: var(--text); }
.swatch span { display: block; height: 40px; border-radius: 8px; position: relative; overflow: hidden; }
.swatch span::after { content: ""; position: absolute; right: 0; bottom: 0; width: 40%; height: 40%; background: var(--sw-accent); border-top-left-radius: 8px; }
.swatch small { display: block; text-align: center; font-size: 11.5px; font-weight: 600; margin-top: 4px; color: var(--text-2); }
.color-field { display: flex; align-items: center; gap: 10px; }
.color-field input[type="color"] { width: 46px; height: 42px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.contrast-ok { color: var(--success); font-size: var(--fs-xs); font-weight: 600; }
.contrast-bad { color: var(--danger); font-size: var(--fs-xs); font-weight: 600; }
.logo-drop { display: flex; align-items: center; gap: 16px; }
.logo-drop .brand-mark { width: 64px; height: 64px; font-size: 22px; border-radius: 16px; }
.preview-frame { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; background: var(--bg); }
.preview-frame .pv-top { height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.preview-frame .pv-body { display: grid; grid-template-columns: 120px 1fr; min-height: 220px; }
.preview-frame .pv-side { background: var(--surface); border-right: 1px solid var(--border); padding: 10px 8px; }
.preview-frame .pv-link { height: 26px; border-radius: 7px; margin-bottom: 5px; background: var(--surface-3); }
.preview-frame .pv-link.on { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.preview-frame .pv-main { padding: 14px; display: grid; gap: 10px; align-content: start; }

/* Component kit page */
.kit-section { scroll-margin-top: 80px; }
.kit-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.token { display: flex; align-items: center; gap: 10px; }
.token i { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border); }
.token code { font-family: var(--mono); font-size: 12px; color: var(--text-2); }

/* Utility */
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 24px; }
.mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.hide-desktop { display: none !important; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 5. Responsive ---------- */
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .profile-btn .who { display: none; }
}

@media (max-width: 1024px) {
  .app, .app.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }
  .app .brand-name, .app .nav-section__title, .app .nav-link span, .app .nav-link .count, .app .sidebar__foot span { display: none; }
  .app .nav-link { justify-content: center; padding: 10px; }
  .app .sidebar__brand { justify-content: center; padding: 0; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .switcher .label, .switcher .txt { display: none; }
}

/* Phones: dedicated layout, not a shrunk desktop */
@media (max-width: 760px) {
  :root { --topbar-h: 56px; }
  body { font-size: 15px; }
  .app, .app.is-collapsed { display: block; }
  .sidebar { display: none; }
  .topbar { padding: 0 8px 0 14px; gap: 4px; }
  .topbar__search, .switcher, .topbar .hide-phone { display: none; }
  .topbar__title { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .topbar__title .brand-mark { width: 32px; height: 32px; font-size: 13px; border-radius: 9px; }
  .topbar__title .ellipsis { max-width: 46vw; }
  .content { padding: 18px 14px calc(var(--bottomnav-h) + 28px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 16px; align-items: flex-start; }
  .page-head h1 { font-size: 22px; }
  .page-head__actions { width: 100%; }
  .page-head__actions .btn { flex: 1; }
  .hide-phone { display: none !important; }
  .hide-desktop { display: initial !important; }
  .grid { gap: 12px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stack { gap: 12px; }
  .card { border-radius: var(--r-lg); }
  .card__head { padding: 14px 16px; }
  .card__body { padding: 16px; }
  .list-item { padding: 13px 16px; }
  .stat { padding: 14px; }
  .stat__value { font-size: 24px; margin-top: 8px; }
  .btn { height: 44px; }
  .btn-sm { height: 36px; }
  .input, .select { height: 46px; font-size: 16px; } /* 16px prevents iOS zoom */
  .textarea { font-size: 16px; }
  .icon-btn { width: 44px; height: 44px; }
  .filterbar { padding: 12px 14px; }
  .filterbar .input-group { max-width: none; min-width: 100%; }
  .filterbar .select { flex: 1; min-width: 0; }
  .pagination { padding: 12px 14px; }
  .pagination .info { display: none; }
  .bar-row { grid-template-columns: 90px 1fr 40px; }
  .task-row { flex-direction: column; gap: 6px; }
  .task-row .grow { width: 100%; }
  .kv { grid-template-columns: 100px 1fr; }
  .deadline { padding: 12px 16px; }
  .announce { padding: 14px 16px; }

  /* Tables turn into stacked cards */
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { padding: 12px 16px; border-bottom: 1px solid var(--border); position: relative; }
  .table-cards tr:last-child { border-bottom: 0; }
  .table-cards td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
  .table-cards td[data-label]::before { content: attr(data-label); color: var(--text-3); font-size: 13px; font-weight: 500; }
  .table-cards td.cell-primary { display: block; padding-bottom: 8px; padding-right: 44px; }
  .table-cards td.cell-primary::before { display: none; }
  .table-cards td.actions { position: absolute; top: 8px; right: 8px; width: auto; padding: 0; }
  .table-cards td.actions::before { display: none; }
  .table-cards td.actions .btn:not(.icon-btn) { display: none; }

  /* Bottom navigation */
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(15, 27, 42, .06);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 11px; font-weight: 600; color: var(--text-3); border: 0; background: none; position: relative; cursor: pointer;
  }
  .bottom-nav a:hover { text-decoration: none; }
  .bottom-nav .icon { width: 23px; height: 23px; }
  .bottom-nav .is-active { color: var(--brand-strong); }
  .bottom-nav .is-active::before { content: ""; position: absolute; top: 0; width: 32px; height: 3px; border-radius: 0 0 3px 3px; background: var(--brand); }
  .bottom-nav .badge-num { position: absolute; top: 7px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 10px; display: grid; place-items: center; border: 2px solid var(--surface); }

  .more-sheet { display: block; position: fixed; inset: 0; z-index: 90; pointer-events: none; visibility: hidden; transition: visibility 0s .25s; }
  .more-sheet .scrim { position: absolute; inset: 0; background: rgba(10, 18, 28, .4); opacity: 0; transition: opacity .2s; }
  .more-sheet .sheet {
    position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto;
    background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 14px calc(24px + env(safe-area-inset-bottom));
    transform: translateY(100%); transition: transform .25s ease;
  }
  .more-sheet .grabber { width: 40px; height: 5px; border-radius: 99px; background: var(--border-strong); margin: 4px auto 12px; }
  .more-sheet.is-open { pointer-events: auto; visibility: visible; transition: none; }
  .more-sheet.is-open .scrim { opacity: 1; }
  .more-sheet.is-open .sheet { transform: none; }
  .sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .sheet-grid a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 14px; color: var(--text); font-size: 12px; font-weight: 550; text-align: center; }
  .sheet-grid a:hover { background: var(--surface-3); text-decoration: none; }
  .sheet-grid .ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-strong); }
  .sheet-title { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 14px 6px 6px; }

  /* Modals become bottom sheets */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: none; border-radius: 22px 22px 0 0; max-height: 92vh; }
  .modal__head { padding: 16px 18px; }
  .modal__body { padding: 18px; }
  .modal__foot { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .modal__foot .btn { flex: 1; }
  .popover { position: fixed; left: 12px; right: 12px; top: 62px; width: auto; }
  .toast-host { left: 12px; right: 12px; bottom: calc(var(--bottomnav-h) + 12px); }
  .toast { max-width: none; }

  /* Auth */
  .auth { grid-template-columns: 1fr; }
  .auth__aside { padding: 28px 22px 34px; min-height: 0; }
  .auth__aside h1 { font-size: 24px; margin-top: 22px; }
  .auth__aside p, .auth__points { display: none; }
  .auth__main { padding: 28px 20px 40px; align-items: flex-start; }

  .swatches { grid-template-columns: repeat(3, 1fr); }
  .preview-frame .pv-body { grid-template-columns: 1fr; }
  .preview-frame .pv-side { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .sidebar, .topbar, .bottom-nav, .more-sheet, .page-head__actions, .proto-ribbon { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
