:root {
  --bg: #F4F5F7; --card: #FFFFFF; --text: #111827; --muted: #4B5563; --line: #E5E7EB;
  --accent: #1D4ED8; --accent-soft: #DBEAFE; --accent-dark: #1E3A8A;
  --warn-bg: #FFF7ED; --warn: #9A3412; --danger: #B91C1C; --danger-bg: #FEF2F2;
  --ok: #166534; --ok-bg: #DCFCE7; --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40vh 20px; text-align: center; color: var(--muted); }

.shell { max-width: 720px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(84px + var(--safe-bottom)); }
.top { padding: calc(18px + var(--safe-top)) 20px 8px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.top h1 { margin: 2px 0 0; font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.top .sub { font-size: 13px; color: var(--muted); }
.avatar-btn { width: 44px; height: 44px; border-radius: 22px; border: none; background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; font-size: 17px; cursor: pointer; flex: none; }
.back { display: inline-flex; align-items: center; min-height: 44px; font-size: 16px; text-decoration: none; background: none; border: none; color: var(--accent); padding: 0; cursor: pointer; }

.sync { margin: 0 20px 6px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sync .dot { width: 8px; height: 8px; border-radius: 4px; background: #22C55E; }
.sync.busy .dot { background: #F59E0B; }
.sync.err { color: var(--danger); } .sync.err .dot { background: var(--danger); }

main { padding: 4px 20px 20px; display: flex; flex-direction: column; gap: 18px; }
h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; display: flex; justify-content: space-between; align-items: center; }
h2 .link { text-transform: none; letter-spacing: 0; font-size: 14px; font-weight: 600; background: none; border: none; color: var(--accent); cursor: pointer; min-height: 32px; }

.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; }
.list { background: var(--card); border-radius: var(--radius); padding: 0 14px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: none; border-right: none; border-top: none; text-align: left; cursor: pointer; }
.row:last-child { border-bottom: none; }
.row .main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row .title { font-size: 15px; font-weight: 600; }
.row .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row .right { font-size: 13px; color: var(--muted); flex: none; text-align: right; }
.empty { padding: 14px 0; font-size: 14px; color: var(--muted); }

.members { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
a.mcard, a.row { text-decoration: none; color: inherit; }
.mcard { background: var(--card); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; border: none; cursor: pointer; text-align: left; }
.mcard .nm { font-weight: 600; font-size: 15px; } .mcard .mt { font-size: 12px; color: var(--muted); }
.av { width: 36px; height: 36px; border-radius: 18px; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.av.c0 { background: #DBEAFE; color: #1E3A8A; } .av.c1 { background: #FCE7F3; color: #831843; } .av.c2 { background: #DCFCE7; color: #14532D; }
.av.c3 { background: #FEF3C7; color: #78350F; } .av.c4 { background: #EDE9FE; color: #4C1D95; } .av.lg { width: 56px; height: 56px; border-radius: 28px; font-size: 22px; }

.alert { border-radius: var(--radius); padding: 12px 14px; font-size: 14px; background: var(--card); border: none; text-align: left; width: 100%; cursor: pointer; display: block; }
.alert.high { background: var(--danger-bg); color: #7F1D1D; } .alert.medium { background: var(--warn-bg); color: #431407; }
.alert b { display: block; font-size: 13px; margin-bottom: 2px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; vertical-align: middle; }
.badge.unc { background: #FFEDD5; color: #9A3412; } .badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.muted { background: #F3F4F6; color: var(--muted); } .badge.bad { background: var(--danger-bg); color: var(--danger); }

.dose { background: var(--card); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.dose .hd { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.btn { min-height: 44px; border-radius: 12px; border: 1px solid #D1D5DB; background: #fff; font-size: 15px; font-weight: 600; cursor: pointer; padding: 0 14px; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #FCA5A5; }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 12px; }
.btn:disabled { opacity: 0.5; }
.btn.block { width: 100%; }
.qa { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.seg button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid #D1D5DB; background: #fff; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--text); color: #fff; border-color: var(--text); font-weight: 600; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.profile-hd { display: flex; gap: 14px; align-items: center; }
.profile-hd h1 { margin: 0; font-size: 24px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px; }
.stat .n { font-size: 22px; font-weight: 700; } .stat .l { font-size: 12px; color: var(--muted); }
.qty { white-space: nowrap; flex: none; display: flex; align-items: center; gap: 6px; }
.qty button { width: 36px; height: 36px; border-radius: 18px; border: 1px solid #D1D5DB; background: #fff; font-size: 18px; cursor: pointer; }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.96); border-top: 1px solid var(--line); padding: 6px 8px calc(8px + var(--safe-bottom)); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); z-index: 10; backdrop-filter: blur(10px); }
nav.tabs a { text-decoration: none; color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 48px; justify-content: center; }
nav.tabs a.on { color: var(--accent); font-weight: 600; }
nav.tabs svg { width: 24px; height: 24px; }

/* sheet (modal) */
.backdrop { position: fixed; inset: 0; background: rgba(17,24,39,0.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; }
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 18px; } }
.sheet-hd { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 8px; }
.sheet-hd h3 { margin: 0; font-size: 17px; }
.sheet-bd { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 14px; }
.sheet-ft { padding: 12px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); display: flex; gap: 10px; }
.sheet-ft .btn { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: #374151; }
.field .hint { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { min-height: 44px; border-radius: 10px; border: 1px solid #D1D5DB; background: #fff; padding: 10px 12px; font-size: 16px; width: 100%; }
.field textarea { min-height: 80px; resize: vertical; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: 24px; height: 24px; min-height: 0; }
.field.hidden { display: none; }
.formerr { background: var(--danger-bg); color: var(--danger); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.viewer img { max-width: 100%; border-radius: 10px; display: block; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-bottom)); background: #111827; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
#toast.show { opacity: 1; } #toast.err { background: var(--danger); }

.login { max-width: 420px; margin: 0 auto; padding: calc(80px + var(--safe-top)) 24px 40px; display: flex; flex-direction: column; gap: 18px; align-items: center; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { margin: 0; font-size: 28px; }
.login p { margin: 0; color: var(--muted); font-size: 15px; }
.login .note { font-size: 12px; color: var(--muted); }
#gbtn { min-height: 44px; }
.small { font-size: 12px; color: var(--muted); }
:focus-visible { outline: 3px solid #93C5FD; outline-offset: 2px; }

/* mobile polish */
#recform, #upform, #keyform, #userform { display: flex; flex-direction: column; gap: 16px; }
.field select { -webkit-appearance: none; appearance: none; padding-right: 36px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%234B5563' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center; }
.kv { grid-template-columns: 96px minmax(0, 1fr); }
.kv dd { overflow-wrap: break-word; word-break: normal; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
button, a { -webkit-tap-highlight-color: rgba(0,0,0,0.05); touch-action: manipulation; }
@media (max-width: 360px) { .top h1 { font-size: 24px; } .members { grid-template-columns: repeat(2, minmax(0, 1fr)); } .btns .btn { font-size: 14px; } }
