:root {
  color-scheme: dark;
  --bg: #0a0a0c;
  --surface: #111114;
  --surface2: #17171b;
  --surface3: #1e1e23;
  --text: #f2ede4;
  --muted: #7a756e;
  --muted2: #4a4540;
  --line: rgba(242,237,228,0.07);
  --line2: rgba(242,237,228,0.13);
  --accent: #f2ede4;
  --warm: #d4c9b8;
  --accent-soft: #c8c3ba;
  --success: #6fd49a;
  --warn: #f5c06a;
  --danger: #ff8a8a;
  --info: #7ab8f5;
  --admin-bg: #07070a;
  --admin-surface: #0d0d11;
  --admin-surface2: #12121a;
  --admin-accent: #8b7cf8;
  --radius-xl: 20px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --shadow: 0 24px 60px rgba(0,0,0,0.5);
}

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

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

* { scrollbar-width: thin; scrollbar-color: rgba(242,237,228,0.1) transparent; }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(242,237,228,0.12); border-radius: 4px; }

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ── PORTAL CENTERED LAYOUT (login, invite, prefs) ── */
.portal-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(242,237,228,0.025), transparent 70%), var(--bg);
}

.portal-shell {
  width: min(460px, calc(100% - 32px));
  margin: 64px auto;
  display: grid;
  gap: 20px;
}

/* ── PORTAL FULL-WIDTH LAYOUT (dashboard) ── */
.portal-app {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ────────────────────────────── */
.portal-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.portal-sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}

.portal-brand-mark {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: var(--bg);
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.72rem; letter-spacing: 0.06em;
  flex-shrink: 0;
}

.portal-sidebar-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.18em; color: var(--muted);
}

.portal-sidebar-sublabel {
  font-size: 0.75rem; color: var(--muted2); margin-top: 2px;
}

.portal-sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.portal-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: 10px;
  border: none; cursor: pointer; background: transparent;
  font-size: 0.88rem; font-weight: 400; color: var(--muted);
  text-align: left; transition: all 160ms ease;
  text-decoration: none; width: 100%;
}

.portal-nav-item:hover { background: var(--surface2); color: var(--text); }
.portal-nav-item.active { background: var(--surface2); color: var(--text); font-weight: 600; }

.portal-nav-icon { font-size: 0.85rem; opacity: 0.7; }

.portal-sidebar-footer {
  padding: 16px 10px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portal-user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--line);
}

.portal-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--line2); color: var(--muted);
  display: grid; place-items: center;
  font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}

.portal-user-name { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.portal-user-role { font-size: 0.72rem; color: var(--muted2); }

/* ── MAIN CONTENT ───────────────────────── */
.portal-main {
  flex: 1;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  min-width: 0;
}

.portal-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.portal-greeting {
  font-size: 1.5rem; font-weight: 800; letter-spacing: -0.04em;
}

.portal-top-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* ── CARDS ──────────────────────────────── */
.portal-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 28px;
  display: grid;
  gap: 20px;
}

.portal-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.portal-card-header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.portal-card h2 {
  font-size: 1.1rem; font-weight: 700; letter-spacing: -0.03em;
}

/* ── STAT CARDS ─────────────────────────── */
.portal-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.portal-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.portal-stat-value {
  font-size: 1.8rem; font-weight: 900;
  letter-spacing: -0.05em; line-height: 1;
  margin-bottom: 4px;
}

.portal-stat-label {
  font-size: 0.78rem; color: var(--muted);
}

/* ── UPLOAD LIST ────────────────────────── */
.portal-upload-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
}

.portal-upload-list li {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 0.88rem; flex-wrap: wrap;
}

.portal-upload-list li.unread {
  border-color: rgba(242,237,228,0.2);
}

