:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  --bg: #f5f5f7;
  --surface: rgba(255,255,255,.88);
  --surface-solid: #fff;
  --surface-soft: #f2f2f7;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: rgba(60,60,67,.18);
  --accent: #0a84ff;
  --danger: #ff3b30;
  --success: #248a3d;
  --warning: #a04d00;
  --shadow: 0 12px 40px rgba(0,0,0,.08);
  --radius: 20px;
  --sidebar: 248px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --surface: rgba(28,28,30,.9);
    --surface-solid: #1c1c1e;
    --surface-soft: #2c2c2e;
    --text: #f5f5f7;
    --muted: #aeaeb2;
    --border: rgba(84,84,88,.65);
    --danger: #ff453a;
    --success: #30d158;
    --warning: #ff9f0a;
    --shadow: 0 18px 54px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
form { margin: 0; }

.app-shell { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar);
  padding: 28px 18px 22px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 26px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent), #5856d6);
  color: #fff;
  font-weight: 800;
  letter-spacing: -.04em;
  box-shadow: 0 8px 22px rgba(10,132,255,.28);
}

.brand-copy strong { display: block; font-size: 15px; }
.brand-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.nav { display: grid; gap: 6px; }
.nav-link {
  min-height: 46px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 650;
}
.nav-link:hover { background: var(--surface-soft); color: var(--text); }
.nav-link.active { background: rgba(10,132,255,.12); color: var(--accent); }
.nav-icon { width: 24px; text-align: center; font-size: 19px; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 10px 0;
  border-top: 1px solid var(--border);
}
.user-name { font-size: 14px; font-weight: 700; }
.user-email { margin: 3px 0 12px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.main { min-height: 100vh; margin-left: var(--sidebar); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  min-height: 72px;
  padding: 0 clamp(20px,4vw,48px);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: rgba(245,245,247,.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
@media (prefers-color-scheme: dark) { .topbar { background: rgba(0,0,0,.76); } }
.topbar h1 { margin: 0; font-size: clamp(22px,3vw,30px); letter-spacing: -.035em; text-align: center; }
.mobile-logo { display: none; width: 32px; height: 32px; border-radius: 10px; }

.content {
  width: min(1240px,100%);
  margin: 0 auto;
  padding: 26px clamp(20px,4vw,48px) 72px;
}

.toolbar {
  min-height: 46px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-actions, .row-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.muted { margin: 0; color: var(--muted); line-height: 1.5; }

.button {
  min-height: 44px;
  padding: 0 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 13px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}
.button:hover { filter: brightness(.97); }
.button:active { transform: scale(.985); }
.button-primary { background: var(--accent); color: #fff; }
.button-danger { background: rgba(255,59,48,.14); color: var(--danger); }
.button-small { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.button-block { width: 100%; }

.card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.card-header {
  min-height: 62px;
  padding: 17px 22px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.card-body { padding: 22px; }

.stats-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 18px; }
.stat-card {
  min-height: 126px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.stat-card span { color: var(--muted); font-size: 13px; font-weight: 650; }
.stat-card strong { font-size: 34px; line-height: 1; letter-spacing: -.045em; }
.stat-card small { color: var(--muted); }
.section { margin-top: 24px; }
.section-first { margin-top: 0; }
.two-column { display: grid; grid-template-columns: minmax(0,1.35fr) minmax(290px,.65fr); gap: 18px; }
.text-link { color: var(--accent); font-size: 14px; font-weight: 700; }

.list { display: grid; }
.list-row {
  min-height: 74px;
  padding: 15px 22px;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 14px;
  align-items: center;
  border-top: 1px solid var(--border);
}
.list-row:first-child { border-top: 0; }
a.list-row:hover { background: rgba(127,127,127,.06); }
.list-primary { font-weight: 700; line-height: 1.35; }
.list-secondary { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.status {
  min-height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}
.status-quote { background: rgba(175,82,222,.14); color: #8944ab; }
.status-planned { background: rgba(10,132,255,.14); color: var(--accent); }
.status-ongoing { background: rgba(255,159,10,.16); color: var(--warning); }
.status-completed { background: rgba(52,199,89,.15); color: var(--success); }
.status-invoiced { background: rgba(88,86,214,.15); color: #5856d6; }

.filters { min-width: min(100%,610px); flex: 1; display: flex; gap: 10px; }
.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: var(--surface-solid);
  color: var(--text);
}
.filters .input { flex: 1; }
.filters .select { width: 180px; }
.textarea { min-height: 118px; resize: vertical; line-height: 1.55; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10,132,255,.16);
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .75; }

.form-card { max-width: 820px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; }
.field { display: grid; gap: 7px; }
.field-full { grid-column: 1/-1; }
.field label, .label { font-size: 13px; font-weight: 700; }
.help { color: var(--muted); font-size: 12px; line-height: 1.45; }
.error-text { color: var(--danger); font-size: 12px; font-weight: 650; }
.has-error .input, .has-error .select, .has-error .textarea { border-color: var(--danger); }
.form-actions {
  margin-top: 24px;
  padding-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.segmented {
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 4px;
  background: var(--surface-soft);
  border-radius: 12px;
}
.segmented label {
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) {
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.project-header {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.project-header h2 { margin: 5px 0 8px; font-size: clamp(26px,4vw,38px); letter-spacing: -.045em; }

.meta-grid {
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.meta-grid > div { min-height: 92px; padding: 18px; background: var(--surface); }
.meta-grid span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.meta-grid strong { display: block; line-height: 1.45; }
.description { white-space: pre-wrap; line-height: 1.65; }
.contact-link { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(10,132,255,.35); text-underline-offset: 3px; }

.journal-form { display: grid; grid-template-columns: 150px minmax(0,1fr) auto; gap: 10px; align-items: start; }
.journal-list { border-top: 1px solid var(--border); }
.journal-entry { padding: 18px 22px; border-top: 1px solid var(--border); }
.journal-entry:first-child { border-top: 0; }
.journal-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.journal-top small { display: block; margin-top: 3px; color: var(--muted); }
.journal-entry p { margin: 11px 0 0; white-space: pre-wrap; line-height: 1.6; }
.danger-zone { margin-top: 24px; }
.account-card { display: grid; gap: 0; }
.account-row {
  min-height: 54px;
  padding: 12px 0;
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 14px;
  align-items: center;
  border-top: 1px solid var(--border);
}
.account-row:first-child { border-top: 0; padding-top: 0; }
.account-row span { color: var(--muted); font-size: 13px; }
.account-row strong { text-align: right; overflow-wrap: anywhere; }
.account-logout { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.prose { line-height: 1.6; }
.prose p { margin: 0 0 14px; }
.prose p:last-child { margin-bottom: 0; }

.activity-row {
  padding: 14px 22px;
  display: grid;
  grid-template-columns: 9px minmax(0,1fr);
  gap: 12px;
  border-top: 1px solid var(--border);
  line-height: 1.45;
}
.activity-row:first-child { border-top: 0; }
.activity-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--accent); }
.activity-row small { display: block; margin-top: 3px; color: var(--muted); }

.empty { padding: 46px 22px; text-align: center; }
.empty h3 { margin: 0 0 8px; font-size: 20px; }
.empty p { max-width: 460px; margin: 0 auto 18px; color: var(--muted); line-height: 1.55; }

.flash {
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: 13px;
  font-size: 14px;
  font-weight: 650;
  transition: opacity .25s, transform .25s;
}
.flash-success { background: rgba(52,199,89,.15); color: var(--success); }
.flash-error { background: rgba(255,59,48,.14); color: var(--danger); }
.flash-hide { opacity: 0; transform: translateY(-5px); }

.auth-page {
  min-height: 100vh;
  padding: max(24px,env(safe-area-inset-top)) 20px max(24px,env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 20% 0%,rgba(10,132,255,.16),transparent 38%),var(--bg);
}
.auth-wrap { width: min(100%,470px); }
.auth-brand { margin-bottom: 22px; display: grid; justify-items: center; gap: 12px; text-align: center; }
.auth-brand .brand-mark { width: 58px; height: 58px; border-radius: 18px; font-size: 22px; }
.auth-brand h1 { margin: 0; font-size: 26px; letter-spacing: -.035em; }
.auth-brand p { margin: 5px 0 0; color: var(--muted); }
.auth-card { padding: 24px; }
.auth-card .field + .field { margin-top: 16px; }
.auth-footnote { margin-top: 16px; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }

.mobile-nav { display: none; }

@media (max-width:1050px) {
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .two-column { grid-template-columns: 1fr; }
}

@media (max-width:820px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .topbar {
    min-height: calc(62px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 16px 0;
  }
  .topbar h1 { font-size: 21px; }
  .mobile-logo { display: grid; }
  .content { padding: 18px 16px calc(92px + env(safe-area-inset-bottom)); }
  .mobile-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(4,1fr);
    background: var(--surface);
    border-top: 1px solid var(--border);
    backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px);
  }
  .mobile-nav a {
    min-height: 48px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    border-radius: 12px;
    color: var(--muted);
    font-weight: 650;
  }
  .mobile-nav a span { font-size: 18px; line-height: 1; }
  .mobile-nav a small { font-size: 11px; }
  .mobile-nav a.active { background: rgba(10,132,255,.10); color: var(--accent); }
  .meta-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .journal-form { grid-template-columns: 1fr; }
  .project-header { flex-direction: column; }
}

@media (max-width:600px) {
  .stats-grid { gap: 12px; }
  .stat-card { min-height: 110px; padding: 16px; }
  .stat-card strong { font-size: 30px; }
  .filters { width: 100%; min-width: 0; flex-direction: column; }
  .filters .select { width: 100%; }
  .toolbar > .button { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .field-full { grid-column: auto; }
  .card-body { padding: 18px; }
  .card-header { padding: 16px 18px 10px; }
  .list-row { padding: 15px 18px; }
  .form-actions {
    position: sticky;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 8;
    margin-inline: -18px;
    padding: 14px 18px;
    background: var(--surface);
  }
  .form-actions .button-primary { flex: 1; }
  .meta-grid { grid-template-columns: 1fr; }
  .project-header .page-actions { width: 100%; }
  .project-header .page-actions .button { flex: 1; }
  .journal-top { align-items: flex-start; }
}

@media print {
  .sidebar,.topbar,.mobile-nav,.toolbar,.page-actions,.form-actions,.journal-form,.danger-zone,.button { display:none!important; }
  .main { margin:0; }
  .content { padding:0; }
  .card { box-shadow:none; }
}

.debug-details {
  max-height: 320px;
  margin: 18px 0 0;
  padding: 14px;
  overflow: auto;
  border-radius: 12px;
  background: var(--surface-soft);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}
