:root,
[data-theme="dark"] {
  --bg: #16171a;
  --bg-2: #1e1f23;
  --bg-3: #26272c;
  --surface: #1e1f23;
  --border: #34353b;
  --border-soft: #2c2d32;
  --text: #e8eaed;
  --text-dim: #9aa0a8;
  --text-faint: #7d828a;
  --accent: #22d3ee;
  --accent-hover: #67e8f9;
  --accent-soft: rgba(34, 211, 238, 0.12);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.14);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 6px 20px -10px rgba(0, 0, 0, 0.5);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Classic navy (the original pumOFFICE look) — opt-in fallback. */
[data-theme="classic"] {
  --bg: #0a0f1c; --bg-2: #111a2e; --bg-3: #162040; --surface: #111a2e;
  --border: #1c2a4a; --border-soft: #1c2a4a;
  --text: #e6edf7; --text-dim: #8ea0b8; --text-faint: #7a8cb5;
}

[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-2: #ffffff;
  --bg-3: #eef1f7;
  --surface: #ffffff;
  --border: #dde2ec;
  --border-soft: #e6eaf2;
  --text: #1a2233;
  --text-dim: #55617a;
  --text-faint: #8b95ab;
  --accent: #0891b2;
  --accent-hover: #0e7490;
  --accent-soft: rgba(8, 145, 178, 0.12);
  --success: #17a05c;
  --success-soft: rgba(23, 160, 92, 0.12);
  --danger: #e14b5a;
  --danger-soft: rgba(225, 75, 90, 0.12);
  --warn: #c9871a;
  --warn-soft: rgba(201, 135, 26, 0.14);
  --shadow-lg: 0 24px 60px -24px rgba(30, 41, 59, 0.25);
  --shadow-sm: 0 6px 20px -12px rgba(30, 41, 59, 0.18);
}

/* Accent theme variants (inherit the dark base, override the accent palette) */
[data-theme="indigo"] {
  --accent: #6366f1; --accent-hover: #818cf8; --accent-soft: rgba(99, 102, 241, 0.14);
  color-scheme: dark;
}
[data-theme="teal"] {
  --accent: #14b8a6; --accent-hover: #2dd4bf; --accent-soft: rgba(20, 184, 166, 0.14);
  color-scheme: dark;
}
[data-theme="violet"] {
  --accent: #a855f7; --accent-hover: #c084fc; --accent-soft: rgba(168, 85, 247, 0.14);
  color-scheme: dark;
}
[data-theme="deepsea"] {
  --accent: #0ea5e9; --accent-hover: #38bdf8; --accent-soft: rgba(14, 165, 233, 0.14);
  --bg: #06121f; --bg-2: #0b1d30; --bg-3: #10263d; --surface: #0b1d30;
  color-scheme: dark;
}
[data-theme="gold"] {
  --accent: #f59e0b; --accent-hover: #fbbf24; --accent-soft: rgba(245, 158, 11, 0.14);
  color-scheme: dark;
}
[data-theme="neon"] {
  --accent: #a3e635; --accent-hover: #bef264; --accent-soft: rgba(163, 230, 53, 0.14);
  color-scheme: dark;
}
[data-theme="cobalt"] {
  --accent: #3b82f6; --accent-hover: #60a5fa; --accent-soft: rgba(59, 130, 246, 0.14);
  color-scheme: dark;
}