.portal-upload-filename {
  font-weight: 500; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.portal-upload-meta {
  font-size: 0.78rem; color: var(--muted); white-space: nowrap;
}

.portal-upload-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── STATUS BADGE ───────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em;
  white-space: nowrap;
}
.badge-success { background: rgba(111,212,154,0.12); color: var(--success); }
.badge-warn    { background: rgba(245,192,106,0.12); color: var(--warn); }
.badge-danger  { background: rgba(255,138,138,0.12); color: var(--danger); }
.badge-info    { background: rgba(122,184,245,0.12); color: var(--info); }
.badge-muted   { background: rgba(122,117,110,0.12); color: var(--muted); }
.badge-purple  { background: rgba(139,124,248,0.15); color: var(--admin-accent); }

/* ── PROJECT STEPPER ────────────────────── */
.project-stepper {
  display: flex; align-items: center; gap: 0;
  margin: 4px 0 8px;
}

.step-item {
  display: flex; flex-direction: column; align-items: center; flex: 1;
  position: relative;
}

.step-item:not(:last-child)::after {
  content: ''; position: absolute;
  top: 12px; left: 50%; right: -50%;
  height: 2px;
  background: var(--line2);
  z-index: 0;
}

.step-item.done:not(:last-child)::after { background: var(--success); }

.step-dot {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--line2);
  background: var(--surface2);
  display: grid; place-items: center;
  font-size: 0.65rem; font-weight: 700;
  z-index: 1; position: relative;
  transition: all 200ms;
}

.step-item.done .step-dot {
  background: var(--success); border-color: var(--success); color: var(--bg);
}

.step-item.active .step-dot {
  border-color: var(--warm); color: var(--warm);
}

.step-label {
  font-size: 0.65rem; color: var(--muted); margin-top: 6px;
  text-align: center; line-height: 1.2;
}

.progress-bar {
  height: 4px; background: var(--line2); border-radius: 999px; overflow: hidden;
}

.progress-bar-fill {
  height: 100%; background: var(--success); border-radius: 999px;
  transition: width 600ms ease;
}

/* ── BUTTONS ────────────────────────────── */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 18px; border-radius: 999px;
  border: 1px solid transparent; cursor: pointer; font-weight: 600;
  font-size: 0.88rem; font-family: inherit;
  transition: all 160ms ease; text-decoration: none;
}
.button:hover { transform: translateY(-1px); }
.button[disabled], .button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }

