:root {
  color-scheme: light dark;
  --bg-light: #f4f6fb;
  --bg-dark: #0f1320;
  --surface-light: #ffffff;
  --surface-dark: #171c2e;
  --tint-light: #eef1fa;
  --tint-dark: #202740;
  --line-light: #dde2f0;
  --line-dark: #2c3554;
  --ink-light: #161b2e;
  --ink-dark: #eef2ff;
  --muted-light: #59627d;
  --muted-dark: #9ea8c9;
  --brand-light: #3a48c4;
  --brand-dark: #8895ff;
  --on-brand-light: #ffffff;
  --on-brand-dark: #101531;
  --wash-light: #e9ecfb;
  --wash-dark: #262f59;
  --ok-light: #146c43;
  --ok-dark: #63e2a5;
  --ok-bg-light: #e8f7ef;
  --ok-bg-dark: #153528;
  --warn-light: #9a5b00;
  --warn-dark: #f7c768;
  --warn-bg-light: #fff6e5;
  --warn-bg-dark: #3a2d15;
  --err-light: #b4233c;
  --err-dark: #ff9cb0;
  --err-bg-light: #fdecef;
  --err-bg-dark: #3f1d28;

  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --tint: var(--tint-light);
  --line: var(--line-light);
  --ink: var(--ink-light);
  --muted: var(--muted-light);
  --brand: var(--brand-light);
  --on-brand: var(--on-brand-light);
  --wash: var(--wash-light);
  --ok: var(--ok-light);
  --ok-bg: var(--ok-bg-light);
  --warn: var(--warn-light);
  --warn-bg: var(--warn-bg-light);
  --err: var(--err-light);
  --err-bg: var(--err-bg-light);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(18, 25, 56, 0.06);
  accent-color: var(--brand);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --tint: var(--tint-dark);
    --line: var(--line-dark);
    --ink: var(--ink-dark);
    --muted: var(--muted-dark);
    --brand: var(--brand-dark);
    --on-brand: var(--on-brand-dark);
    --wash: var(--wash-dark);
    --ok: var(--ok-dark);
    --ok-bg: var(--ok-bg-dark);
    --warn: var(--warn-dark);
    --warn-bg: var(--warn-bg-dark);
    --err: var(--err-dark);
    --err-bg: var(--err-bg-dark);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--bg-dark);
  --surface: var(--surface-dark);
  --tint: var(--tint-dark);
  --line: var(--line-dark);
  --ink: var(--ink-dark);
  --muted: var(--muted-dark);
  --brand: var(--brand-dark);
  --on-brand: var(--on-brand-dark);
  --wash: var(--wash-dark);
  --ok: var(--ok-dark);
  --ok-bg: var(--ok-bg-dark);
  --warn: var(--warn-dark);
  --warn-bg: var(--warn-bg-dark);
  --err: var(--err-dark);
  --err-bg: var(--err-bg-dark);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 999;
  background: var(--brand); color: var(--on-brand); padding: 8px 14px; border-radius: var(--radius-sm);
  text-decoration: none; font-weight: 600;
}
.skip-link:focus { top: 12px; }

/* Auth Shell */
.auth-shell {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.auth-card {
  width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand h1 { margin: 2px 0 0; font-size: 22px; line-height: 1.2; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--brand); color: var(--on-brand); font-weight: 800; font-size: 16px; flex: none;
}

/* App Shell */
.app-shell { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 14px; min-height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--line); flex: none;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.brand-btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent;
  color: var(--ink); cursor: pointer; padding: 4px 6px; border-radius: var(--radius-sm);
}
.brand-btn:hover { background: var(--tint); }
.brand-title { font-weight: 700; font-size: 15px; }
.primary-nav { display: flex; align-items: center; gap: 4px; margin-inline-start: 6px; }
.nav-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.nav-btn:hover { background: var(--tint); color: var(--ink); }
.nav-btn[aria-current="page"] { background: var(--wash); color: var(--brand); }

/* Multi-Project Open Tabs */
.open-tabs {
  display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0;
  overflow-x: auto; scrollbar-width: none; padding: 0 4px;
}
.open-tabs::-webkit-scrollbar { display: none; }
.proj-tab {
  display: inline-flex; align-items: center; gap: 6px; max-width: 210px;
  padding: 5px 8px 5px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--tint); color: var(--ink);
  font-size: 12.5px; font-weight: 600; cursor: pointer; flex: none;
}
.proj-tab[aria-selected="true"] { background: var(--wash); border-color: var(--brand); color: var(--brand); }
.proj-tab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-tab-dot { width: 7px; height: 7px; border-radius: 99px; background: var(--warn); flex: none; }
.proj-tab-close {
  border: 0; background: transparent; color: inherit; opacity: 0.7; cursor: pointer;
  padding: 0 3px; font-size: 14px; line-height: 1; border-radius: 4px;
}
.proj-tab-close:hover { opacity: 1; background: rgba(128, 128, 128, 0.2); }

