/* ==========================================================================
   type.css — v0.8.0. Third layer, loaded after styles.css and theme.css.

   What this layer is for
   ----------------------
   The two earlier layers were tuned as a dense instrument panel: 13–14px body,
   10.5px micro-labels, 12–13px controls. That reads well on a 27" monitor at arm's
   length and poorly everywhere else — on a laptop, a projector, or a browser at
   90% zoom. This layer moves the whole product onto one larger, calmer scale
   closer to a public-facing site: 16px body, ~15px controls, 28px page titles,
   more line-height, and touch-sized targets.

   It also owns *responsive layout*, because both earlier layers carry
   @media rules written at different times that now contradict each other — a
   later-loaded file at 206px sidebar width will beat an earlier media query no
   matter what the query says. Re-asserting the layout here, in source order last,
   is the only way to make behaviour predictable.

   Rollback: remove the <link> for this file from base.html. Nothing else depends
   on it; no template, script or route knows it exists.
   ========================================================================== */

:root{
  /* One type scale, so a future change is one number, not 300. */
  --fs-micro:11px;    /* mono caps labels */
  --fs-small:13px;    /* helper text, hints */
  --fs-body:16px;     /* body copy */
  --fs-ui:15px;       /* nav, buttons, inputs, table cells */
  --fs-lead:17px;     /* page subtitles, intro copy */
  --fs-h3:19px;
  --fs-h2:22px;
  --fs-h1:28px;       /* page title */

  --lh-tight:1.25;
  --lh-body:1.55;

  /* Controls get a real height: a 38px button is easier to hit than a 30px one. */
  --control-h:38px;
  --control-pad-y:9px;
  --control-pad-x:14px;

  --font-ui:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI","PingFang SC",
             "Microsoft YaHei UI","Microsoft YaHei","Noto Sans SC",system-ui,sans-serif;
}

/* ------------------------------------------------------------------- base */

html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
html,body{
  font-family:var(--font-ui);
  font-size:var(--fs-body);
  line-height:var(--lh-body);
}
/* Supported floor. Below 320px CSS width the layout keeps 320 and the window
   scrolls, instead of collapsing into unreadable slivers. This is the *layout*
   floor — it is not page-zoom locking: a reader may still zoom the browser to
   200% (WCAG 1.4.4) and the layout will reflow at the resulting width. */
body{min-width:320px}
p,li,dd,dt,td,th,label,span,div{letter-spacing:0}

/* The mono caps label survives, it is just readable now. */
.eyebrow,
.section-title,
.kv .k,
.rail-field span,
.rail-spec dt,
.rail-record-title,
.sidebar-footer .hall,
.field-block-title,
.growth-panel-title,
.evidence-list-label,
.tl-label,
.stat .label,
.data-table th{
  font-size:var(--fs-micro);
  letter-spacing:.07em;
}

/* -------------------------------------------------------------------- rail */

.app-shell{grid-template-columns:228px minmax(0,1fr)}
.sidebar{width:228px}
.brand{height:60px;padding:0 16px;gap:10px}
.brand img{width:28px;height:28px}
.brand-cn{font-size:var(--fs-ui);font-weight:600}
.brand-en{font-size:8.5px;letter-spacing:.13em}

.nav{padding:10px 8px}
.nav a{
  padding:9px 10px;
  border-radius:7px;
  font-size:var(--fs-ui);
  gap:10px;
  line-height:1.35;
}
.nav a svg{width:16px;height:16px}
.nav .badge{font-size:var(--fs-micro);min-width:20px;height:20px;border-radius:5px}

.rail-search input{font-size:var(--fs-ui)}
.rail-record-title{font-size:var(--fs-micro)}
.rail-field b{font-size:var(--fs-small)}
.rail-spec dd{font-size:var(--fs-small)}
.rail-note{font-size:var(--fs-small)}
.sidebar-footer .cn{font-size:var(--fs-small)}
.sidebar-footer .en{font-size:10px}
.user-menu-copy .name{font-size:var(--fs-small);font-weight:600}
.user-menu-copy .position{font-size:var(--fs-micro)}
.user-dropdown a,.user-dropdown button,.user-dropdown-item{font-size:var(--fs-ui)}
.avatar{width:30px;height:30px;font-size:var(--fs-micro);border-radius:7px}
.notes-trigger{width:34px;height:34px}
.global-search{height:34px}
.notes-item-body{font-size:var(--fs-small)}
.notes-when{font-size:var(--fs-micro)}