/* smooth theme transitions */
body, .topbar, .sidebar, .toolbar, .editor-pane, .user-menu, .modal,
.text-input, .btn-secondary, .file-item, .user-row {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app-shell { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Auth gate (login / setup) ---------- */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex;
  background:
    radial-gradient(ellipse 800px 600px at 50% 30%, rgba(34, 211, 238, 0.07), transparent 70%),
    radial-gradient(ellipse 600px 400px at 15% 90%, rgba(99, 102, 241, 0.05), transparent 60%),
    #060a14;
}
.auth-gate[hidden] { display: none; }

.gate-side {
  flex: 0 0 42%;
  display: flex; align-items: center; justify-content: center;
  padding: 48px;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  background:
    radial-gradient(700px 500px at 30% 20%, rgba(34, 211, 238, 0.12), transparent 60%),
    linear-gradient(180deg, #0d1526, #060a14);
}
.gate-brand { max-width: 380px; }
.gate-brand .brand-mark {
  width: 76px; height: 76px; border-radius: 20px;
  display: grid; place-items: center; color: #0b1626;
  background: linear-gradient(135deg, var(--accent), #0891b2);
  box-shadow: 0 0 40px rgba(34, 211, 238, 0.35);
}
.gate-brand h1 {
  margin-top: 26px; font-size: clamp(32px, 4vw, 44px); font-weight: 900;
  letter-spacing: -1.5px;
  background: linear-gradient(180deg, #fff 30%, #8aa0bf 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.gate-brand h1 span {
  font-style: normal;
  background: linear-gradient(135deg, #22d3ee 0%, #0891b2 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.gate-brand p { margin-top: 16px; font-size: 16px; line-height: 1.7; color: var(--text-dim); }

.gate-main {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 32px; position: relative;
}
.gate-card {
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 16px;
}
.gate-card h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; margin-bottom: 4px; }
.gate-field { display: flex; flex-direction: column; gap: 7px; }
.gate-field[hidden] { display: none; }
.gate-field .opt { font-weight: 400; color: var(--text-faint); }
.gate-card .text-input {
  padding: 12px 14px; font-size: 14px;
  background: #0d1526; border-color: rgba(255, 255, 255, 0.08);
}
.gate-card #submitAuth { margin-top: 6px; padding: 12px 14px; font-size: 14px; }
.gate-links { margin-top: 6px; display: flex; justify-content: center; }
.gate-links[hidden] { display: none; }

.gate-foot {
  position: absolute; bottom: 22px;
  font-size: 12px; color: var(--text-faint); text-align: center;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 18px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #0891b2);
  box-shadow: 0 6px 18px -6px rgba(34, 211, 238, 0.5);
}

.brand-name { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-name .accent { color: var(--accent); }
.brand-sub { display: block; font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.conn-pill {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
  padding: 6px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--bg-2);
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); transition: background 0.3s; }
.conn-dot.online { background: var(--success); }
.conn-dot.offline { background: var(--danger); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 999px;
  background: transparent; border: 1px solid transparent;
  color: var(--text); cursor: pointer; font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.user-chip:hover { background: var(--bg-2); border-color: var(--border-soft); }
.user-caret { color: var(--text-faint); transition: transform 0.15s; }
.user-chip[aria-expanded="true"] .user-caret { transform: rotate(180deg); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #8a63d2, #6a4bb0);
}
.user-avatar.muted { background: linear-gradient(135deg, #4a536a, #2f3850); }
[data-theme="light"] .user-avatar.muted { background: linear-gradient(135deg, #c3cad9, #a5aec2); }
.user-name { font-size: 13px; color: var(--text); }

.user-menu {
  position: absolute; top: 52px; right: 16px; z-index: 70;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px; overflow: hidden;
}
.user-menu[hidden] { display: none; }
.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  border: 0; background: transparent; border-radius: var(--radius-sm);
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 500;
  text-align: left; cursor: pointer;
  transition: background 0.12s;
}
.user-menu-item:hover { background: var(--bg-2); }
.user-menu-item[hidden] { display: none; }
.user-menu-item svg { color: var(--text-dim); flex-shrink: 0; }
.user-menu-item .menu-right { margin-left: auto; color: var(--text-faint); font-size: 11px; }
.user-menu-sep { height: 1px; background: var(--border-soft); margin: 6px 4px; }

.setup-notice {
  background: var(--accent-soft);
  border: 1px solid rgba(34, 211, 238, 0.4);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px; line-height: 1.5; color: var(--text);
  margin-bottom: 16px;
}
.setup-notice[hidden] { display: none; }
.setup-notice strong { color: var(--accent-hover); }
.auth-error {
  background: var(--danger-soft);
  border: 1px solid rgba(255, 93, 108, 0.4);
  border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 13px; color: var(--danger);
  margin-top: 14px;
}
.auth-error[hidden] { display: none; }
.auth-foot-left { margin-right: auto; }
.btn-link {
  background: none; border: 0; color: var(--text-dim);
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  padding: 4px 2px;
}
.btn-link:hover { color: var(--accent-hover); text-decoration: underline; }
.modal-wide { max-width: 620px; }
.modal-tall { max-height: 88vh; display: flex; flex-direction: column; }
.modal-tall .modal-body { flex: 1; min-height: 0; overflow-y: auto; }

.users-form {
  display: grid; grid-template-columns: 1fr 1fr 1fr auto auto;
  gap: 8px; margin-bottom: 14px;
}
.users-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.user-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
}
.user-row .is-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
  font-size: 12px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #22d3ee, #0891b2);
}
.user-row .u-info { flex: 1; min-width: 0; }
.user-row .u-name { font-size: 13px; font-weight: 500; color: var(--text); }
.user-row .u-username { font-size: 11px; color: var(--text-faint); }
.user-row .u-role {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
}
.user-row .u-role.admin { background: var(--accent-soft); color: var(--accent-hover); }
.user-row .u-role.user { background: var(--bg-3); color: var(--text-dim); }
.user-row.is-self .u-name { color: var(--accent-hover); }

/* Role badge */
.doc-submeta { display: flex; align-items: center; gap: 8px; }
.role-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 2px 8px; border-radius: 999px;
}
.role-badge[hidden] { display: none; }
.role-badge.viewer { background: var(--bg-3); color: var(--text-faint); border: 1px solid var(--border); }
.role-badge.editor { background: var(--accent-soft); color: var(--accent-hover); border: 1px solid rgba(79,140,255,0.4); }
.role-badge.admin { background: var(--success-soft); color: var(--success); border: 1px solid rgba(52,199,123,0.4); }

/* Admin panel tabs */
.admin-tabs {
  display: flex; gap: 4px; padding: 8px 20px 0;
  border-bottom: 1px solid var(--border-soft); background: var(--bg-2);
}
.admin-tab {
  padding: 9px 16px; border: 0; background: transparent; color: var(--text-dim);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; transition: color 0.12s, border-color 0.12s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent-hover); border-bottom-color: var(--accent); }
.admin-pane[hidden] { display: none; }
.admin-pane { padding-top: 14px; }
.admin-toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.admin-search { flex: 1; }
.users-list .user-row .u-role { cursor: default; }
.role-select {
  font-size: 12px; padding: 4px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text);
  font-family: inherit; cursor: pointer;
}
.acl-form { grid-template-columns: 1fr 1fr auto auto; }
.audit-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--bg-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); font-size: 12px; color: var(--text-dim);
  margin-bottom: 5px;
}
.audit-row .a-action { font-weight: 600; color: var(--text); }
.audit-row .a-time { margin-left: auto; color: var(--text-faint); flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

/* The `hidden` attribute must always win, even over explicit display rules
   (e.g. .btn sets inline-flex). Without this, buttons toggled via .hidden
   (Forge/Back) stay visible. */
[hidden] { display: none !important; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn svg { flex-shrink: 0; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent-hover); }

.btn-secondary { background: var(--bg-3); color: var(--text); border-color: var(--border); }
.btn-secondary:not(:disabled):hover { background: var(--bg-2); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn-danger:not(:disabled):hover { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-2); color: var(--text); }

.btn-block { width: 100%; justify-content: center; }

.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-2); color: var(--text); }
.icon-btn[disabled], .icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Workspace ---------- */
.workspace { display: flex; flex: 1; min-height: 0; }

/* Sidebar */
.sidebar {
  width: 280px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 10px;
}
.sidebar-title { font-size: 13px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }

.file-list { flex: 1; overflow-y: auto; padding: 4px 10px; }

.file-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  margin-bottom: 2px;
}
.file-item:hover { background: var(--bg-2); }
.file-item.active { background: var(--accent-soft); border-color: rgba(34, 211, 238, 0.4); }

