/* ============================================================================
   DevPlan — design tokens and base styles
   RULE: no literal colour may appear outside the :root / [data-theme] blocks
   below. Everything else references a var(). This is what makes dark mode work.
   Mobile first: the 390px one-handed case is the design target, not an
   afterthought. Tap targets >= 46px. Text inputs >= 16px or iOS zooms on focus.
   ========================================================================= */

:root {
  /* --- neutrals (light) --- */
  --bg:            #f6f7f9;
  --surface:       #ffffff;
  --surface-2:     #f0f2f5;
  --surface-sunk:  #e9ecf1;
  --border:        #dde1e8;
  --border-strong: #c3cad6;

  /* --- text --- */
  --text:          #16191f;
  --text-muted:    #5b6472;
  --text-faint:    #8590a0;
  --text-on-accent:#ffffff;

  /* --- brand / accent --- */
  --accent:        #2f5fd9;
  --accent-hover:  #2650bd;
  --accent-sunk:   #1d3f9c;
  --accent-wash:   #e8eefc;

  /* --- semantic --- */
  --ok:            #1c7c4f;
  --ok-wash:       #e3f5ec;
  --warn:          #a8620a;
  --warn-wash:     #fcf1e0;
  --danger:        #b3261e;
  --danger-wash:   #fceceb;
  --preview:       #c2410c;
  --preview-wash:  #fff1e8;

  /* --- avatar tints ---
     Deliberately NOT the semantic colours: a person is not a warning. Picked
     by hashing the user id, so one person keeps one tint forever. */
  --avatar-1-bg:   #dbe6fb;
  --avatar-1-fg:   #1d4ed8;
  --avatar-2-bg:   #d3eeea;
  --avatar-2-fg:   #0f6259;
  --avatar-3-bg:   #e5ddfa;
  --avatar-3-fg:   #5b34c4;
  --avatar-4-bg:   #f6e6cd;
  --avatar-4-fg:   #8a5206;
  --avatar-5-bg:   #fadfe6;
  --avatar-5-fg:   #a72b52;
  --avatar-6-bg:   #dcefd4;
  --avatar-6-fg:   #3a6b1e;

  /* --- overlay behind the mobile account sheet --- */
  --scrim:         rgba(16, 24, 40, .38);

  /* --- shape & motion --- */
  --radius:        10px;
  --radius-sm:     7px;
  --radius-lg:     16px;
  --tap:           46px;          /* minimum interactive height */
  --shadow-1:      0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-2:      0 4px 12px rgba(16, 24, 40, .10);
  --ring:          0 0 0 3px var(--accent-wash);
  --speed:         140ms;

  /* --- type --- */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* --- layout --- */
  --page-max:      880px;
  --gutter:        16px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #101317;
    --surface:       #181c22;
    --surface-2:     #20252d;
    --surface-sunk:  #0c0f13;
    --border:        #2c333d;
    --border-strong: #414a57;

    --text:          #e9edf3;
    --text-muted:    #a2acbb;
    --text-faint:    #77828f;
    --text-on-accent:#ffffff;

    --accent:        #6b93f5;
    --accent-hover:  #82a4f7;
    --accent-sunk:   #a8c0fa;
    --accent-wash:   #1b2740;

    --ok:            #4ec78d;
    --ok-wash:       #122a20;
    --warn:          #e0a14a;
    --warn-wash:     #2c2114;
    --danger:        #f27168;
    --danger-wash:   #2e1614;
    --preview:       #fb923c;
    --preview-wash:  #2e1a0e;

    --avatar-1-bg:   #1c2b48;
    --avatar-1-fg:   #9ab6f8;
    --avatar-2-bg:   #123230;
    --avatar-2-fg:   #6fd4c6;
    --avatar-3-bg:   #272044;
    --avatar-3-fg:   #b8a4f5;
    --avatar-4-bg:   #33280f;
    --avatar-4-fg:   #e2b26a;
    --avatar-5-bg:   #3a1c26;
    --avatar-5-fg:   #f0a1b6;
    --avatar-6-bg:   #1e2f18;
    --avatar-6-fg:   #a6d38a;

    --scrim:         rgba(0, 0, 0, .55);

    --shadow-1:      0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px rgba(0, 0, 0, .30);
    --shadow-2:      0 4px 14px rgba(0, 0, 0, .45);
  }
}