.user-chip { display: inline-flex; align-items: center; gap: 8px; padding: 2px 6px; }
.user-chip-text { display: flex; flex-direction: column; line-height: 1.15; }
.avatar {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 999px;
  color: #fff; font-weight: 700; font-size: 12px; flex: none;
}
.presence-cluster { display: inline-flex; align-items: center; gap: 4px; }
.presence-dot {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px 3px 4px;
  border-radius: 999px; background: var(--tint); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink); white-space: nowrap;
}
.presence-dot .avatar { width: 20px; height: 20px; font-size: 10px; }

/* Main & Page Views */
.main-content { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.page-view {
  flex: 1; overflow-y: auto; padding: 28px clamp(16px, 3vw, 40px) 48px;
  display: flex; flex-direction: column; gap: 20px; max-width: 1320px; width: 100%; margin: 0 auto;
}
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head h1 { margin: 2px 0 4px; font-size: 26px; line-height: 1.2; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.eyebrow { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: 0.08em; color: var(--brand); text-transform: uppercase; }
.muted { margin: 0; color: var(--muted); }
.muted-sm { margin: 0; color: var(--muted); font-size: 13px; }
.muted-xs { color: var(--muted); font-size: 11.5px; }

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: var(--on-brand); }
.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn--secondary:hover { background: var(--tint); }
.btn--ghost { background: transparent; color: var(--ink); }
.btn--ghost:hover { background: var(--tint); }
.btn--warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.btn--danger { background: var(--err-bg); color: var(--err); border-color: var(--err); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; }
.btn--full { width: 100%; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }

.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.field input, .field select, .field textarea, .input {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 11px;
}
.input { min-width: 220px; flex: 1; }
.input--compact { flex: 0 1 190px; min-width: 150px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* Pills & Alerts */
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
  border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--tint); color: var(--ink);
}
.pill--brand { background: var(--wash); color: var(--brand); }
.pill--ok { background: var(--ok-bg); color: var(--ok); }
.pill--warn { background: var(--warn-bg); color: var(--warn); }
.pill--neutral { background: var(--tint); color: var(--muted); }

.alert {
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  font-size: 13px; display: flex; flex-direction: column; gap: 8px;
}
.alert--error { background: var(--err-bg); color: var(--err); border-color: var(--err); }
.alert--ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }

/* Projects Grid */
.projects-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 16px;
}
.project-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.project-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.project-card h2 { margin: 0; font-size: 17px; line-height: 1.25; }
.project-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12.5px; color: var(--muted); }
.project-card-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-top: 10px; border-top: 1px solid var(--line);
}

/* Panels & Responsive Tables */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.online-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.online-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: var(--radius-sm); background: var(--tint); border: 1px solid var(--line);
}

.table-wrapper {
  overflow: auto; max-inline-size: 100%; max-block-size: min(560px, 68vh);
  container-type: inline-size; padding: 0;
}
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data-table thead { position: sticky; inset-block-start: 0; z-index: 1; background: var(--tint); }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--line); vertical-align: middle;
}
.data-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.data-table tbody tr:hover { background: var(--tint); }

@container (width < 660px) {
  .data-table, .data-table thead, .data-table tbody, .data-table tr, .data-table th, .data-table td { display: block; }
  .data-table thead { display: none; }
  .data-table tr { margin: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
  .data-table td { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); }
  .data-table td:last-child { border-bottom: 0; }
  .data-table td::before { content: attr(data-label); font-weight: 700; color: var(--muted); }
}