.file-menu-btn {
  display: none; place-items: center;
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 6px; border: 0; background: var(--bg-3);
  color: var(--text-dim); cursor: pointer;
}
.file-menu-btn:hover { color: var(--text); background: var(--border); }
.file-item:hover .file-menu-btn, .file-item.menu-open .file-menu-btn { display: grid; }
.file-menu {
  position: absolute; right: 12px; z-index: 30;
  min-width: 170px; padding: 5px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.file-menu[hidden] { display: none; }
.file-item .file-menu { top: 40px; }
.file-menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 8px 10px; border: 0; background: transparent;
  border-radius: 6px; color: var(--text);
  font-family: inherit; font-size: 13px; cursor: pointer;
}
.file-menu-item svg { flex-shrink: 0; color: var(--text-faint); }
.file-menu-item:hover { background: var(--bg-2); }
.file-menu-item.act-delete { color: var(--danger); }
.file-menu-item.act-delete svg { color: var(--danger); }
.file-menu-item.act-delete:hover { background: var(--danger-soft); }
.file-menu-sep {
  height: 1px; margin: 5px 2px; background: var(--border-soft);
}

.file-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 7px; color: #fff;
}
.file-icon.word { background: linear-gradient(135deg, #0ea5e9, #0891b2); }
.file-icon.cell { background: linear-gradient(135deg, #2fb46e, #1e8a50); }
.file-icon.slide { background: linear-gradient(135deg, #f68a2f, #d4622a); }
.file-icon.text { background: linear-gradient(135deg, #7a8aa0, #5c6780); }

.file-info { min-width: 0; flex: 1; }
.file-name { font-size: 13px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.empty-state { text-align: center; padding: 28px 12px; color: var(--text-faint); }
.empty-state p { font-size: 13px; }
.empty-state .hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border-soft); }

/* Storage allowance meter */
.storage-meter { margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--bg-2); border: 1px solid var(--border-soft); }
.storage-meter-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--text-dim); font-weight: 600; }
.storage-meter-head #storagePct { color: var(--text-faint); font-weight: 500; }
.storage-bar { height: 6px; border-radius: 4px; background: var(--border-soft); overflow: hidden; margin: 8px 0 6px; }
.storage-bar span { display: block; height: 100%; width: 0; border-radius: 4px; background: linear-gradient(90deg, var(--accent), #0891b2); transition: width .3s; }
.storage-bar span.over { background: linear-gradient(90deg, var(--danger), #e14b5a); }
.storage-meta { font-size: 11px; color: var(--text-faint); }

/* Editor pane */
.editor-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.doc-meta { min-width: 0; }
.doc-name { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.doc-state { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.doc-state.saving { color: var(--warn); }
.doc-state.saved { color: var(--success); }
.doc-state.error { color: var(--danger); }

.toolbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

.editor-frame { flex: 1; min-height: 0; position: relative; }

/* Forge AI assistant */
.forge-panel {
  position: absolute; right: 16px; top: 16px; z-index: 20;
  width: 380px; max-height: calc(100% - 32px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.forge-panel[hidden] { display: none; }
.forge-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border-soft);
  background: var(--bg-2);
}
.forge-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; color: var(--accent-hover);
}
.forge-actions {
  display: flex; gap: 8px; padding: 12px 14px 4px; flex-wrap: wrap;
}
.forge-action {
  padding: 7px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-3);
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.12s, border-color 0.12s;
}
.forge-action:hover { background: var(--border); border-color: var(--accent); }
.forge-action:disabled { opacity: 0.5; cursor: not-allowed; }
.forge-source { padding: 12px 14px; }
.forge-input {
  width: 100%; min-height: 110px; resize: vertical;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-2);
  color: var(--text); font-family: inherit; font-size: 13px; line-height: 1.5;
}
.forge-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.forge-output { padding: 0 14px 14px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.forge-output[hidden] { display: none; }
.forge-answer {
  flex: 1; overflow-y: auto; padding: 12px;
  background: var(--bg-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 13px; line-height: 1.6; color: var(--text); white-space: pre-wrap;
}
.forge-status {
  padding: 10px 14px; font-size: 12px; color: var(--text-faint);
  border-top: 1px solid var(--border-soft);
}
.forge-status[hidden] { display: none; }
.forge-status.loading { color: var(--accent-hover); }
@media (max-width: 640px) {
  .forge-panel { width: calc(100% - 32px); }
}
.editor-frame iframe { width: 100%; height: 100%; border: 0; display: block; }

.editor-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 24px; text-align: center; padding: 32px;
  color: var(--text-faint);
}
.editor-placeholder[hidden] { display: none; }
.placeholder-icon { color: var(--text-faint); opacity: 0.5; }
.editor-placeholder h3 { color: var(--text-dim); font-size: 20px; font-weight: 600; }

/* Welcome hub (create / open) */
.hub-head { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hub-icon { color: var(--text-faint); opacity: 0.35; }
.hub-head p { max-width: 460px; font-size: 13px; line-height: 1.6; }
.hub-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px; width: 100%; max-width: 560px;
}
.hub-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 22px 12px 16px;
  background: var(--bg-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius); cursor: pointer;
  color: var(--text); font-family: inherit;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.hub-card:hover { background: var(--bg-3); border-color: var(--accent); transform: translateY(-2px); }
.hub-badge {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-size: 17px; font-weight: 700; color: #fff;
}
.hub-badge.word { background: linear-gradient(135deg, #2f7cf6, #3b5bdb); }
.hub-badge.cell { background: linear-gradient(135deg, #2fb46e, #1e8a50); }
.hub-badge.slide { background: linear-gradient(135deg, #f68a2f, #d4622a); }
.hub-badge.text { background: linear-gradient(135deg, #7a8aa0, #5c6780); }
.hub-label { font-size: 13px; font-weight: 600; }
.hub-sub { font-size: 11px; color: var(--text-faint); }
.hub-tagline { color: var(--text-dim); }
.hub-actions { display: flex; gap: 10px; }

/* Subtle pumOFFICE brand watermark behind the workspace/hub */
.app-shell { position: relative; }
.app-shell::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(60% 50% at 15% 0%, var(--accent-soft) 0%, transparent 55%),
    radial-gradient(45% 40% at 92% 95%, var(--accent-soft) 0%, transparent 55%),
    radial-gradient(30% 30% at 80% 8%, var(--accent-soft) 0%, transparent 50%);
}
/* Keep the topbar (and its dropdowns) above the watermark but below modals. */
.app-shell > .topbar { position: relative; z-index: 60; }
.app-shell > .workspace { position: relative; z-index: 1; }

/* Large decorative wordmark in the empty hub area (behind the cards), so the
   pumOFFICE identity is unmistakable when no document is open. */
.editor-placeholder::before {
  content: "pumOFFICE";
  position: absolute; inset: 0; display: grid; place-items: center;
  pointer-events: none; z-index: 0;
  font-size: 11vw; font-weight: 800; letter-spacing: -0.05em;
  color: var(--accent); opacity: 0.07; white-space: nowrap;
}
.editor-placeholder > * { position: relative; z-index: 1; }


/* Recent files panel in the welcome hub */
.hub-recent {
  margin-top: 26px; width: 100%; max-width: 620px; text-align: left;
}
.hub-recent-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.hub-recent-head h4 {
  margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-faint);
}
.hub-recent-list { display: flex; flex-direction: column; gap: 2px; }
.hub-recent-item {
  position: relative;
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--text); font-family: inherit; cursor: pointer;
  text-align: left; transition: background .15s, border-color .15s;
}
.hub-recent-item:hover { background: var(--surface); border-color: var(--border-soft); }
.hub-recent-item .hub-recent-name { flex: 1; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hub-recent-item .hub-recent-meta { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.hub-recent-item .file-menu { top: 38px; right: 12px; }

.sidebar-search { padding: 0 12px 10px; }
.sidebar-search .text-input { width: 100%; padding: 7px 11px; font-size: 13px; }
.filter-row { display: flex; gap: 6px; margin-top: 6px; }
.filter-row .text-input { flex: 1; font-size: 12px; padding: 6px 8px; }
.search-content-check { margin: 4px 0 0 2px; font-size: 12px; }

/* Onboarding first-run guidance */
/* Guided onboarding tour overlay */
.tour-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4, 8, 16, 0.7); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 24px;
}
.tour-backdrop[hidden] { display: none; }
.tour-card {
  width: 100%; max-width: 440px; padding: 26px 28px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.tour-progress { display: flex; gap: 6px; margin-bottom: 16px; }
.tour-progress .dot {
  width: 22px; height: 5px; border-radius: 4px; background: var(--border-soft);
  transition: background .2s;
}
.tour-progress .dot.on { background: var(--accent); }
.tour-card h3 { margin: 0 0 10px; font-size: 19px; font-weight: 700; }
.tour-body { margin: 0 0 22px; color: var(--text-dim); line-height: 1.6; font-size: 14px; }
.tour-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.tour-actions .btn-ghost { margin-right: auto; }

/* Toolbar button grouping */
.tool-group { display: inline-flex; align-items: center; gap: 2px; }
.tool-group.tool-save {
  margin: 0 6px; padding-left: 10px;
  border-left: 1px solid var(--border-soft);
}

/* Reveal the file list sidebar (from hub "View all") */
.sidebar.reveal .file-list { max-height: none; overflow: visible; }

/* Admin settings modal */
.settings-section {
  padding: 14px 0; border-bottom: 1px solid var(--border-soft);
}
.settings-section:last-of-type { border-bottom: 0; }
.settings-section h4 {
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-dim); margin: 6px 0 14px;
}
.settings-section .field-label { margin-top: 12px; }
.settings-section h4 { margin-top: 6px; }
.settings-section .field-label:first-child { margin-top: 0; }
.settings-section .comment { font-size: 12px; color: var(--text-faint); margin: 4px 0 0; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.settings-grid.settings-grid-flex { display: flex; align-items: flex-end; gap: 8px; }
.settings-grid.settings-grid-flex .text-input { flex: 1; }
.settings-grid .text-input { margin-top: 0; }
@media (max-width: 520px) { .settings-grid { grid-template-columns: 1fr; } }
.settings-field { min-width: 0; }
.settings-field .field-label { margin-top: 0; margin-bottom: 6px; }
.settings-field .check-row { margin: 0 0 4px; }
.muted { font-weight: 400; color: var(--text-faint); text-transform: none; }
.settings-danger-row { display: flex; align-items: center; gap: 14px; }
.settings-danger-row .settings-danger-note { flex: 1; margin: 0; }
.settings-danger-row .btn-danger { flex-shrink: 0; }
.settings-deploy {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  padding: 12px 14px;
}
.settings-deploy h4 { color: var(--text-faint); }
.settings-deploy-note { margin: 0 0 12px; font-size: 12px; color: var(--text-faint); line-height: 1.4; }
@media (max-width: 520px) { .settings-danger-row { flex-direction: column; align-items: stretch; } .settings-danger-row .btn-danger { width: 100%; } }
.settings-section.settings-danger {
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  padding: 12px 14px;
}
.settings-section.settings-danger h4 { color: var(--danger); margin-top: 0; }
.settings-danger-note { margin: 0 0 12px; font-size: 13px; color: var(--text-dim); }

.licence-status {
  margin: 6px 0; padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13px; border: 1px solid var(--border-soft); color: var(--text-dim);
}
.licence-status.ok { border-color: var(--success); color: var(--success); background: var(--success-soft); }
.licence-status.err { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.settings-row { margin: 12px 0; }
.check-row {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 0; font-size: 13px; color: var(--text); cursor: pointer;
}
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }
.settings-status {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 13px;
}
.settings-status[hidden] { display: none; }
.settings-status.ok { background: var(--success-soft); color: var(--success); }
.settings-status.err { background: var(--danger-soft); color: var(--danger); }

@media (max-width: 720px) {
  .hub-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(6, 9, 16, 0.7);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%; max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 12px; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 6px 20px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border-soft); background: var(--bg-2); }

.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 8px; }
.new-name-row { display: flex; gap: 8px; }
.new-name-row .text-input:first-child { flex: 1; }
.text-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-family: inherit; font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.text-input.select { width: auto; min-width: 150px; }

/* ---------- Toast ---------- */
.toast-region {
  position: fixed; bottom: 20px; right: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 380px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: toast-in 0.25s ease;
}
.toast.success { border-color: rgba(52, 199, 123, 0.5); background: var(--success-soft); }
.toast.error { border-color: rgba(255, 93, 108, 0.5); background: var(--danger-soft); }
.toast.info { border-color: rgba(34, 211, 238, 0.5); background: var(--accent-soft); }
.toast-ind { font-weight: 700; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2e3b55; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .sidebar { width: 220px; }
  .doc-name { max-width: 30vw; }
  .conn-pill { display: none; }
  .user-name { display: none; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .btn .btn-label { display: none; }
}

/* Drive toggle (Server / Shared) */
.drive-toggle{display:flex;gap:6px;padding:0 12px 10px}
.drive-tab{flex:1;padding:8px 10px;border-radius:8px;border:1px solid var(--border-soft);background:transparent;color:var(--text-dim);font-family:inherit;font-size:12px;font-weight:600;cursor:pointer;transition:.15s;display:flex;align-items:center;justify-content:center;gap:6px}
.drive-tab:hover{background:var(--bg-2);color:var(--text)}
.drive-tab.active{background:var(--accent-soft);color:var(--accent-hover);border-color:var(--accent)}
.drive-badge{font-size:9px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;background:var(--accent);color:#08222e;padding:1px 6px;border-radius:20px}

/* Team modal */
.team-invite{display:flex;gap:8px;margin-bottom:14px}
.team-invite .text-input{flex:1}
.team-list{display:flex;flex-direction:column;gap:2px;max-height:300px;overflow-y:auto}
.team-row{display:flex;align-items:center;gap:12px;padding:9px 8px;border-radius:8px}
.team-row:hover{background:var(--bg-2)}
.team-info .u-name{font-size:13px;font-weight:600;color:var(--text)}
.team-info .u-sub{font-size:11px;color:var(--text-faint)}