/* Explicit override wins over the media query in both directions. */
:root[data-theme="dark"] {
  --bg:            #101317;
  --surface:       #181c22;
  --surface-2:     #20252d;
  --surface-sunk:  #0c0f13;
  --border:        #2c333d;
  --border-strong: #414a57;

  --text:          #e9edf3;
  --text-muted:    #a2acbb;
  --text-faint:    #77828f;
  --text-on-accent:#ffffff;

  --accent:        #6b93f5;
  --accent-hover:  #82a4f7;
  --accent-sunk:   #a8c0fa;
  --accent-wash:   #1b2740;

  --ok:            #4ec78d;
  --ok-wash:       #122a20;
  --warn:          #e0a14a;
  --warn-wash:     #2c2114;
  --danger:        #f27168;
  --danger-wash:   #2e1614;
  --preview:       #fb923c;
  --preview-wash:  #2e1a0e;

  --avatar-1-bg:   #1c2b48;
  --avatar-1-fg:   #9ab6f8;
  --avatar-2-bg:   #123230;
  --avatar-2-fg:   #6fd4c6;
  --avatar-3-bg:   #272044;
  --avatar-3-fg:   #b8a4f5;
  --avatar-4-bg:   #33280f;
  --avatar-4-fg:   #e2b26a;
  --avatar-5-bg:   #3a1c26;
  --avatar-5-fg:   #f0a1b6;
  --avatar-6-bg:   #1e2f18;
  --avatar-6-fg:   #a6d38a;

  --scrim:         rgba(0, 0, 0, .55);

  --shadow-1:      0 1px 2px rgba(0, 0, 0, .40), 0 1px 3px rgba(0, 0, 0, .30);
  --shadow-2:      0 4px 14px rgba(0, 0, 0, .45);

  color-scheme: dark;
}

/* Native widgets (scrollbars, date pickers) must follow the override too. */
:root[data-theme="light"] { color-scheme: light; }

/* ---------------------------------------------------------------- reset -- */

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

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* keeps content clear of the iOS home indicator */
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; font-weight: 650; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 .8em; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* -------------------------------------------------------------- layout -- */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--gutter);
}

.chrome {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chrome__brand {
  display: inline-flex;
  align-items: center;
  flex: none;
  line-height: 0;
}

/* Height is fixed and width follows the intrinsic ratio: the mark is never
   squashed, whatever the wordmark ends up measuring. */
.chrome__logo {
  display: block;
  height: 26px;
  width: auto;
}

/* Whatever the context says, it yields space rather than pushing the avatar
   off the edge at 390px. */
.chrome__context {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chrome__spacer { margin-left: auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 16px;
  margin-bottom: 14px;
}

.stack > * + * { margin-top: 12px; }

/* ------------------------------------------------------------ controls -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  color: var(--text-on-accent);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--speed) ease, transform var(--speed) ease;
}
.btn:hover:not(:disabled)  { background: var(--accent-hover); }
.btn:active:not(:disabled) { background: var(--accent-sunk); transform: translateY(1px); }
.btn:disabled              { opacity: .5; cursor: not-allowed; }
.btn--block                { width: 100%; }
.btn--quiet {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}
.btn--quiet:hover:not(:disabled)  { background: var(--surface-sunk); }
.btn--quiet:active:not(:disabled) { background: var(--surface-sunk); }

.field { display: block; margin-bottom: 14px; }
.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: .92rem;
  font-weight: 600;
  color: var(--text);
}
.field__hint { margin: 4px 0 0; font-size: .85rem; color: var(--text-muted); }

.input, .textarea, .select {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 16px;              /* < 16px makes iOS zoom on focus. Do not lower. */
  line-height: 1.45;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color var(--speed) ease, box-shadow var(--speed) ease;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.textarea { min-height: 120px; resize: vertical; }

/* ---------------------------------------------------------- feedback --- */

.banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: .92rem;
}
.banner--error   { color: var(--danger); background: var(--danger-wash); border-color: var(--danger); }
.banner--ok      { color: var(--ok);     background: var(--ok-wash);     border-color: var(--ok); }
.banner--warn    { color: var(--warn);   background: var(--warn-wash);   border-color: var(--warn); }

/* Preview mode must be impossible to mistake for the real thing. */
.preview-banner {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 10px var(--gutter);
  font-weight: 700;
  text-align: center;
  color: var(--text-on-accent);
  background: var(--preview);
}

.muted { color: var(--text-muted); }
.small { font-size: .87rem; }

[hidden] { display: none !important; }

/* ---------------------------------------------------------- utilities -- */

.center-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: var(--gutter);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* ============================================================================
   Sign-in — the only public page in the product, so it is the one screen a
   client sees before he trusts us with a passport. Worth getting right.
   Tokens only; light and dark both handled by the variables.
   ========================================================================= */

.auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: calc(var(--gutter) * 1.5) var(--gutter);
  /* A soft wash behind the card so it reads as a surface, not a floating box. */
  background:
    radial-gradient(90% 60% at 50% -10%, var(--accent-wash) 0%, transparent 70%),
    var(--bg);
}