.button-primary { background: var(--accent); color: var(--bg); }
.button-primary:hover { background: #fff; }

.button-secondary { background: var(--surface2); color: var(--text); border-color: var(--line2); }
.button-secondary:hover { border-color: var(--warm); }

.button-admin { background: var(--admin-accent); color: #fff; }
.button-admin:hover { background: #9d8ff9; }

.button-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.button-ghost:hover { color: var(--text); border-color: var(--line2); }

.button-danger { background: rgba(255,138,138,0.12); color: var(--danger); border-color: rgba(255,138,138,0.2); }
.button-danger:hover { background: rgba(255,138,138,0.2); }

.button-sm { min-height: 32px; padding: 0 14px; font-size: 0.78rem; }

/* ── FORMS ──────────────────────────────── */
.portal-form { display: grid; gap: 16px; }

.portal-form label, .portal-field {
  display: grid; gap: 7px;
  font-size: 0.82rem; font-weight: 600; color: var(--warm);
}

.portal-form input,
.portal-form textarea,
.portal-form select {
  width: 100%; padding: 12px 16px;
  background: var(--surface2); border: 1px solid var(--line2);
  border-radius: var(--radius-md); color: var(--text);
  font-size: 0.92rem; outline: none;
  transition: border-color 180ms ease;
}

.portal-form input:focus,
.portal-form textarea:focus { border-color: var(--warm); }

.portal-form input::placeholder,
.portal-form textarea::placeholder { color: var(--muted2); }

.portal-form input[readonly] { opacity: 0.6; cursor: not-allowed; }

/* ── UPLOAD DROPZONE ────────────────────── */
.upload-dropzone {
  border: 1px dashed var(--line2);
  border-radius: var(--radius-lg);
  min-height: 160px;
  display: grid; place-items: center; text-align: center;
  padding: 24px;
  background: linear-gradient(180deg, var(--surface), var(--surface2));
  transition: border-color 180ms, background 180ms;
  cursor: pointer;
}

.upload-dropzone strong { display: block; font-weight: 600; margin-bottom: 4px; }
.upload-dropzone p { color: var(--muted); font-size: 0.85rem; }
.upload-dropzone.is-dragover { border-color: var(--accent); background: linear-gradient(180deg, var(--surface2), var(--surface3)); }

.file-list {
  list-style: none; padding: 0; margin: 10px 0 0; width: 100%;
  display: grid; gap: 5px; text-align: left;
}
.file-list li {
  font-size: 0.82rem; background: rgba(242,237,228,0.04);
  padding: 6px 10px; border-radius: 8px;
  display: flex; justify-content: space-between; gap: 10px;
}
.file-list li span.size { color: var(--muted); flex-shrink: 0; }

.progress {
  margin: 8px 0 0; width: 100%; height: 4px;
  background: var(--surface2); border-radius: 999px; overflow: hidden; display: none;
}
.progress[data-active="true"] { display: block; }
.progress > span { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 200ms ease; }

/* ── PORTAL.JS-GENERATED LIST ITEMS ────── */
.portal-upload-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px;
  background: var(--surface2); border: 1px solid var(--line);
  border-radius: var(--radius-md); font-size: 0.88rem; flex-wrap: wrap;
  list-style: none;
}

.portal-upload-info {
  display: flex; flex-direction: column; gap: 4px;
  flex: 1; min-width: 0;
}

.portal-upload-name {
  display: flex; align-items: center; gap: 8px;
  font-weight: 500; flex-wrap: wrap;
}

.portal-upload-badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.05em;
  background: var(--surface3); color: var(--muted); border: 1px solid var(--line2);
  white-space: nowrap;
}

.portal-status-chip {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
  border: 1px solid currentColor; white-space: nowrap;
}

/* ── FORM STATUS ────────────────────────── */
.form-status {
  min-height: 1.2em; font-size: 0.88rem; color: var(--muted);
}
.form-status.success { color: var(--success); }
.form-status.error { color: var(--danger); }

/* ── PORTAL LEDE / FOOTNOTE ─────────────── */
.portal-lede { color: var(--muted); font-size: 0.92rem; line-height: 1.6; }
.portal-footnote { font-size: 0.82rem; color: var(--muted2); text-align: center; line-height: 1.7; }
.portal-footnote a { color: var(--warm); text-decoration: underline; }

/* Divider */
.pref-divider { border: none; border-top: 1px solid var(--line); margin: 8px 0; }
.pref-section-title { font-size: 1rem; font-weight: 700; letter-spacing: -0.03em; }

/* Upload actions row */
.upload-actions {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px;
}

/* Link button */
.link-button {
  background: none; border: none; color: var(--warm); cursor: pointer;
  font-family: inherit; font-size: inherit; padding: 0; text-decoration: underline;
}

/* ── RESPONSIVE ─────────────────────────── */
@media (max-width: 760px) {
  .portal-app { flex-direction: column; }
  .portal-sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--line); }
  .portal-sidebar-nav { flex-direction: row; flex-wrap: wrap; padding: 10px; gap: 4px; }
  .portal-nav-item { flex: none; padding: 8px 14px; }
  .portal-sidebar-footer { flex-direction: row; align-items: center; padding: 10px; }
  .portal-main { padding: 20px 16px; }
  .portal-stats { grid-template-columns: 1fr 1fr; }
  .portal-shell { margin: 32px auto; }
}

@media (max-width: 480px) {
  .portal-stats { grid-template-columns: 1fr; }
}