/* Workspace (Full Embedded MakeUIUXEasy Studio) */
.workspace-view { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.ws-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 14px; background: var(--tint); border-bottom: 1px solid var(--line); flex: none;
  flex-wrap: wrap;
}
.ws-bar-left, .ws-bar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ws-sep { color: var(--muted); }
.ws-title { font-size: 14px; }
.ws-status { font-size: 12px; color: var(--muted); }
.ws-status--dirty { color: var(--warn); font-weight: 600; }
.ws-status--ok { color: var(--ok); font-weight: 600; }
.ws-body { flex: 1; min-height: 0; display: flex; position: relative; }
.ws-frame-host { flex: 1; min-width: 0; position: relative; display: flex; }
.studio-frame { width: 100%; height: 100%; border: 0; background: var(--bg); }
.ws-loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--muted); font-weight: 600; z-index: 2;
}
.ws-drawer {
  width: min(360px, 100%); border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0; flex: none;
}
.ws-drawer-head {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.ws-drawer-head h2 { margin: 0; font-size: 14px; }
.drawer-presence { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; }
.activity-feed { list-style: none; margin: 0; padding: 10px 14px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.feed-item {
  display: flex; gap: 9px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--tint); border: 1px solid var(--line); font-size: 12.5px;
}
.feed-item-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.feed-item-meta { font-size: 11px; color: var(--muted); }

/* Native Modal Dialogs (per Modern Web Guidance) */
dialog {
  padding: 0; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  max-width: min(94vw, 860px); width: fit-content;
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop {
  background: rgba(12, 16, 32, 0.55); backdrop-filter: blur(3px);
  overflow: hidden; overscroll-behavior: contain;
}
.dialog-body { padding: 22px; width: min(460px, 88vw); display: flex; flex-direction: column; gap: 14px; }
.dialog-body--wide { width: min(820px, 92vw); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h1 { margin: 0; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }

/* Sync Modal */
.sync-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.sync-card {
  background: var(--tint); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.sync-card h2 { margin: 0; font-size: 15px; }
.code-row {
  display: flex; align-items: flex-start; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px;
}
.code-row code {
  flex: 1; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 11.5px;
  line-height: 1.45; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.fsa-box { padding-top: 4px; }

/* Keyboard shortcut badge & Command Palette trigger */
kbd {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 1px 6px; font-size: 11px; font-weight: 700; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--tint); color: var(--ink); border: 1px solid var(--line); border-radius: 6px;
}
.cmd-trigger {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px;
  background: var(--tint); color: var(--muted); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 12.5px; cursor: pointer;
}
.cmd-trigger:hover { border-color: var(--brand); color: var(--ink); }

.input--xs { padding: 4px 8px; font-size: 12px; border-radius: 8px; width: auto; min-width: 0; flex: none; }
.btn--follow { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); font-weight: 700; }
.btn--follow:hover { background: var(--brand); color: #fff; }
.pin-btn {
  background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 3px 5px; color: var(--muted);
}
.pin-btn:hover { background: var(--tint); color: var(--warn); }
.pin-btn[aria-pressed="true"] { color: var(--warn); }

.presence-dot--btn { cursor: pointer; }
.presence-dot--btn:hover { border-color: var(--brand); background: var(--brand-soft); }
.presence-dot--following { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 25%, transparent); }
.online-card--btn { cursor: pointer; text-align: left; font: inherit; color: inherit; }
.online-card--btn:hover { border-color: var(--brand); background: var(--brand-soft); }

.drawer-note-form {
  display: flex; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.drawer-note-form input { flex: 1; min-width: 0; }
.feed-item--note { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 30%, var(--line)); }
.feed-link {
  background: none; border: 0; padding: 0; color: var(--brand); font: inherit;
  text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}

/* Built-in How-to-Use Guide */
.guide-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px;
}
.guide-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow);
}
.guide-card > .pill { align-self: flex-start; }
.guide-card--wide { grid-column: 1 / -1; }
.guide-card h2 { margin: 2px 0 0; font-size: 16px; }
.guide-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; font-size: 13.5px; line-height: 1.5; }
.guide-cmds { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.guide-cmd-item { display: flex; flex-direction: column; gap: 4px; }
.shortcut-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.shortcut-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: var(--tint); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 13px;
}

/* Interactive Onboarding Wizard */
.dialog-body--wizard { width: min(640px, 92vw); padding: 24px; gap: 18px; }
.wizard-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wizard-dots { display: flex; gap: 6px; align-items: center; }
.wizard-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--line); border: 0; padding: 0; cursor: pointer; }
.wizard-dot--active { width: 22px; background: var(--brand); }
.wizard-stage { display: flex; flex-direction: column; gap: 14px; min-height: 230px; }
.wizard-hero {
  padding: 18px; border-radius: var(--radius); background: linear-gradient(135deg, var(--brand-soft), var(--tint));
  border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px;
}
.wizard-hero h2 { margin: 0; font-size: 20px; }
.wizard-hero p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.wizard-highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.wizard-tile {
  padding: 12px; border-radius: var(--radius-sm); background: var(--tint);
  border: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; font-size: 12.5px;
}
.wizard-tile strong { font-size: 13px; }
.wizard-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-top: 10px; border-top: 1px solid var(--line); flex-wrap: wrap;
}
.wizard-check { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; }

/* Command Palette */
.palette-box { width: min(580px, 92vw); display: flex; flex-direction: column; }
.palette-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.palette-input {
  flex: 1; border: 0; outline: 0; background: transparent; color: var(--ink);
  font-size: 15px; font-family: inherit;
}
.palette-list {
  list-style: none; margin: 0; padding: 8px; max-height: 360px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.palette-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
}
.palette-item:hover, .palette-item[aria-selected="true"] { background: var(--brand-soft); color: var(--brand); }
.palette-item-meta { font-size: 11.5px; color: var(--muted); }
.palette-foot {
  display: flex; gap: 16px; padding: 8px 16px; border-top: 1px solid var(--line); background: var(--tint);
}

/* Toast */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 1000;
  background: var(--ink); color: var(--surface); padding: 10px 16px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 13px; box-shadow: var(--shadow);
}