/* ------------------------------------------------------------- page + card */

.content{padding:28px 32px 48px;max-width:1680px}
.page-head{margin-bottom:22px;gap:18px}
.page-title{font-size:var(--fs-h1);line-height:var(--lh-tight);letter-spacing:-.018em;font-weight:650}
.page-sub{font-size:var(--fs-lead);color:var(--muted);margin-top:6px}
.section-title{margin:0 0 12px;gap:9px}
.section-title::before{width:3px;height:11px}
.section-sub{font-size:var(--fs-small);line-height:var(--lh-body)}
.card{padding:20px 22px}

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

.btn{
  min-height:var(--control-h);
  padding:var(--control-pad-y) var(--control-pad-x);
  font-size:var(--fs-ui);
  border-radius:7px;
  gap:7px;
}
.btn-small{min-height:30px;padding:5px 10px;font-size:var(--fs-small)}
.btn svg,.btn i{width:16px;height:16px}
/* A disabled primary action is a neutral control, not a faded red one: at 45%
   opacity the cardinal red turns pink and reads as an error state. */
.btn-primary:disabled{background:#e4e0db;color:#8d857e;opacity:1;cursor:not-allowed}
.btn-secondary:disabled,.btn:disabled{opacity:.55}

.input,.select,.textarea{
  min-height:var(--control-h);
  padding:var(--control-pad-y) 12px;
  font-size:var(--fs-ui);
  border-radius:7px;
  line-height:1.4;
}
.textarea{min-height:84px;line-height:var(--lh-body)}
.field label{font-size:var(--fs-small);font-weight:550}
.helper{font-size:var(--fs-small);line-height:1.5}
.field-unit{font-size:var(--fs-micro)}
.auto-tag{font-size:9.5px}
.tl-value{font-size:var(--fs-h3)}

.choice h4{font-size:var(--fs-ui)}
.choice p{font-size:var(--fs-small)}

/* ----------------------------------------------------------- summaries etc */

.summary-row{font-size:var(--fs-small);padding:7px 0;gap:10px;align-items:baseline}
.summary-row>span:first-child{
  font-size:var(--fs-small);min-width:0;flex:1 1 auto;
  /* Wrapping, not ellipsis: "Fields f…" is shorter than the label but tells the
     reader nothing, and these rows are the record's own explanation of itself. */
  white-space:normal;line-height:1.35;
}
.summary-row b{font-size:var(--fs-small);flex:0 0 auto;text-align:right;white-space:nowrap}
.status{font-size:var(--fs-micro);padding:3px 9px}
.stat .value{font-size:30px;line-height:1.1}
.stat .hint{font-size:var(--fs-small)}
.empty{font-size:var(--fs-ui)}
.info-box{font-size:var(--fs-small);line-height:var(--lh-body)}
.quick-item strong{font-size:var(--fs-ui)}
.quick-item span{font-size:var(--fs-small)}
.side-note{font-size:var(--fs-small)}
.review-update,.glossary-pair{font-size:var(--fs-small)}

.step-item{font-size:var(--fs-small)}
.step-circle{font-size:var(--fs-micro);width:28px;height:28px}
.growth-panel-hint{font-size:var(--fs-small)}
.field-block-zh{font-size:var(--fs-small)}

/* ------------------------------------------------------------------ tables */

/* Tables sit one notch below body size on purpose: a data table carries ten columns
   and has to fit without scrolling on a 1440px screen. 14px is still a clear step up
   from the 13px these cells were set at. */
.table-wrap{overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch}
.data-table{font-size:14px}
.data-table th{padding:12px 11px;white-space:nowrap}
.data-table td{padding:14px 11px;line-height:1.45;white-space:nowrap}
/* Only the long free-text column is allowed to break: a project name is prose, an
   ID or a status is not, and wrapping those is what made the table unreadable. */
.data-table td.cell-wrap{white-space:normal;min-width:180px}
.sample-link{font-size:var(--fs-ui);white-space:nowrap}
.kv .v{font-size:var(--fs-ui)}
.kv-grid{gap:14px 20px}

/* The checkbox column and the export bar added in v0.7.0. */
.data-table th input[type="checkbox"],
.data-table td input[type="checkbox"]{width:17px;height:17px;cursor:pointer;accent-color:var(--pku)}
.bulkbar{gap:14px}
#bulk-summary{white-space:nowrap;flex:0 0 auto}
.bulkbar select{
  flex:0 1 300px;min-width:200px;max-width:320px;
  min-height:var(--control-h);font-size:var(--fs-small);
}
.bulkbar .helper{font-size:var(--fs-small)}

/* Entry blocks on the record page. */
.entry-title b{font-size:var(--fs-body)}
.entry-zh{font-size:var(--fs-small)}
.entry-instance-meta{font-size:var(--fs-small)}
.condition-label-en{font-size:var(--fs-body)}
.condition-label-zh{font-size:var(--fs-small)}
.condition-value{font-size:var(--fs-body)}
.entry-result,.entry-notes{font-size:var(--fs-body);line-height:var(--lh-body)}
.evidence-file-row{font-size:var(--fs-small)}
.evidence-file-row b{font-size:var(--fs-ui)}
.file-type-badge,.storage-badge{font-size:10px}

/* ---------------------------------------------------------------- sign in */

/* The sign-in page is its own layout (no rail). Its grid column must be allowed
   to shrink: the mono demo-account line is wider than a phone viewport and, with
   the default min-width:auto, it stretched the column to ~380px and pushed the
   card past the right edge at 320px. */
.login-page{min-width:0}
.login-panel{padding:clamp(16px,4vw,40px);min-width:0}
.login-card{width:min(440px,100%);max-width:100%;min-width:0}
.demo-box{overflow-wrap:anywhere;word-break:break-word}
.login-copy h1{font-size:clamp(30px,3.4vw,44px);line-height:1.12;letter-spacing:-.02em}
.login-copy p{font-size:var(--fs-body);line-height:var(--lh-body)}
.login-facts dt{font-size:var(--fs-micro)}
.login-facts dd{font-size:var(--fs-ui)}
.login-brand .name{font-size:var(--fs-h2)}
.login-brand-sub{font-size:var(--fs-micro)}
.login-card h2{font-size:var(--fs-h2)}
.login-card p{font-size:var(--fs-small)}
.demo-box{font-size:var(--fs-small)}
.login-foot{font-size:var(--fs-micro)}
.login-tag{font-size:var(--fs-micro)}

/* ==========================================================================
   Responsive layout

   Breakpoints follow the content, not the devices: 1180 (rail + two-column
   detail stops fitting), 900 (tables start scrolling), 760 (rail becomes a top
   strip), 520 (phone).
   ========================================================================== */

@media(max-width:1400px){
  .content{padding:26px 28px 44px}
}

@media(max-width:1180px){
  /* The shell becomes one column here, so the sidebar turns into a top strip.
     align-content:start matters: with min-height:100vh on the shell and two auto
     rows, the grid stretches row 1 and centres the strip's items, which is what
     produced a 300px blank band above the navigation. */
  .app-shell{align-content:start;min-height:0;grid-template-columns:minmax(0,1fr)}
  /* styles.css places .main in column 2 explicitly. Once the shell is one column
     that placement creates an implicit second column, and the content is squeezed
     into the sidebar's 228px track — which is the broken rail that appeared at
     901–1180px. Put it back in the only column there is. */
  .main{grid-column:1}
  /* Grid items default to min-width:auto: without this a wide table stretches the
     column and the whole document scrolls sideways instead of the table. */
  .main,.sidebar,.content{min-width:0;max-width:100%}
  .main{overflow-x:clip}
  /* The strip has to be re-declared, not just left to theme.css: the 228px
     .sidebar width in this file's base rules beats theme's earlier media query
     (same specificity, later source), which kept the sidebar a narrow column while
     the shell was one column — its brand, search and nav then stacked vertically
     into a 3,000px-tall strip that pushed the navigation off screen. */
  /* The chrome becomes a two-row header, laid out by grid rather than by
     flex-wrap. Wrapping made the shape depend on the window: at one width the
     account block sat at the right of the navigation, at another it fell onto a
     third line on its own, and the brand row kept a strip of empty space. A grid
     with named areas is the same two rows at every width.

       ┌ brand ──────────────── search ─────────────── account ┐
       └ nav ──────────────────────────────────────────────────┘

     A page-owned record summary (data-entry pages only) gets a third, explicit
     row — it is a deliberate band, not a wrapped leftover. */
  .sidebar{
    position:static;width:auto;height:auto;overflow:visible;
    display:grid;
    grid-template-columns:auto minmax(0,1fr) auto;
    grid-template-areas:"brand search account" "nav nav nav" "record record record";
    align-items:center;column-gap:20px;
    border-right:0;border-bottom:1px solid var(--line);
    padding:0 18px;
    background:#fbfaf9;
  }
  .brand{grid-area:brand;height:58px;padding:0;border-bottom:0;gap:10px}
  .rail-toggle{display:none}
  .rail-search{grid-area:search;margin:0;width:100%;max-width:420px;height:36px}
  .rail-foot{
    grid-area:account;display:flex;align-items:center;gap:10px;
    margin:0;padding:0;border:0;
  }
  /* The rail opens its popovers upward, because the trigger sits at the bottom of
     the rail. In the header the trigger is at the top of the page, so "upward" put
     the account menu — and Log out with it — off screen. Open downward, aligned to
     the right edge of the header. */
  .user-dropdown{
    left:auto;right:0;top:calc(100% + 8px);bottom:auto;
    width:240px;z-index:60;
  }
  .notes-dropdown{
    left:auto;right:0;top:calc(100% + 8px);bottom:auto;
    width:min(340px,calc(100vw - 24px));z-index:60;
  }
  /* The menu rows are anchors inside the popover; at narrow widths they inherited
     the closed-state hidden flag and rendered as blank strips. Pin them visible
     while the popover itself is open. */
  .user-dropdown.open .user-dropdown-item{visibility:visible;opacity:1;color:var(--ink-2)}
  .user-dropdown.open .user-dropdown-item.danger{color:var(--pku)}
  .nav{
    grid-area:nav;display:flex;flex-direction:row;flex-wrap:nowrap;
    overflow-x:auto;overflow-y:hidden;gap:2px;
    margin:0 -18px;padding:2px 18px 8px;
  }
  .nav a{white-space:nowrap}
  .nav a.active::before{display:none}
  /* One ruled band, read left to right, only where the page provides one. */
  .rail-record{
    grid-area:record;display:flex;flex-direction:row;align-items:center;gap:18px;
    margin:0 -18px;padding:8px 18px;border-top:1px solid var(--line);
    border-left:0;overflow-x:auto;
  }
  .rail-record:empty{display:none}
  .rail-record .rail-note{display:none}
  /* Read the summary as one line of pairs ("PROJECT — · SAMPLE Pending"), not as
     the rail's stacked label/value rows squeezed into a band. */
  .rail-record .rail-record-head{display:flex;align-items:center;gap:10px;flex:0 0 auto}
  .rail-record .rail-spec{
    display:flex;flex-direction:row;flex-wrap:wrap;align-items:baseline;gap:6px;
    margin:0;min-width:0;
  }
  .rail-record .rail-spec dt{font-size:var(--fs-micro);letter-spacing:.06em;color:var(--muted)}
  .rail-record .rail-spec dt:not(:first-of-type)::before{
    content:"·";margin:0 7px 0 1px;color:var(--line-2);
  }
  .rail-record .rail-spec dd{margin:0 4px 0 0;font-size:var(--fs-small);font-weight:600;color:var(--ink)}
  .detail-layout{grid-template-columns:minmax(0,1fr)}
  .detail-side{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:14px}
  .content{padding:24px 22px 40px}
  .page-title{font-size:26px}
  .dashboard-grid,.wizard-shell{grid-template-columns:minmax(0,1fr)}
}

@media(max-width:900px){
  .page-head{flex-wrap:wrap}
  .page-head-actions{width:100%;justify-content:flex-start}
  .page-sub{font-size:var(--fs-body)}
  .filters .input,.filters .select{min-width:0;flex:1 1 220px}
  .bulkbar{flex-wrap:wrap}
  #bulk-summary{text-align:left}
  .data-table{min-width:880px}
  .data-table td{padding:13px 10px}
  .data-table th{padding:12px 10px}
  .kv-grid{grid-template-columns:1fr}
  .detail-side{grid-template-columns:minmax(0,1fr)}
}

@media(max-width:760px){
  /* Same two-row header, tighter: the search box steps out, the account stays at
     the right of the brand row. It used to be hidden here, which left a phone with
     no way to reach the account menu at all. */
  .app-shell{grid-template-columns:minmax(0,1fr);align-content:start;min-height:0}
  .main,.sidebar,.content{min-width:0;max-width:100%}
  .main{overflow-x:clip}
  .sidebar{
    grid-template-columns:auto minmax(0,1fr) auto;
    grid-template-areas:"brand brand account" "nav nav nav" "record record record";
    column-gap:12px;padding:0 12px;
  }
  .brand{height:52px;padding:0;border-bottom:0}
  .brand img{width:24px;height:24px}
  .brand-en{display:none}
  .rail-search{display:none}
  .nav{margin:0 -12px;padding:2px 12px 6px}
  .nav a{white-space:nowrap;padding:8px 10px;font-size:var(--fs-small)}
  .nav a.active::before{display:none}
  .nav .badge{display:none}
  .nav svg{width:15px;height:15px}
  .rail-record{margin:0 -12px;padding:6px 12px;gap:12px}
  .sidebar-footer{display:none}
  .content{padding:18px 16px 36px}
  .page-title{font-size:24px}
  .data-table{min-width:820px}
  .bulkbar{flex-direction:column;align-items:stretch;gap:10px;text-align:left;justify-content:flex-start}
  .bulkbar .btn,.bulkbar select{width:100%;max-width:none;min-width:0}
  /* In a column flex container flex-basis is the HEIGHT: `flex:0 1 300px` from the
     desktop rule made the format dropdown 300px tall. */
  .bulkbar select{flex:0 0 auto;height:var(--control-h)}
  #bulk-summary{text-align:left;align-self:flex-start}
  .btn{min-height:40px}
}

@media(max-width:520px){
  html,body{font-size:15px}
  .content{padding:16px 12px 32px}
  .page-title{font-size:22px}
  .card{padding:16px}
  .filters .input,.filters .select{flex:1 1 100%}
  .data-table{min-width:780px}
  .login-copy h1{font-size:28px}
  /* Five actions on one line cannot fit a phone; two per row can. */
  .page-head-actions{gap:8px}
  .page-head-actions .btn{flex:1 1 calc(50% - 8px);justify-content:center}
  .page-head-actions form{flex:1 1 100%;display:flex}
  .page-head-actions form .btn{width:100%}
}

/* Small phones (iPhone SE, Galaxy A series). Tighten what is left; the rail is
   already a two-row strip and the tables already scroll. */
@media(max-width:360px){
  html,body{font-size:14.5px}
  .content{padding:14px 10px 28px}
  .page-title{font-size:20px}
  .brand{height:46px}
  .card{padding:14px}
  .data-table{min-width:700px}
  .btn{min-height:38px;padding:8px 11px}
}

/* Respect a reader who has asked the OS for less motion (the rail and the
   dropdowns animate). */
@media(prefers-reduced-motion:reduce){
  *{animation-duration:.01ms !important;transition-duration:.01ms !important}
}
