:root {
  --green: #79C258; --green-light: #97D476; --green-dark: #5FA040; --green-deeper: #477A30;
  --charcoal: #57585B; --charcoal-light: #6E6F72; --charcoal-dark: #3D3E40; --charcoal-deeper: #252627;
  --offwhite: #F5F5F5;

  --bg: var(--charcoal-deeper);
  --surface: var(--charcoal-dark);
  --surface-2: #48494C;
  --line: #4E4F52;
  --text: var(--offwhite);
  --muted: #B4B5B8;
  --faint: #8C8D90;
  --link: var(--green-light);
  --accent: var(--green);
  --danger: #E5735F;
  --warn-bg: #4A3F24; --warn-text: #F2D58A;

  --r: 4px;
  --s1: 8px; --s2: 16px; --s3: 24px; --s4: 32px;
  --font: 'Source Sans 3', 'Myriad Pro', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--offwhite); --surface: #FFFFFF; --surface-2: #EDEDED; --line: #DCDCDD;
    --text: var(--charcoal-deeper); --muted: var(--charcoal); --faint: var(--charcoal-light);
    --link: var(--green-dark); --accent: var(--green-dark);
    --warn-bg: #FBF1D6; --warn-text: #6B4E0E;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 400 17px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: var(--link); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
svg.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 16px; height: 16px; }
.mono { font-family: var(--mono); font-size: 15px; }

/* ---- layout ---- */
#app { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.bar {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: calc(var(--safe-top) + var(--s1)) var(--s2) var(--s1);
  display: flex; align-items: center; gap: var(--s1); min-height: 56px;
  border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; min-width: 0; margin: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wordmark { flex: 1; font-weight: 300; letter-spacing: .04em; font-size: 22px; text-transform: lowercase; color: var(--text); }
.wordmark b { font-weight: 300; color: var(--green); }
.wordmark span { color: var(--faint); font-size: 16px; margin-left: 6px; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  background: none; border: 0; border-radius: var(--r); color: var(--muted); cursor: pointer; flex: none;
}
.iconbtn:active { background: var(--surface); }
.iconbtn.on { color: var(--green); }
.iconbtn.on svg { fill: var(--green); }
main { flex: 1; padding: var(--s2) var(--s2) calc(var(--s4) + var(--safe-bottom)); }
footer { padding: var(--s2) var(--s2) calc(var(--s2) + var(--safe-bottom)); color: var(--faint); font-size: 13px; text-align: center; border-top: 1px solid var(--line); }

/* ---- search ---- */
.search { position: relative; margin-bottom: var(--s2); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input {
  width: 100%; height: 48px; padding: 0 44px 0 42px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); outline: none; font-size: 17px;
}
.search input:focus { border-color: var(--green); }
.search .clear { position: absolute; right: 4px; top: 4px; }

/* ---- sections & lists ---- */
.section-h { display: flex; align-items: center; justify-content: space-between; margin: var(--s3) 0 var(--s1); color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.section-h:first-child { margin-top: 0; }
.list { background: var(--surface); border-radius: var(--r); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px var(--s2); min-height: 56px; color: var(--text);
  border-top: 1px solid var(--line); cursor: pointer; width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0;
}
.list > .row:first-child, .list > :first-child .row { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .ic { color: var(--green); display: flex; }
.row .txt { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .chev { color: var(--faint); }
.group-h { padding: 10px var(--s2) 6px; font-size: 13px; color: var(--muted); background: var(--surface-2); display: flex; align-items: center; gap: 6px; font-weight: 600; }
.empty { color: var(--faint); padding: var(--s3) var(--s2); text-align: center; }
.muted { color: var(--muted); }
.dim { opacity: .6; }

/* ---- org tabs ---- */
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--s2)) var(--s2); padding: 0 var(--s2); }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 15px; cursor: pointer;
}
.tab .n { font-size: 12px; color: var(--faint); }
.tab.on { background: var(--green); border-color: var(--green); color: #fff; }
.tab.on .n { color: rgba(255,255,255,.85); }

/* ---- detail ---- */
.head { margin-bottom: var(--s2); }
.head .k { color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; display: flex; align-items: center; gap: 6px; }
.head h2 { margin: 4px 0 2px; font-size: 26px; line-height: 1.2; font-weight: 600; word-break: break-word; }
.head .sub { color: var(--muted); }
.head .org { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 15px; }
.alert { background: var(--warn-bg); color: var(--warn-text); padding: 12px var(--s2); border-radius: var(--r); margin-bottom: var(--s2); }
.fields { background: var(--surface); border-radius: var(--r); overflow: hidden; }
.field { display: flex; align-items: center; gap: 8px; padding: 10px var(--s2); border-top: 1px solid var(--line); min-height: 56px; }
.field:first-child { border-top: 0; }
.field .fv { flex: 1; min-width: 0; }
.field .l { font-size: 13px; color: var(--muted); }
.field .v { word-break: break-word; white-space: pre-line; }
.field .v.mono { white-space: pre-wrap; }
.field.header { min-height: 0; padding: 14px var(--s2) 6px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.field.tap { cursor: pointer; }
.field.tap:active { background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--link); font-size: 14px; }

.rich { background: var(--surface); border-radius: var(--r); padding: var(--s2); overflow-wrap: anywhere; }
.rich :first-child { margin-top: 0; } .rich :last-child { margin-bottom: 0; }
.rich img { max-width: 100%; height: auto; border-radius: var(--r); }
.rich table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: 15px; }
.rich td, .rich th { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; }
.rich pre { background: var(--bg); padding: 12px; border-radius: var(--r); overflow-x: auto; font: 14px/1.5 var(--mono); }
.rich code { font-family: var(--mono); font-size: .9em; }
.rich h1, .rich h2, .rich h3, .rich h4 { line-height: 1.25; }