.auth__card {
  width: 100%;
  max-width: 400px;
  padding: 30px 26px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
}


.auth__title {
  margin: 0 0 4px;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -.02em;
}

.auth__sub {
  margin: 0 0 24px;
  color: var(--text-muted);
  font-size: .95rem;
}

/* The gap that was missing: an error must never sit flush against the button
   the client is about to press again. */
.auth__error {
  display: flex;
  gap: 8px;
  margin: 4px 0 18px;
  line-height: 1.45;
}

.auth__error::before {
  content: '!';
  flex: 0 0 20px;
  height: 20px;
  margin-top: 1px;
  font-size: .8rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  color: var(--text-on-accent);
  background: var(--danger);
  border-radius: 50%;
}

.auth__submit {
  margin-top: 4px;
  font-size: 1rem;
  box-shadow: var(--shadow-1);
}

.auth__hint {
  margin: 18px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: .85rem;
  line-height: 1.5;
}

/* Give the fields a little more air than the dense in-app forms. */
.auth__card .field { margin-bottom: 18px; }

/* ============================================================================
   Account — avatar trigger and the menu it opens.
   Wide screens: a panel anchored under the avatar, right-aligned.
   Narrow screens (<=480px): a full-width sheet on the bottom edge, over a
   scrim. Either way it is width-capped to the viewport and never overflows.
   Tokens only.
   ========================================================================= */

.acct {
  position: relative;   /* no z-index: the panel and the scrim must stack
                           against each other inside .chrome, not inside .acct */
  flex: none;
}

.acct__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap);        /* 34px of avatar, the rest is tap target */
  min-height: var(--tap);
  padding: 0;
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.acct__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 34px;
  height: 34px;
  font-size: .82rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: var(--avatar-1-fg);
  background: var(--avatar-1-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  user-select: none;
  transition: box-shadow var(--speed) ease;
}
.acct__trigger:hover .acct__avatar,
.acct__trigger[aria-expanded="true"] .acct__avatar { box-shadow: var(--ring); }

.acct__avatar--lg { width: 40px; height: 40px; font-size: .95rem; }

/* Stable per user: app.js hashes the user id to one of these. */
.acct__avatar[data-tint="1"] { color: var(--avatar-1-fg); background: var(--avatar-1-bg); }
.acct__avatar[data-tint="2"] { color: var(--avatar-2-fg); background: var(--avatar-2-bg); }
.acct__avatar[data-tint="3"] { color: var(--avatar-3-fg); background: var(--avatar-3-bg); }
.acct__avatar[data-tint="4"] { color: var(--avatar-4-fg); background: var(--avatar-4-bg); }
.acct__avatar[data-tint="5"] { color: var(--avatar-5-fg); background: var(--avatar-5-bg); }
.acct__avatar[data-tint="6"] { color: var(--avatar-6-fg); background: var(--avatar-6-bg); }

/* ------------------------------------------------------------------ panel -- */

.acct-scrim {
  position: fixed;
  inset: 0;
  z-index: 39;
  display: none;                 /* sheet-only; the wide panel needs no scrim */
  background: var(--scrim);
}

.acct-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 40;
  width: min(320px, calc(100vw - var(--gutter) * 2));
  max-height: min(76vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  /* One inset for the whole panel. Rows and dividers are laid out against it,
     which is the only way the left edges actually line up. */
  --acct-pad: 8px;
  --acct-inset: 12px;
  padding: var(--acct-pad);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  animation: acct-pop var(--speed) ease-out;
}
.acct-panel:focus { outline: none; }

@keyframes acct-pop {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

/* Bleeds to the panel edge, so it reads as a section header rather than a row
   with a stray line under it. The separator below it does the same. */
.acct-panel__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px var(--acct-inset);
  margin: calc(var(--acct-pad) * -1) calc(var(--acct-pad) * -1) 6px;
  border-bottom: 1px solid var(--border);
}
.acct-panel__id { flex: 1 1 auto; min-width: 0; }

