:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e6eb;
  --border-strong: #cdd2da;
  --text: #1c2330;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #2453e6;
  --primary-hover: #1a43c4;
  --primary-soft: #eaf0ff;
  --danger: #c8322a;
  --danger-soft: #fdeceb;
  --ok: #157f4c;
  --ok-soft: #e6f6ee;
  --warn: #9a6200;
  --warn-soft: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.icon { flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); padding: 4px 10px 18px; }
.brand:hover { text-decoration: none; }
.brand .icon { color: var(--primary); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #344054; font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .count { margin-left: auto; background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 10px 0; font-size: 12.5px; }
.sidebar-foot .who { font-weight: 600; }
.usage { margin: 6px 0 10px; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font: inherit; display: inline-flex; gap: 6px; align-items: center; }
.link-btn:hover { color: var(--text); }

.main { min-width: 0; padding: 0 32px 48px; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.search { flex: 1; max-width: 520px; position: relative; }
.search .icon { position: absolute; left: 11px; top: 9px; color: var(--faint); }
.search input { width: 100%; padding: 8px 12px 8px 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); }

.page-head { display: flex; align-items: flex-end; gap: 16px; margin: 10px 0 18px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.subtitle { color: var(--muted); margin-top: 4px; }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs .sep { color: var(--faint); }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 13.5px var(--font); cursor: pointer; white-space: nowrap; box-shadow: var(--shadow); }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; box-shadow: none; background: transparent; }
.btn-ghost:hover { background: rgba(16, 24, 40, .05); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.inline { display: inline; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-weight: 550; margin-bottom: 5px; }
.field .hint { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 14px var(--font);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(36, 83, 230, .25); border-color: var(--primary); }
textarea { resize: vertical; min-height: 90px; }
.check { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 12px; cursor: pointer; }
.check input { margin-top: 3px; }
.check small { display: block; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.copy-field { display: flex; gap: 6px; }
.copy-field input { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { flex: 1; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 2px; }

.flash { padding: 10px 14px; border-radius: 8px; margin: 4px 0 14px; border: 1px solid; }
.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: #b7e4cb; }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: #f5c2bf; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); border: 1px solid #f3dca6; margin-bottom: 14px; }
.error-text { color: var(--danger); margin-bottom: 12px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef0f3; color: #475467; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-blue { background: var(--primary-soft); color: var(--primary); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 550; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfc; }
.table .name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.table .name a { color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.table .num { color: var(--faint); font-family: var(--mono); font-size: 12px; min-width: 34px; }
.table-wrap { overflow-x: auto; }
.ic-folder { color: #4f7cff; fill: #dbe5ff; }
.ic-pdf { color: #d92d20; }
.ic-image { color: #7a5af8; }
.ic-text { color: #667085; }
.ic-office { color: #2e6ae6; }
.ic-sheet { color: #12924f; }
.ic-other { color: #98a2b3; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .icon { color: var(--faint); margin-bottom: 8px; }
.empty h3 { color: var(--text); margin-bottom: 4px; }

/* ---------- Menus & dialogs ---------- */
details.menu { position: relative; display: inline-block; }
details.menu > summary { list-style: none; cursor: pointer; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu .menu-items { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 180px; padding: 4px; z-index: 20; }
.menu-items a, .menu-items button { display: flex; width: 100%; gap: 9px; align-items: center; padding: 7px 10px; border: 0; background: none; border-radius: 6px; color: var(--text); font: 13.5px var(--font); cursor: pointer; text-align: left; }
.menu-items a:hover, .menu-items button:hover { background: var(--surface-2); text-decoration: none; }
.menu-items .danger { color: var(--danger); }
.menu-items form { margin: 0; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); color: var(--text); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog .dlg-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
dialog .dlg-head h2 { flex: 1; }
dialog .dlg-body { padding: 18px 20px 6px; }
dialog .dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }

/* ---------- Upload ---------- */
.drop-overlay { position: fixed; inset: 0; background: rgba(36, 83, 230, .10); border: 3px dashed var(--primary); z-index: 50; display: none; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; color: var(--primary); pointer-events: none; }
body.dragging .drop-overlay { display: flex; }
.uploads { position: fixed; right: 20px; bottom: 20px; width: 340px; z-index: 40; }
.upload-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 12px 14px; margin-top: 8px; }
.progress { height: 6px; background: #edf0f4; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; width: 0; background: var(--primary); transition: width .15s; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: 12px; padding: 30px 20px; text-align: center; color: var(--muted); background: var(--surface-2); cursor: pointer; transition: all .15s; }
.dropzone.over, .dropzone:hover { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dropzone strong { color: var(--text); }
.picked { list-style: none; padding: 0; margin: 10px 0 0; text-align: left; }
.picked li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; margin-top: 6px; font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 20px; overflow-x: auto; }
.tabs a { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 6px; }

/* ---------- Permissions matrix ---------- */
.perm-table td.folder-cell { white-space: nowrap; }
.perm-table select { width: auto; min-width: 150px; padding: 5px 8px; font-size: 13px; }
.perm-table select.explicit { border-color: var(--primary); background: var(--primary-soft); }
.perm-table .eff { display: block; font-size: 11.5px; color: var(--faint); margin-top: 2px; }

/* ---------- Bars ---------- */
.bar { height: 8px; background: #edf0f4; border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > div { height: 100%; background: var(--primary); border-radius: 99px; }

/* ---------- Activity ---------- */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 12px; padding: 11px 20px; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .dot { width: 30px; height: 30px; flex: none; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.feed .dot.guest { background: #f1ecff; color: #6941c6; }
.feed .when { margin-left: auto; color: var(--faint); font-size: 12px; white-space: nowrap; }

/* ---------- Auth & public ---------- */
.public { min-height: 100vh; display: flex; flex-direction: column; }
.public-top { display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--border); }
.public-top .brand { padding: 0; font-size: 16px; }
.public-main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 24px 60px; }
.narrow { max-width: 560px; margin: 0 auto; }
.auth-card { max-width: 400px; margin: 9vh auto 0; }
.auth-card .brand { justify-content: center; font-size: 22px; padding-bottom: 20px; }
.auth-card .card { padding: 26px 28px; }
.auth-card .btn-primary { width: 100%; justify-content: center; padding: 10px; }
.foot-note { text-align: center; color: var(--muted); margin-top: 16px; }
.nda-text { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; max-height: 46vh; overflow: auto; font-size: 13.5px; line-height: 1.6; margin-bottom: 16px; }
.room-banner { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.room-logo { height: 44px; max-width: 160px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--border); padding: 4px; }
.room-logo-sm { height: 22px; max-width: 60px; object-fit: contain; }
.contact-card { display: flex; gap: 14px; align-items: center; }
.contact-card .avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.instructions-body { line-height: 1.6; }
.instructions-body h3 { margin: 12px 0 4px; }
.instructions-body ul { margin: 4px 0 8px; padding-left: 20px; }
.instructions-body p { margin: 0 0 8px; }
.instructions-card summary { list-style: none; }
.instructions-card summary::-webkit-details-marker { display: none; }
.room-banner .mark { width: 44px; height: 44px; border-radius: 12px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; }

/* ---------- Viewer ---------- */
.viewer { background: #e9ebef; border-radius: var(--radius); border: 1px solid var(--border); }
.viewer-bar { position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.viewer-bar .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pages { padding: 24px 16px; display: flex; flex-direction: column; align-items: center; gap: 18px; user-select: none; -webkit-user-select: none; }
.pages img { width: 100%; max-width: var(--page-width, 900px); background: #fff; box-shadow: 0 2px 10px rgba(16, 24, 40, .18); display: block; min-height: 200px; -webkit-user-drag: none; }
.no-preview { padding: 60px 20px; text-align: center; color: var(--muted); }
.preview-frame { width: 100%; height: 78vh; border: 0; background: #fff; border-radius: 0 0 var(--radius) var(--radius); }
.preview-img { max-width: 100%; display: block; margin: 0 auto; }
.preview-text { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; padding: 18px; max-height: 70vh; overflow: auto; margin: 0; background: #fff; }
.qa-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.qa-item .answer { margin-top: 10px; padding: 10px 12px; border-left: 3px solid var(--ok); background: var(--ok-soft); border-radius: 0 8px 8px 0; white-space: pre-wrap; }
.qa-item .q { white-space: pre-wrap; }

@media print { body * { visibility: hidden !important; } body::after { content: "Printing is disabled for this document."; visibility: visible; } }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .sidebar .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar-foot { display: none; }
  .brand { padding: 4px 10px; }
  .main { padding: 0 14px 40px; }
  .cols, .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