.doc .sec { margin-bottom: var(--s2); }
.doc .sec-heading { margin: var(--s3) 0 var(--s1); font-weight: 600; line-height: 1.25; }
.doc .step { display: flex; gap: 12px; background: var(--surface); border-radius: var(--r); padding: var(--s2); }
.doc .step .num { flex: none; width: 28px; height: 28px; border-radius: 999px; background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.doc .step .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.doc .step .body :first-child { margin-top: 0; }
.doc .step .dur { color: var(--faint); font-size: 13px; margin-top: 6px; }
.doc .step .body pre { background: var(--bg); padding: 12px; border-radius: var(--r); overflow-x: auto; font: 14px/1.5 var(--mono); }
.doc .step .body img { max-width: 100%; height: auto; }

/* ---- password secret ---- */
.secret { background: var(--surface); border-radius: var(--r); padding: var(--s2); margin-bottom: var(--s2); }
.secret .l { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.secret .val { font: 500 20px/1.4 var(--mono); word-break: break-all; min-height: 28px; letter-spacing: .02em; }
.secret .val.masked { letter-spacing: .2em; color: var(--faint); }
.secret .acts { display: flex; gap: 8px; margin-top: 12px; }
.secret .timer { height: 3px; background: var(--line); border-radius: 2px; margin-top: 12px; overflow: hidden; }
.secret .timer i { display: block; height: 100%; background: var(--green); transition: width 1s linear; }

/* ---- buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 var(--s2);
  border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600; flex: 1;
}
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:active { background: var(--green-dark); }
.btn.ghost { background: none; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 8px; margin-top: var(--s2); }
label.fl { display: block; margin-bottom: 12px; }
label.fl span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input.in, select.in {
  width: 100%; height: 46px; padding: 0 12px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); outline: none;
}
input.in:focus { border-color: var(--green); }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--green); }
.err { color: var(--danger); min-height: 22px; margin: 4px 0 8px; }

/* ---- login ---- */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: calc(var(--safe-top) + var(--s4)) var(--s3) var(--s4); max-width: 420px; width: 100%; margin: 0 auto; }
.login .wordmark { font-size: 40px; margin-bottom: 4px; flex: none; }
.login .wordmark span { font-size: 26px; }
.login p { color: var(--muted); margin: 0 0 var(--s4); }

/* ---- admin ---- */
.card { background: var(--surface); border-radius: var(--r); padding: var(--s2); margin-bottom: var(--s2); }
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 15px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.audit .row { cursor: default; align-items: flex-start; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 6px; vertical-align: 2px; }
.tag.g { background: var(--green-deeper); color: #fff; }
details.notes { margin-bottom: var(--s2); }
details.notes summary { cursor: pointer; color: var(--muted); padding: 8px 0; list-style: none; display: flex; align-items: center; gap: 6px; font-size: 15px; }
details.notes summary::-webkit-details-marker { display: none; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: var(--s4) auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.banner { background: var(--surface); border-left: 3px solid var(--green); padding: 10px var(--s2); border-radius: var(--r); margin-bottom: var(--s2); font-size: 15px; color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: var(--r); font-weight: 600; transition: all .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- 1.0.2: files, devices ---- */
.filecard { background: var(--surface); border-radius: var(--r); padding: var(--s3) var(--s2); text-align: center; margin-bottom: var(--s2); }
.filecard .fc-ic { color: var(--accent); display: flex; justify-content: center; margin-bottom: 8px; }
.filecard .fc-ic svg { width: 56px; height: 56px; stroke-width: 1.25; }
.filecard .fc-name { font-weight: 600; font-size: 19px; word-break: break-word; }
.filecard .fc-meta { color: var(--muted); font-size: 14px; margin: 4px 0 var(--s2); }
.filecard .fc-note { color: var(--faint); font-size: 13px; margin-top: 12px; }
.userblock + .userblock { border-top: 1px solid var(--line); }
.userblock > .row { border-top: 0; cursor: pointer; }
.devpanel { padding: 0 var(--s2) var(--s2); background: var(--surface); }
.devpanel .list { background: var(--bg); }
.devpanel .actions { margin-top: 8px; }
.hint { color: var(--faint); font-size: 13px; margin-top: 6px; }
.btn.block + .btn.block { margin-top: 8px; }
.login .btn { flex: none; }

/* ---- 1.0.3: passkeys ---- */
.login .or { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: 14px; margin: 4px 0 16px; }
.login .or::before, .login .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.pkprompt { border-left: 3px solid var(--green); }
.pkprompt .pk-h { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 4px; }
.pkprompt .pk-h svg { color: var(--accent); }
.userblock select.in { flex: none; width: 104px !important; padding: 0 8px; font-size: 15px; }
.userblock .row .s { white-space: normal; }
