/* ── ClientDoor Design System ─────────────────────────────────────────────
   Hand-crafted. No frameworks. No dependencies.
   Loads in < 5kb gzipped.
   ──────────────────────────────────────────────────────────────────────── */

/* ── Custom properties ──────────────────────────────────────────────────── */
:root {
  /* Palette */
  --purple-50:  #EEEDFE;
  --purple-100: #CECBF6;
  --purple-400: #7F77DD;
  --purple-600: #534AB7;
  --purple-800: #3C3489;
  --purple-900: #26215C;

  --teal-50:  #E1F5EE;
  --teal-400: #1D9E75;
  --teal-600: #0F6E56;
  --teal-800: #085041;

  --amber-50:  #FAEEDA;
  --amber-400: #BA7517;
  --amber-600: #854F0B;

  --coral-50:  #FAECE7;
  --coral-400: #D85A30;
  --coral-600: #993C1D;

  --gray-50:  #F7F7F5;
  --gray-100: #EFEFEB;
  --gray-200: #D3D1C7;
  --gray-400: #888780;
  --gray-600: #5F5E5A;
  --gray-900: #1A1A18;

  /* Semantic tokens — light mode */
  --bg:           #FFFFFF;
  --bg-secondary: #F7F7F5;
  --bg-tertiary:  #EFEFEB;
  --surface:      #FFFFFF;

  --text:         #1A1A18;
  --text-muted:   #5F5E5A;
  --text-faint:   #888780;

  --border:       rgba(26,26,24,0.12);
  --border-strong:rgba(26,26,24,0.22);

  --accent:       var(--amber-400);
  --accent-hover: var(--amber-600);
  --accent-light: var(--amber-50);
  --accent-text:  var(--amber-600);

  --success-bg:   #E1F5EE;
  --success-text: #085041;
  --warning-bg:   #FAEEDA;
  --warning-text: #633806;
  --danger-bg:    #FAECE7;
  --danger-text:  #993C1D;

  /* Layout */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Typography */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Spacing scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px;  --s4: 16px;
  --s5: 20px; --s6: 24px; --s8: 32px;  --s10: 40px;

  /* Transitions */
  --t-fast:   100ms ease;
  --t-normal: 180ms ease;
}

/* ── Dark mode ──────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #131312;
    --bg-secondary: #1C1C1A;
    --bg-tertiary:  #242422;
    --surface:      #1C1C1A;

    --text:         #EEEEE8;
    --text-muted:   #A0A09A;
    --text-faint:   #6B6B65;

    --border:       rgba(238,238,232,0.10);
    --border-strong:rgba(238,238,232,0.20);

    --accent:       var(--amber-400);
    --accent-hover: var(--amber-50);
    --accent-light: var(--amber-50);
    --accent-text:  var(--amber-600)
  }
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 4; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

img, video { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: 1.75rem; font-weight: 600; line-height: 1.2; letter-spacing: -.02em; }
h2 { font-size: 1.375rem; font-weight: 600; line-height: 1.3; letter-spacing: -.015em; }
h3 { font-size: 1.1rem;   font-weight: 500; line-height: 1.4; }
h4 { font-size: 0.9rem;   font-weight: 500; line-height: 1.4; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }

p { max-width: 60ch; }
p + p { margin-top: var(--s3); }

/* ── Layout helpers ─────────────────────────────────────────────────────── */
.container   { max-width: 1080px; margin: 0 auto; padding: 0 var(--s6); }
.container-sm{ max-width: 680px;  margin: 0 auto; padding: 0 var(--s6); }
.stack       { display: flex; flex-direction: column; }
.stack-sm    { gap: var(--s3); }
.stack-md    { gap: var(--s4); }
.stack-lg    { gap: var(--s6); }
.cluster     { display: flex; flex-wrap: wrap; align-items: center; }
.cluster-sm  { gap: var(--s2); }
.cluster-md  { gap: var(--s3); }
.cluster-lg  { gap: var(--s4); }
.split       { display: flex; align-items: center; justify-content: space-between; }
.grid-2      { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--s4); }
.grid-3      { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: var(--s4); }
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--s5) var(--s6);
}
.card-sm { padding: var(--s4); border-radius: var(--radius-md); }
.card + .card { margin-top: var(--s4); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 9px var(--s5);
  font-size: 14px; font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
  user-select: none;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--amber-400); text-decoration: none; }

.btn-secondary {
  background: var(--bg-secondary); color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg-tertiary); text-decoration: none; }

.btn-ghost {
  background: transparent; color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-secondary); color: var(--text); text-decoration: none; }

.btn-success { background: var(--success-bg); color: var(--success-text); border-color: var(--teal-400); }
.btn-success:hover { background: var(--teal-50); text-decoration: none; }

.btn-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--coral-400); }
.btn-danger:hover { background: var(--coral-50); text-decoration: none; }

.btn-sm { padding: 6px var(--s4); font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px var(--s8); font-size: 16px; }
.btn-block { width: 100%; }