.acct-panel__name {
  margin: 0;
  font-weight: 650;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.acct-panel__email {
  margin: 2px 0 0;
  font-size: .85rem;
  line-height: 1.35;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.acct-role {
  display: inline-flex;
  align-items: center;
  margin-top: 9px;
  padding: 1px 9px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-wash);
  border: 1px solid var(--accent);
  border-radius: 999px;
}

.acct-panel__label {
  margin: 0;
  padding: 10px var(--acct-inset) 8px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* --------------------------------------------------------------- theme --- */
/* Same segmented idiom as the project switcher, so it reads as one product. */

.acct-theme {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 0 0 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.acct-theme__btn {
  flex: 1 1 0;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 6px;
  font: inherit;
  font-size: .87rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--speed) ease, color var(--speed) ease,
              border-color var(--speed) ease;
}
.acct-theme__btn:hover { color: var(--text); }
.acct-theme__btn[aria-checked="true"] {
  color: var(--accent);
  background: var(--accent-wash);
  border-color: var(--accent);
}
.acct-theme__btn[aria-checked="true"]:hover { color: var(--accent); }

/* --------------------------------------------------------------- items --- */

.acct-sep {
  height: 1px;
  margin: 10px calc(var(--acct-pad) * -1);
  background: var(--border);
}

.acct-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 0 var(--acct-inset);
  font: inherit;
  font-weight: 600;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--speed) ease;
}
.acct-item:hover { background: var(--surface-2); }
.acct-item:active { background: var(--surface-sunk); }

/* -------------------------------------------------------- narrow screens -- */

@media (max-width: 480px) {
  .acct-scrim { display: block; }

  .acct-panel {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 82vh;
    /* A sheet has a screen edge under it, not a shadow. The last row needs
       real space below it or it reads as clipped — and on a gesture-bar phone
       the home indicator lands right on top of "Sign out". */
    --acct-pad: 10px;
    --acct-inset: 14px;
    padding: var(--acct-pad) var(--acct-pad)
             calc(18px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation-name: acct-sheet;
  }

  /* Roomier on touch: this is the whole visible surface, not a dropdown. */
  .acct-panel__head { padding: 18px var(--acct-inset); }
  .acct-panel__label { padding: 14px var(--acct-inset) 9px; }
  .acct-sep { margin: 12px calc(var(--acct-pad) * -1); }
  .acct-item { min-height: 52px; }

  @keyframes acct-sheet {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
  }
}

/* ============================================================================
   Section tabs — Questionnaire / Documents, inside one engagement.

   Deliberately a different shape from .tn-switch above it. That control is a
   filled pill group and picks the PROJECT; this one is an underline and picks a
   section within the project. Two identical pill groups stacked would read as
   one four-way choice, which is not what either of them means.
   ========================================================================= */

.vtabs {
  display: flex;
  gap: 4px;
  margin: 0 0 18px;
  border-bottom: 1px solid var(--border);
}

.vtab {
  position: relative;
  flex: 0 1 auto;
  min-height: var(--tap);
  padding: 0 14px;
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: 0;
  /* The indicator is a transparent border that gains colour when selected, so
     the label never shifts by a pixel between states. */
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color var(--speed) ease, border-color var(--speed) ease;
}
.vtab:hover { color: var(--text); }
.vtab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* The tablist is one stop in the tab order and arrows move within it, so the
   focus ring has to be visible on the unselected tab too. */
.vtab:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

/* ============================================================================
   Brand lockup — the DP mark as artwork, the wordmark as live text.
   Text rather than a baked image so it stays sharp at any size, follows the
   theme, and never depends on a font the machine may not have.
   ========================================================================= */

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  line-height: 1;
  white-space: nowrap;
}

.brand__mark {
  height: 26px;
  width: auto;
  display: block;
  flex: none;
}

.brand__word {
  font-weight: 700;
  font-size: 1.16rem;
  letter-spacing: -.021em;
  color: var(--text);
}

/* "Plan" carries the accent, as in the brand sheet. */
.brand__word i { font-style: normal; color: var(--accent); }

.brand--lg { gap: 12px; }
.brand--lg .brand__mark { height: 38px; }
.brand--lg .brand__word { font-size: 1.72rem; letter-spacing: -.028em; }
