/* Adde app styles. Loaded after /styles.css (tokens, .btn*, .modal, .login-card, .input, .field*, .phone-input live there). */

:root {
  --red: #D70015;
  --amber: #B25000;
  --card-border: #E5E5EA;
  --card-shadow: 0 3px 0 #EDEDF0;
  --pop-shadow: 0 16px 48px rgba(0, 0, 0, 0.18);
  --nav-h: 56px;
}

[hidden] { display: none !important; }
input, textarea { scroll-margin: 90px 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

body.app { background: #fff; }
#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ App layout */
.app-nav {
  position: sticky; top: 0; z-index: 20; height: var(--nav-h); flex: none;
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  background: rgba(255, 255, 255, 0.88); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--hairline);
}
.profile-wrap { position: relative; }
.profile-btn {
  width: 32px; height: 32px; display: grid; place-items: center; font-size: 16px;
  border-radius: 8px; background: #fff; border: 1px solid var(--hairline); box-shadow: 0 2px 0 #EDEDF0;
  transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s;
}
.profile-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 0 #EDEDF0; }
.profile-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #EDEDF0; }
.profile-btn[aria-expanded="true"] { border-color: var(--blue); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #fff; }
.app-main.bg-gray { background: var(--gray); }

.app-footer { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; padding: 20px 80px; background: #fff; font-size: 12px; line-height: 1.4; }
.app-footer a { color: var(--link-gray); }
.app-footer a:hover { color: var(--ink); text-decoration: underline; }
.foot-copy { color: var(--muted); }

.page-loading { width: 24px; height: 24px; margin: 96px auto; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--blue); animation: spin 0.7s linear infinite; }
.page-error { margin: 96px auto; padding: 0 24px; text-align: center; color: var(--muted); }

/* Site layout (/login): the landing nav and footer; the card sits in the middle */
.login-stage { flex: 1; display: grid; place-items: start center; padding: 120px 16px 150px; }

/* ------------------------------------------------------------ Page shell */
.page { width: 100%; max-width: 680px; margin: 0 auto; padding: 40px 20px 64px; }
.page-narrow { max-width: 560px; }
.page-title { font-size: 48px; font-weight: 700; line-height: 1.08; letter-spacing: -0.025em; }
.page-sub { margin-top: 8px; font-size: 18px; line-height: 1.4; color: var(--muted); }
.foot-note { margin-top: 20px; text-align: center; font-size: 13px; line-height: 1.4; color: var(--muted); }
.stack-lg { display: flex; flex-direction: column; gap: 28px; margin-top: 28px; }
.stack-sm { display: flex; flex-direction: column; gap: 14px; }

.avatar { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #F2F2F7; font-size: 15px; font-weight: 600; color: var(--ink); text-transform: uppercase; }

/* Buttons (extend .btn from styles.css) */
.btn-tall { height: 52px; padding: 0 22px; }
.btn-alive { height: 38px; padding: 0 16px; gap: 8px; background: var(--green); color: #fff; border: 1px solid #1F7A36; box-shadow: 0 2px 0 #17602A; font-size: 15px; font-weight: 600; }
.btn-alive:hover { box-shadow: 0 3px 0 #17602A; }
.btn-alive:active { box-shadow: 0 1px 0 #17602A; }
.btn-alive .icon { stroke-width: 2.5; }
.btn-danger { background: var(--red); color: #fff; border: 1px solid #B80012; box-shadow: 0 3px 0 #8C000E; }
.btn-danger:hover { box-shadow: 0 4px 0 #8C000E; }
.btn-danger:active { box-shadow: 0 1px 0 #8C000E; }
.btn-write { height: 58px; font-size: 17px; font-weight: 500; }
.btn-write .icon { font-size: 18px; }
.btn-light.btn-tall { box-shadow: 0 2px 0 var(--hairline); }
.danger-link { align-self: center; padding: 8px 12px; font-size: 15px; font-weight: 500; color: var(--red); border-radius: 8px; }
.danger-link:hover { text-decoration: underline; }
.form-error { padding: 10px 12px; border-radius: 10px; background: #FFF1F2; color: #B3001B; font-size: 14px; line-height: 1.4; }

/* ---------------------------------------------------------- Form controls */
.radio-group { display: flex; flex-direction: column; gap: 10px; }
.radio-opt { position: relative; display: flex; align-items: flex-start; gap: 14px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--hairline); background: #fff; cursor: pointer; transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; }
.radio-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.radio-dot { flex: none; width: 20px; height: 20px; margin-top: 1px; border-radius: 50%; border: 1.5px solid #C7C7CC; background: #fff; transition: border-color 0.15s, box-shadow 0.15s; }
.radio-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.radio-title { font-size: 15px; font-weight: 600; line-height: 1.35; }
.radio-sub { font-size: 13px; line-height: 1.4; color: var(--muted); }
.radio-opt:has(input:checked) { background: #EAF3FE; border-color: var(--blue); box-shadow: 0 0 0 0.5px var(--blue); }
.radio-opt:has(input:checked) .radio-dot { border-color: var(--blue); box-shadow: inset 0 0 0 4.5px #fff; background: var(--blue); }
.radio-opt:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 2px; }
.radio-group.v-list .radio-opt { align-items: center; padding: 15px 16px; }
.radio-group.v-list .radio-dot { margin-top: 0; }
.radio-group.v-list .radio-title { font-size: 16px; font-weight: 500; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 16px; border-radius: 99px; background: var(--gray); font-size: 14px; font-weight: 600; color: var(--ink); transition: background 0.15s, color 0.15s; }
.chip:hover { background: #ECECF0; }
.chip .chip-check { display: none; font-size: 13px; }
.chip.on { background: #E3EFFD; color: var(--blue); }
.chip.on .chip-check { display: inline-grid; }
.chip .icon { stroke-width: 2.5; }
.reveal { margin-top: 12px; animation: rise-small 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) both; }

.check { position: relative; display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check-box { flex: none; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 6px; border: 1.5px solid #C7C7CC; background: #fff; color: transparent; font-size: 14px; transition: background 0.15s, border-color 0.15s; }
.check-box .icon { stroke-width: 3; }
.check input:checked + .check-box { background: var(--blue); border-color: var(--blue); color: #fff; }
.check input:focus-visible + .check-box { outline: 2px solid var(--blue); outline-offset: 2px; }
.check-text { font-size: 13px; line-height: 1.5; color: var(--ink); padding-top: 2px; }

/* ----------------------------------------------------------------- Sheets */
.sheet { position: relative; width: 440px; max-width: 100%; max-height: calc(100dvh - 32px); overflow-y: auto; padding: 28px; border-radius: 18px; background: #fff; border: 1px solid var(--card-border); box-shadow: 0 4px 0 #EDEDF0, 0 24px 48px -12px rgba(0, 0, 0, 0.18); animation: rise-small 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both; outline: 0; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.sheet-title { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
.sheet-sub { margin-top: 6px; font-size: 15px; line-height: 1.45; color: var(--muted); }
.sheet-x { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--gray); font-size: 16px; color: var(--muted); }
.sheet-form { display: flex; flex-direction: column; gap: 18px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.sheet > .form-error { margin-top: 14px; }

/* Toasts */
.toast-stack { position: fixed; z-index: 100; left: 0; right: 0; bottom: 24px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none; }
.toast { display: inline-flex; align-items: center; gap: 10px; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 500; line-height: 1.35; box-shadow: 0 12px 30px -8px rgba(0, 0, 0, 0.35); animation: rise-small 0.25s cubic-bezier(0.2, 0.8, 0.2, 1) both; pointer-events: auto; transition: opacity 0.25s, transform 0.25s; }
.toast .icon { font-size: 16px; color: #5BD67E; stroke-width: 2.5; }
.toast.error { background: #B3001B; }
.toast.error .icon { color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ----------------------------------------------------------------- Popovers */
.pop-host { position: relative; display: inline-block; }
.pop-menu { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 190px; padding: 6px; border-radius: 12px; background: #fff; border: 1px solid var(--card-border); box-shadow: var(--pop-shadow); animation: rise-small 0.18s ease both; }
.pop-menu.right { left: auto; right: 0; }
.pop-item { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 12px; border-radius: 8px; text-align: left; font-size: 14px; font-weight: 500; white-space: nowrap; }
.pop-item:hover, .pop-item:focus-visible { background: var(--gray); outline: 0; }
.pop-item.on { color: var(--blue); }
.pop-item .icon { font-size: 15px; stroke-width: 2.5; }

.profile-menu { position: absolute; z-index: 40; top: calc(100% + 10px); right: 0; width: 320px; max-width: calc(100vw - 24px); padding: 8px; border-radius: 16px; background: #fff; border: 1px solid var(--card-border); box-shadow: var(--pop-shadow); animation: rise-small 0.2s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.pm-who { display: flex; align-items: center; gap: 12px; padding: 8px 8px 10px; }
.pm-id { min-width: 0; }
.pm-name { font-size: 15px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-email { font-size: 13px; line-height: 1.3; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-rule { height: 1px; margin: 6px 0; border: 0; background: var(--hairline); }
.pm-check { padding: 8px 8px 6px; display: flex; flex-direction: column; gap: 10px; }
.pm-title { font-size: 13px; font-weight: 600; line-height: 1.3; }
.pm-next { font-size: 12px; line-height: 1.4; color: var(--muted); }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 2px; border-radius: 10px; background: #EFEFF4; }
.seg-btn { height: 32px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--link-gray); transition: background 0.15s, box-shadow 0.15s; }
.seg-btn.on { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.pm-row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 10px; text-align: left; font-size: 15px; font-weight: 500; }
.pm-row:hover, .pm-row:focus-visible { background: var(--gray); outline: 0; }
.pm-row > .icon { font-size: 18px; color: var(--link-gray); stroke-width: 1.75; }
.pm-label { flex: 1; }
.pm-count { font-size: 14px; font-weight: 400; color: var(--muted); }

/* ------------------------------------------------------------------ Welcome */
.page-narrow .stack-lg .field-label { font-size: 14px; }

/* --------------------------------------------------------------------- Home */
.page-home { display: flex; flex-direction: column; gap: 20px; }
.card { padding: 20px 20px 8px; border-radius: 16px; background: #fff; border: 1px solid var(--card-border); box-shadow: var(--card-shadow); }
#trusted { scroll-margin-top: 76px; }
.card-title { font-size: 22px; font-weight: 600; line-height: 1.25; letter-spacing: -0.01em; }
.card-title.small { font-size: 15px; font-weight: 600; letter-spacing: 0; }
.card-sub { margin-top: 4px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.empty { padding: 14px 0 16px; margin-top: 14px; border-top: 1px solid #EFEFF2; font-size: 14px; color: var(--muted); }

.alive-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; }
.alive-dot { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); }
.alive-dot span { width: 10px; height: 10px; border-radius: 50%; background: var(--green); }
.alive-dot.due { background: rgba(178, 80, 0, 0.12); }
.alive-dot.due span { background: #E8710A; }
.alive-text { flex: 1; min-width: 0; }
.alive-title { font-size: 15px; font-weight: 600; line-height: 1.3; }
.alive-sub { font-size: 13px; line-height: 1.35; color: var(--muted); }
.freq-btn { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; line-height: 1.35; color: var(--link); border-radius: 4px; }
.freq-btn:hover { text-decoration: underline; }
.freq-btn .icon { font-size: 13px; }

.greet { padding-top: 12px; display: flex; flex-direction: column; gap: 0; }
.greet .page-sub { margin-bottom: 22px; }

.rows { margin-top: 14px; }
.rows > li { border-top: 1px solid #EFEFF2; }
.row { width: 100%; display: flex; align-items: center; gap: 14px; padding: 14px 0; text-align: left; border-radius: 8px; }
.row:hover .row-title { color: #000; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-size: 16px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; line-height: 1.35; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-icon { flex: none; font-size: 18px; color: #86868B; stroke-width: 1.75; }
.avatar.add { background: transparent; border: 1px dashed var(--blue); color: var(--blue); font-size: 18px; }
.avatar.add .icon { stroke-width: 1.75; }
.add-title { color: var(--link); }

.steps-card { padding-bottom: 16px; }
.steps-list { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.steps-list li { display: flex; align-items: center; gap: 12px; font-size: 18px; line-height: 1.35; }
.step-no { flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--line); font-size: 12px; color: var(--link-gray); }
.help-link { align-self: center; display: inline-flex; align-items: center; gap: 8px; padding: 4px 0 8px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.help-link:hover { color: var(--ink); text-decoration: underline; }
.help-link .icon { font-size: 15px; }

/* ----------------------------------------------------------------- Settings */
.back-link { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 20px; font-size: 16px; line-height: 1.3; color: var(--link); }
.back-link:hover { text-decoration: underline; }
.page-settings .page-title { margin-bottom: 20px; }
.sgroup { margin-top: 22px; }
.sgroup + .sgroup { margin-top: 24px; }
.sgroup-label { margin-bottom: 8px; padding-left: 0; font-size: 12px; font-weight: 400; line-height: 1.3; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted); }
.slist { border-radius: 16px; background: #fff; padding: 0 16px; }
.slist > li + li { border-top: 1px solid #EFEFF2; }
.srow { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 12px; padding: 12px 0; text-align: left; font-size: 17px; line-height: 1.3; }
.srow-label { flex: 1; min-width: 0; }
.srow-value { flex: none; max-width: 55%; text-align: right; color: #86868B; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.srow-chev { flex: none; margin-left: -4px; font-size: 18px; color: #C7C7CC; }
.srow.blue { color: var(--link); }
.srow.red { color: var(--red); }
button.srow:hover .srow-label, a.srow:hover .srow-label { color: #000; }
.srow.blue:hover .srow-label { color: var(--blue); }
.srow.red:hover .srow-label { color: #B3001B; }

/* ============================================================================
   WRITE / CHAT STYLES
   Part 2 (js/pages/write.js: /write, /write/new, /write/chat) puts its styles
   HERE, at the end of app.css (no separate stylesheet). Prefix selectors with
   .w- or scope them under body[data-page^="write"].
   Available shared pieces: .page, .avatar, .btn*, .sheet/.modal, .input/.field,
   .chip, .pop-menu, .toast, .card, tokens in styles.css (--blue, --gray, ...).
   ============================================================================ */

/* ---- Shell: people sidebar + content. The page is exactly one viewport tall; the footer sits below the shell. */
body[data-page^="write"] #app { min-height: 0; height: 100vh; height: max(100dvh, 560px); }
body[data-page^="write"] .app-main { min-height: 0; overflow: hidden; }
.w-shell { position: relative; flex: 1; min-height: 0; display: flex; }
.w-side { flex: none; width: 280px; display: flex; flex-direction: column; gap: 0; padding: 16px 12px; overflow-y: auto; background: var(--gray); border-right: 1px solid var(--hairline); }
.w-content { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; }
.w-content.is-chat { overflow: hidden; }
.w-scrim, .w-side-close, .w-menu-btn, .w-phone-bar { display: none; }

.w-new { flex: none; display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 14px; border-radius: 12px; background: #fff; border: 1px solid var(--hairline); box-shadow: 0 2px 0 #E6E6EB; font-size: 16px; font-weight: 500; color: var(--ink); transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; }
.w-new .icon { font-size: 18px; stroke-width: 1.75; }
.w-new:hover { box-shadow: 0 3px 0 #E6E6EB; }
.w-new[aria-current="page"] { background: #EAF3FE; border-color: #CFE0F7; box-shadow: none; font-size: 14px; font-weight: 600; }
.w-side-label { margin: 20px 10px 8px; font-size: 12px; line-height: 1.3; color: var(--muted); }
.w-side-empty { margin: 4px 10px; font-size: 13px; line-height: 1.45; color: var(--muted); }
.w-people { display: flex; flex-direction: column; gap: 2px; }
.w-person { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; transition: background 0.15s; }
.w-person:hover { background: rgba(0, 0, 0, 0.04); }
.w-person[aria-current="page"] { background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.07); }
.w-av { width: 34px; height: 34px; font-size: 14px; }
.w-person-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.w-person-name { font-size: 14px; font-weight: 600; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-person-status { font-size: 12px; line-height: 1.3; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-home { margin-top: auto; flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 10px 4px; font-size: 14px; font-weight: 600; }
.w-home .icon { font-size: 18px; stroke-width: 1.75; }
.w-home:hover { color: #000; text-decoration: underline; }

.w-menu-btn { width: 40px; height: 40px; flex: none; place-items: center; border-radius: 10px; background: #fff; border: 1px solid var(--hairline); box-shadow: 0 2px 0 #EDEDF0; font-size: 20px; }
.w-menu-btn .icon { stroke-width: 1.75; }

/* ---- New person */
.w-new-wrap { width: 100%; max-width: 480px; margin: 0 auto; padding: 88px 20px 56px; }
.w-new-wrap .page-title { font-size: 44px; }
.w-form { display: flex; flex-direction: column; gap: 18px; margin-top: 24px; }
.w-more { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 13px; line-height: 1.4; color: var(--link); border-radius: 4px; }
.w-more:hover { text-decoration: underline; }
.w-more .icon { font-size: 14px; }
.w-extra { display: flex; flex-direction: column; gap: 18px; margin-top: 0; }
.w-foot { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: -2px; font-size: 13px; line-height: 1.4; color: var(--muted); text-align: center; }
.w-foot .icon { font-size: 14px; }

/* ---- Chat */
.w-chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.w-chat-head { flex: none; width: 100%; max-width: 720px; margin: 0 auto; padding: 16px 20px 10px; display: flex; align-items: center; gap: 12px; }
.w-head { min-width: 0; display: flex; align-items: center; gap: 12px; padding: 4px 8px 4px 0; margin: -4px 0; border-radius: 12px; text-align: left; }
.w-head:hover .w-head-name { text-decoration: underline; }
.w-av-lg { width: 40px; height: 40px; font-size: 15px; }
.w-head-text { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.w-head-name { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-head-sub { font-size: 12.5px; line-height: 1.3; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; padding: 0 20px; }
.w-col { width: 100%; max-width: 680px; margin: 0 auto; padding: 22px 0 16px; display: flex; flex-direction: column; }
.w-tip { align-self: center; display: flex; align-items: flex-start; gap: 10px; max-width: 440px; padding: 12px 16px; border-radius: 12px; background: #FFF6EE; color: #A0612B; font-size: 13px; line-height: 1.5; }
.w-tip .icon { margin-top: 3px; font-size: 14px; }
.w-notes { display: flex; flex-direction: column; gap: 14px; }
.w-notes:not(:empty) { margin-top: 24px; }

.w-note { display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: 14px; background: #FFFDF8; border: 1px solid #F1EADB; animation: rise-small 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.w-note-text { font-size: 16px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.w-photos { display: grid; gap: 6px; grid-template-columns: 1fr; }
.w-photos.n2 { grid-template-columns: 1fr 1fr; }
.w-photos.n3 { grid-template-columns: repeat(3, 1fr); }
.w-photo { display: block; overflow: hidden; border-radius: 10px; background: #F1EADB; }
.w-photos.n1 .w-photo { max-width: 380px; }
.w-photo img { width: 100%; max-height: 300px; object-fit: cover; transition: transform 0.25s; }
.w-photos.n2 img, .w-photos.n3 img { height: 150px; }
.w-photo:hover img { transform: scale(1.02); }
.w-media-fail { display: flex; align-items: center; gap: 8px; padding: 16px; font-size: 13px; color: var(--muted); }
.w-video { width: 100%; max-width: 420px; max-height: 320px; border-radius: 10px; background: #000; }
.w-voice { display: flex; align-items: center; gap: 10px; max-width: 420px; }
.w-voice-ico { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: #F4ECD8; color: #8A6A2B; font-size: 16px; }
.w-audio { flex: 1; min-width: 0; height: 38px; }
.w-note-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.w-note-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: 12px; line-height: 1.4; color: #8E8E93; }
.w-locked { display: inline-flex; align-items: center; gap: 4px; }
.w-locked .icon { font-size: 12px; }
.w-note-menu { position: relative; display: inline-block; flex: none; }
.w-note-more { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: #8E8E93; font-size: 18px; }
.w-note-more:hover, .w-note-more[aria-expanded="true"] { background: rgba(0, 0, 0, 0.05); color: var(--ink); }
.w-note-menu .pop-menu { min-width: 150px; }
.w-note-menu .pop-menu.up { top: auto; bottom: calc(100% + 6px); }
.w-edit-ta { height: auto; min-height: 150px; padding: 12px 14px; line-height: 1.5; resize: vertical; font-size: 16px; }
.w-lightbox { width: min(960px, 100%); padding: 12px; background: #111; border-color: #111; }
.w-lightbox-img { width: 100%; max-height: calc(100dvh - 80px); object-fit: contain; border-radius: 10px; }
.w-lightbox-x { position: absolute; top: 18px; right: 18px; z-index: 1; background: rgba(0, 0, 0, 0.55); color: #fff; }

/* Composer */
.w-composer { position: relative; flex: none; width: 100%; max-width: 720px; margin: 0 auto; padding: 12px 20px 28px; background: #fff; }
.w-row { display: flex; align-items: flex-end; gap: 10px; }
.w-circle { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: #fff; border: 1px solid var(--line); box-shadow: 0 2px 0 var(--hairline); font-size: 21px; transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s, opacity 0.2s; }
.w-circle .icon { stroke-width: 1.75; }
.w-circle:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 3px 0 var(--hairline); }
.w-circle:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 1px 0 var(--hairline); }
.w-circle:disabled, .w-cam:disabled { opacity: 0.4; }
.w-attach { position: relative; flex: none; }
.w-attach-pop { position: absolute; z-index: 30; left: 0; bottom: calc(100% + 8px); min-width: 230px; padding: 6px; border-radius: 12px; background: #fff; border: 1px solid var(--card-border); box-shadow: var(--pop-shadow); animation: rise-small 0.18s ease both; }
.w-pop-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 8px; text-align: left; font-size: 15px; font-weight: 500; white-space: nowrap; }
.w-pop-item:hover, .w-pop-item:focus-visible { background: var(--gray); outline: 0; }
.w-pop-item .icon { font-size: 18px; color: var(--link-gray); stroke-width: 1.75; }
.w-file { display: none; }
.w-field { flex: 1; min-width: 0; min-height: 46px; display: flex; align-items: flex-end; gap: 6px; padding: 0 8px 0 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; cursor: text; transition: border-color 0.2s, box-shadow 0.2s; }
.w-field:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15); }
.w-ta { flex: 1; min-width: 0; padding: 11px 0; border: 0; outline: 0; resize: none; background: none; font: inherit; font-size: 17px; line-height: 22px; color: var(--ink); max-height: 168px; overflow-y: auto; }
.w-ta::placeholder { color: #86868B; }
.w-cam { flex: none; width: 32px; height: 44px; display: grid; place-items: center; color: #86868B; font-size: 18px; }
.w-cam:hover:not(:disabled) { color: var(--ink); }
.w-cam .icon { stroke-width: 1.75; }
.w-save { width: 100%; height: 48px; margin-top: 10px; gap: 8px; font-size: 16px; font-weight: 500; }
.w-save .icon { font-size: 16px; }
.w-save:disabled:not(.is-busy) { opacity: 0.45; box-shadow: 0 3px 0 var(--blue-shadow); transform: none; }
.w-hint { margin-bottom: 8px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.w-hint.is-error { color: #B3001B; }

/* Pending attachments */
.w-pending { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.w-chip { position: relative; width: 76px; height: 76px; border-radius: 12px; background: #F2F2F7; border: 1px solid var(--hairline); overflow: visible; }
.w-chip.is-voice { width: auto; min-width: 150px; padding: 0 16px 0 10px; display: flex; align-items: center; gap: 10px; }
.w-chip-img { width: 100%; height: 100%; object-fit: cover; border-radius: 11px; background: #E5E5EA; }
.w-chip-voice { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: #fff; color: var(--blue); font-size: 18px; }
.w-chip:not(.is-voice) .w-chip-voice { width: 100%; height: 100%; border-radius: 11px; background: transparent; color: var(--muted); }
.w-chip-kind { position: absolute; left: 6px; bottom: 6px; font-size: 14px; color: #fff; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5)); }
.w-chip-label { font-size: 13px; font-weight: 500; line-height: 1.3; white-space: nowrap; }
.w-chip-over { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 2px; border-radius: 11px; background: rgba(29, 29, 31, 0.55); color: #fff; font-size: 12px; font-weight: 600; line-height: 1.3; text-align: center; }
.w-chip[data-status="preparing"] .w-chip-over, .w-chip[data-status="uploading"] .w-chip-over, .w-chip[data-status="error"] .w-chip-over { display: flex; }
.w-chip.is-voice .w-chip-over { left: auto; width: auto; background: none; color: var(--muted); right: 12px; flex-direction: row; }
.w-chip.is-voice[data-status="error"] .w-chip-over { color: #B3001B; }
.w-chip[data-status="error"]:not(.is-voice) .w-chip-over { background: rgba(179, 0, 27, 0.72); }
.w-chip.is-voice .w-chip-label { margin-right: 54px; }
.w-chip.is-voice[data-status="done"] .w-chip-label { margin-right: 0; }
.w-chip-retry { width: 30px; height: 30px; display: none; place-items: center; border-radius: 50%; background: #fff; color: #B3001B; font-size: 14px; }
.w-chip[data-status="error"] .w-chip-retry { display: grid; }
.w-chip-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; border-radius: 0 0 11px 11px; overflow: hidden; background: rgba(0, 0, 0, 0.12); display: none; }
.w-chip-bar i { display: block; height: 100%; width: 0; background: var(--blue); transition: width 0.15s linear; }
.w-chip[data-status="uploading"] .w-chip-bar { display: block; }
.w-chip-x { position: absolute; top: -7px; right: -7px; z-index: 1; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: #fff; font-size: 12px; box-shadow: 0 0 0 2px #fff; }
.w-chip-x .icon { stroke-width: 2.5; }
.w-chip-x:hover { background: #000; }

/* Recording */
.w-rec { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 6px 0 16px; border-radius: 12px; background: #FFF1F2; border: 1px solid #FFD3D8; }
.w-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #E5192D; animation: w-pulse 1.1s ease-in-out infinite; }
.w-rec-label { font-size: 14px; font-weight: 500; color: #B3001B; }
.w-rec-time { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.w-rec-gap { flex: 1; }
.w-rec-btn { height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 14px; border-radius: 9px; background: #fff; border: 1px solid #FFC2C8; font-size: 14px; font-weight: 600; }
.w-rec-btn:hover { background: #FFF8F8; }
.w-rec-btn.stop { background: #E5192D; border-color: #C70F22; color: #fff; }
.w-rec-btn.stop:hover { background: #D1101F; }
.w-rec-btn .icon { font-size: 13px; fill: currentColor; }
@keyframes w-pulse { 50% { opacity: 0.25; transform: scale(0.8); } }

/* Saved overlay */
.w-saved { display: flex; flex-direction: column; align-items: center; text-align: center; }
.w-saved-check { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 16px; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 30px; animation: w-pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.w-saved-check .icon { stroke-width: 2.5; }
.w-saved .sheet-sub { margin-top: 8px; }
.w-saved .sheet-actions { width: 100%; margin-top: 22px; }
.w-trusted-row { width: 100%; display: flex; align-items: center; gap: 12px; margin-top: 22px; padding: 14px; border-radius: 14px; background: var(--gray); text-align: left; transition: background 0.15s; }
.w-trusted-row:hover { background: #EEEEF2; }
.w-trusted-ico { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: #E3EFFD; color: var(--blue); font-size: 18px; }
.w-trusted-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.w-trusted-title { font-size: 15px; font-weight: 600; line-height: 1.3; }
.w-trusted-sub { font-size: 13px; line-height: 1.4; color: var(--muted); }
.w-trusted-chev { font-size: 18px; color: #C7C7CC; }
@keyframes w-pop { from { transform: scale(0.5); opacity: 0; } }

/* Tablet: narrower sidebar */
@media (max-width: 1199.98px) {
  .w-side { width: 240px; }
  .w-new-wrap { padding-top: 72px; }
}

/* Phone: the sidebar becomes a slide-in drawer, the composer stays pinned to the bottom */
@media (max-width: 809.98px) {
  .w-menu-btn, .w-phone-bar { display: grid; }
  .w-phone-bar { display: flex; padding-bottom: 14px; }
  .w-side { position: fixed; z-index: 60; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); padding-top: 56px; visibility: hidden; transform: translateX(-100%); box-shadow: none; transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s; }
  .w-shell.drawer-open .w-side { visibility: visible; transform: none; box-shadow: 8px 0 40px rgba(0, 0, 0, 0.18); transition-delay: 0s; }
  .w-scrim { display: block; position: fixed; z-index: 55; inset: 0; background: rgba(29, 29, 31, 0.32); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .w-shell.drawer-open .w-scrim { opacity: 1; pointer-events: auto; }
  .w-side-close { display: grid; position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; place-items: center; border-radius: 50%; background: #fff; font-size: 16px; color: var(--muted); }
  .w-new-wrap { padding: 16px 16px 40px; }
  .w-new-wrap .page-title { font-size: 34px; }
  .w-chat-head { padding: 12px 16px 8px; gap: 10px; }
  .w-head-name { font-size: 20px; }
  .w-scroll { padding: 0 16px; }
  .w-col { padding-top: 16px; }
  .w-tip { max-width: none; align-self: stretch; }
  .w-composer { padding: 10px 16px 14px; border-top: 1px solid var(--hairline); }
  .w-ta { font-size: 16px; }
  .w-note-text { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .w-side, .w-scrim, .w-note, .w-saved-check, .w-rec-dot { transition: none; animation: none; }
}

/* ------------------------------------------------------------- Responsive */
@media (max-width: 1199.98px) {
  .app-footer { padding-left: 40px; padding-right: 40px; }
}

@media (max-width: 809.98px) {
  .page { padding: 24px 16px 48px; }
  .page-title { font-size: 34px; }
  .page-sub { font-size: 17px; }
  .app-footer { padding: 20px 16px 24px; gap: 4px 16px; }
  /* Footer is hidden on phone for app pages, except /welcome */
  body:not([data-page="welcome"])[data-layout="app"] .app-footer { display: none; }
  .login-stage { padding: 48px 16px 64px; }
  .sheet { padding: 24px 20px; }
  .steps-list li { font-size: 17px; align-items: flex-start; }
  .step-no { margin-top: 2px; }
  .srow { font-size: 16px; }
  .srow-value { max-width: 48%; }
  .toast-stack { bottom: 16px; }
  .alive-card { padding-left: 12px; }
  .btn-write { height: 54px; }
}

@media (max-width: 380px) {
  .profile-menu { right: -4px; }
}
.check-text a { color: var(--link); text-decoration: underline; }