/* ── Form elements ──────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--s1); }
.field + .field { margin-top: var(--s4); }

label {
  font-size: 13px; font-weight: 500; color: var(--text-muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 9px var(--s3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 14px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(186,117,23,.15);
}
textarea { resize: vertical; min-height: 80px; }
input::placeholder, textarea::placeholder { color: var(--text-faint); }

.field-hint { font-size: 12px; color: var(--text-faint); }
.field-error { font-size: 12px; color: var(--danger-text); }
input.is-invalid, textarea.is-invalid { border-color: var(--coral-400); }

/* ── Badges / pills ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px var(--s3);
  font-size: 12px; font-weight: 500;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-new      { background: var(--accent-light); color: var(--accent-text); }
.badge-approved { background: var(--success-bg);   color: var(--success-text); }
.badge-changes  { background: var(--warning-bg);   color: var(--warning-text); }
.badge-pending  { background: var(--bg-tertiary);  color: var(--text-muted); }
.badge-draft    { background: var(--bg-tertiary);  color: var(--text-faint); }

/* ── Progress bar ───────────────────────────────────────────────────────── */
.progress { height: 5px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; }
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 3px;
  transition: width 400ms ease;
}

/* ── Milestone stepper ──────────────────────────────────────────────────── */
.milestones {
  display: flex; position: relative; padding: var(--s4) 0;
}
.milestones::before {
  content: '';
  position: absolute; top: calc(var(--s4) + 9px);
  left: calc(var(--s4) + 9px); right: calc(var(--s4) + 9px);
  height: 1px; background: var(--border);
}
.milestone { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--s2); z-index: 1; }
.milestone-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--t-normal), border-color var(--t-normal);
}
.milestone-dot.done { background: var(--accent); border-color: var(--accent); }
.milestone-dot.done::after { content: '✓'; color: #fff; font-size: 11px; }
.milestone-dot.active { border-color: var(--accent); border-width: 2px; }
.milestone-dot.active::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.milestone-label { font-size: 12px; color: var(--text-muted); text-align: center; }
.milestone-label.active { color: var(--text); font-weight: 500; }

/* ── File row ───────────────────────────────────────────────────────────── */
.file-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--t-fast), background var(--t-fast);
  cursor: pointer;
  text-decoration: none; color: inherit;
}
.file-row:hover { border-color: var(--border-strong); background: var(--bg); text-decoration: none; }
.file-row.is-new { border-color: var(--accent); }

.file-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; flex-shrink: 0;
}
.file-icon-pdf { background: var(--coral-50);  color: var(--coral-600); }
.file-icon-fig { background: var(--accent-light); color: var(--accent-text); }
.file-icon-mp4 { background: var(--teal-50);   color: var(--teal-800); }
.file-icon-img { background: var(--amber-50);  color: var(--amber-600); }
.file-icon-doc { background: var(--bg-tertiary); color: var(--text-muted); }

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

/* ── Comments ───────────────────────────────────────────────────────────── */
.comment {
  display: flex; gap: var(--s3);
  padding: var(--s4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.comment + .comment { margin-top: var(--s3); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-light); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.avatar-owner { background: var(--bg-tertiary); color: var(--text-muted); }

.comment-meta { font-size: 12px; color: var(--text-faint); margin-bottom: var(--s1); }
.comment-meta strong { color: var(--text); font-weight: 500; }
.comment-text { font-size: 14px; color: var(--text); line-height: 1.55; }

/* ── Navigation ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--s6); height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar-brand { display: flex; align-items: center; gap: var(--s3); font-weight: 600; font-size: 15px; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  height: 100vh; position: sticky; top: 0;
  overflow-y: auto;
  padding: var(--s5) var(--s4);
}
.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: 8px var(--s3);
  font-size: 14px; color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-item:hover { background: var(--bg-tertiary); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-light); color: var(--accent-text); font-weight: 500; }

/* ── Portal header (branded) ────────────────────────────────────────────── */
.portal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s4) var(--s6);
}
.portal-header.dark { background: var(--gray-900); }
.portal-header.dark .portal-brand-name  { color: #fff; }
.portal-header.dark .portal-header-meta { color: rgba(255,255,255,.45); font-size: 12px; }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
  padding: var(--s3) var(--s4);
  border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.5;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--teal-400); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--amber-400); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--coral-400); }
.alert-info    { background: var(--accent-light); color: var(--accent-text); border-color: var(--purple-400); }

/* ── Table ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { padding: var(--s3) var(--s4); text-align: left; font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); border-bottom: 1px solid var(--border); }
tbody td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-secondary); }

/* ── Utility ────────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.text-muted  { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-accent { color: var(--accent); }
.text-success{ color: var(--success-text); }
.text-danger { color: var(--danger-text); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.fw-500 { font-weight: 500; }
.mt-1 { margin-top: var(--s1); } .mt-2 { margin-top: var(--s2); } .mt-4 { margin-top: var(--s4); } .mt-6 { margin-top: var(--s6); }
.mb-1 { margin-bottom: var(--s1); } .mb-2 { margin-bottom: var(--s2); } .mb-4 { margin-bottom: var(--s4); } .mb-6 { margin-bottom: var(--s6); }
.divider { border: none; border-top: 1px solid var(--border); margin: var(--s5) 0; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
