/* ============ Bookly — Instagram-style light theme ============ */
:root {
  --bg: #ffffff;
  --bg-page: #ffffff;
  --bg-soft: #fafafa;
  --bg-hover: #f2f2f2;
  --border: #dbdbdb;
  --border-soft: #efefef;
  --text: #262626;
  --text-2: #737373;
  --text-3: #8e8e8e;
  --blue: #0095f6;
  --blue-dark: #1877f2;
  --blue-light: #e0f1ff;
  --red: #ed4956;
  --sidebar-w: 244px;
  --sidebar-w-narrow: 72px;
  --feed-w: 470px;
  --right-w: 320px;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --logo-font: "Grand Hotel", "Brush Script MT", "Segoe Script", "Lucida Handwriting", cursive;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 18px;
  color: var(--text);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; font-size: inherit; color: inherit; cursor: pointer; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
img { display: block; }

/* ---------- generic ---------- */
.logo {
  font-family: var(--logo-font);
  font-size: 34px;
  line-height: 1;
  color: var(--text);
  font-weight: 400;
}
.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.avatar-24 { width: 24px; height: 24px; }
.avatar-32 { width: 32px; height: 32px; }
.avatar-44 { width: 44px; height: 44px; }
.avatar-56 { width: 56px; height: 56px; }
.avatar-77 { width: 77px; height: 77px; }
.avatar-150 { width: 150px; height: 150px; }

.username { font-weight: 600; color: var(--text); }
a.username:hover { opacity: .7; }
.muted { color: var(--text-3); }
.small { font-size: 12px; line-height: 16px; }
.bold { font-weight: 600; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 8px; padding: 7px 16px;
  font-weight: 600; font-size: 14px; line-height: 18px;
  background: var(--blue); color: #fff; transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--blue-dark); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-secondary { background: var(--bg-hover); color: var(--text); }
.btn-secondary:hover { background: #dbdbdb; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #c93a46; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg-soft); }
.btn-sm { padding: 5px 12px; font-size: 12px; line-height: 16px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--blue); font-weight: 600; cursor: pointer; }
.btn-link:hover { color: var(--blue-dark); }
.btn-link:disabled { opacity: .4; cursor: default; }
.link-muted { background: none; border: 0; padding: 0; color: var(--text-3); cursor: pointer; }
.link-muted:hover { color: var(--text-2); }

.icon-btn {
  background: none; border: 0; padding: 8px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: var(--text); line-height: 0;
}
.icon-btn:hover { color: var(--text-3); }
.icon-btn svg { width: 24px; height: 24px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-soft); padding: 9px 10px; font-size: 14px; line-height: 18px; outline: none;
}
.input:focus { border-color: #a8a8a8; background: #fff; }
textarea.input { resize: vertical; min-height: 80px; }
.error-text { color: var(--red); font-size: 13px; line-height: 17px; margin: 8px 0; text-align: center; white-space: pre-wrap; }
.error-text:empty { display: none; }
.hint { font-size: 12px; color: var(--text-3); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--bg-hover); color: var(--text-2);
}
.chip-green { background: #e6f6ec; color: #1b7a3e; }
.chip-red { background: #fdecee; color: #c62737; }
.chip-blue { background: var(--blue-light); color: #0d6cbf; }
.chip-gray { background: var(--bg-hover); color: var(--text-2); }

.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 20px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.card-sub { font-size: 13px; color: var(--text-3); margin: -6px 0 14px; }

.divider { display: flex; align-items: center; gap: 16px; margin: 16px 0; color: var(--text-3); font-size: 13px; font-weight: 600; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- spinner ---------- */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border-soft); border-top-color: var(--text-3);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 24px auto;
}
.spinner.sm { width: 18px; height: 18px; border-width: 2px; margin: 0; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-block { padding: 40px 0; text-align: center; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 60px 20px; color: var(--text-2); }
.empty-icon { width: 64px; height: 64px; margin: 0 auto 16px; border: 2px solid var(--text); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text); }
.empty-icon svg { width: 32px; height: 32px; }
.empty h3 { margin: 0 0 6px; font-size: 20px; font-weight: 600; color: var(--text); }
.empty p { margin: 0 0 14px; }

/* ============ AUTH ============ */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: var(--bg-soft); padding: 40px 16px;
}
.auth-box { width: 100%; max-width: 350px; }
.auth-card { background: #fff; border: 1px solid var(--border); border-radius: 2px; padding: 36px 40px 24px; }
.auth-card .logo { display: block; text-align: center; font-size: 50px; margin-bottom: 30px; }
.auth-card .input { margin-bottom: 6px; padding: 9px 8px; font-size: 12px; background: var(--bg-soft); border-radius: 3px; }
.auth-card .btn { margin-top: 10px; }
.auth-tagline { text-align: center; color: var(--text-3); font-size: 16px; font-weight: 600; line-height: 20px; margin: 0 0 16px; }
.otp-panel { display: flex; flex-direction: column; gap: 10px; }
.otp-badge {
  align-self: center; padding: 5px 10px; border-radius: 999px; background: var(--blue-light); color: var(--blue-dark);
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.otp-title { margin-bottom: 0; }
.otp-email {
  text-align: center; font-weight: 700; color: var(--text); background: var(--bg-soft); border: 1px solid var(--border-soft);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 4px; word-break: break-all;
}
.otp-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.otp-actions .btn-secondary { background: #f3f4f6; color: var(--text); }
.otp-actions .btn-secondary:hover { background: #e8e9eb; }
.otp-actions .btn-secondary:disabled { cursor: not-allowed; opacity: .6; }
.auth-switch { background: #fff; border: 1px solid var(--border); border-radius: 2px; padding: 20px; text-align: center; margin-top: 10px; }
.avatar-picker { display: flex; align-items: center; gap: 14px; margin: 4px 0 12px; }
.avatar-picker .avatar { width: 56px; height: 56px; }
.avatar-picker input[type="file"] { display: none; }
.avatar-picker .btn-link { font-size: 13px; }
.auth-footer { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 30px; }

/* ============ LAYOUT ============ */
.layout { display: block; min-height: 100vh; }
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  border-right: 1px solid var(--border); background: #fff;
  padding: 8px 12px 20px; display: flex; flex-direction: column; z-index: 20;
}
.sidebar .logo { padding: 25px 12px 16px; margin-bottom: 19px; display: block; font-size: 30px; }
.nav-list { display: flex; flex-direction: column; gap: 4px; }
.nav-bottom { margin-top: auto; }
.nav-item {
  display: flex; align-items: center; gap: 16px; padding: 12px; border-radius: 8px;
  background: none; border: 0; text-align: left; width: 100%; color: var(--text); font-size: 16px; line-height: 20px;
  transition: background .15s;
}
.nav-item:hover { background: var(--bg-soft); }
.nav-item:hover .nav-icon svg { transform: scale(1.05); }
.nav-item.active { font-weight: 700; }
.nav-item.active .nav-icon svg path,
.nav-item.active .nav-icon svg line,
.nav-item.active .nav-icon svg circle { stroke-width: 2.6; }
.nav-item.active .avatar { outline: 2px solid var(--text); }
.nav-icon { width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; line-height: 0; flex-shrink: 0; }
.nav-icon svg { width: 24px; height: 24px; transition: transform .15s; }

.page { margin-left: var(--sidebar-w); min-height: 100vh; }

/* ---------- home ---------- */
.home { display: flex; justify-content: center; gap: 64px; padding: 30px 20px 40px; max-width: 1000px; margin: 0 auto; }
.feed { width: var(--feed-w); max-width: 100%; flex-shrink: 0; }
.right-col { width: var(--right-w); flex-shrink: 0; padding-top: 6px; }
.me-card { display: flex; align-items: center; gap: 12px; padding: 8px 0 16px; }
.me-card .me-info { flex: 1; min-width: 0; }
.me-card .me-info div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.right-title { display: flex; justify-content: space-between; color: var(--text-2); font-weight: 600; margin: 8px 0 12px; }
.suggest-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.suggest-row .avatar { width: 44px; height: 44px; }
.suggest-info { flex: 1; min-width: 0; }
.suggest-info .username { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest-info .muted { display: block; font-size: 12px; }
.rank-badge { font-size: 11px; font-weight: 700; color: var(--text-3); width: 18px; text-align: right; }

/* ---------- post card ---------- */
.post { padding-bottom: 16px; margin-bottom: 20px; border-bottom: 1px solid var(--border-soft); }
.post-head { display: flex; align-items: center; gap: 10px; padding: 0 0 12px; height: 56px; }
.post-head-text { flex: 1; min-width: 0; display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; }
.post-head-text .time { color: var(--text-3); }
.post-head-text .dot { color: var(--text-3); }
.post-img-wrap {
  width: 100%; aspect-ratio: 1 / 1; overflow: hidden; border: 1px solid var(--border-soft); border-radius: 4px;
  background: #000; cursor: pointer;
}
.post-img { width: 100%; height: 100%; object-fit: cover; }
.post-actions { display: flex; align-items: center; margin: 4px -8px 0; }
.post-actions .icon-btn.liked, .pm-actions .icon-btn.liked { color: var(--red); }
.post-likes { font-weight: 600; margin: 4px 0 8px; }
.post-caption { line-height: 18px; word-break: break-word; }
.post-desc { color: var(--text); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.post .link-muted { margin-top: 6px; display: block; }
.like-anim { animation: pop .3s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.3); } 100% { transform: scale(1); } }

/* ---------- search ---------- */
.search-page { max-width: 630px; margin: 0 auto; padding: 30px 20px 40px; }
.search-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.search-input-wrap { flex: 1; position: relative; }
.search-input-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-3); }
.search-input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-hover); padding: 0 14px 0 42px; font-size: 16px; outline: none; }
.search-input:focus { background: #fff; border-color: #a8a8a8; }
.result-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 24px; }
.result-head { display: flex; gap: 20px; align-items: flex-start; }
.result-body { flex: 1; min-width: 0; }
.result-name { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.result-name .username { font-size: 20px; font-weight: 400; }
.result-stats { display: flex; gap: 20px; margin-bottom: 8px; flex-wrap: wrap; }
.result-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.result-bio { white-space: pre-wrap; word-break: break-word; }
.result-grid { margin-top: 16px; }
.warn-box { background: #fff8e1; border: 1px solid #ffe08a; color: #7a5a00; padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-top: 10px; }
.section-title { font-weight: 600; color: var(--text-2); margin: 24px 0 10px; }
.popular-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-soft); }
.popular-row:last-child { border-bottom: 0; }

/* ---------- profile ---------- */
.profile { max-width: 935px; margin: 0 auto; padding: 30px 20px 40px; }
.profile-head { display: flex; gap: 30px; margin-bottom: 44px; }
.profile-avatar-col { width: 290px; display: flex; justify-content: center; flex-shrink: 0; }
.profile-avatar-col .avatar { width: 150px; height: 150px; }
.profile-lock { width: 150px; height: 150px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-soft); display: flex; align-items: center; justify-content: center; color: var(--text-2); flex-shrink: 0; }
.profile-lock svg { width: 44px; height: 44px; }
.profile-body { flex: 1; min-width: 0; }
.profile-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.profile-row .username { font-size: 20px; font-weight: 400; }
.profile-stats { display: flex; gap: 40px; margin-bottom: 20px; }
.profile-stats .stat { background: none; border: 0; padding: 0; font-size: 16px; color: var(--text); font-family: inherit; }
.profile-stats .stat b { font-weight: 600; }
.profile-stats button.stat { cursor: pointer; }
.profile-bio { white-space: pre-wrap; word-break: break-word; }
.profile-email { color: var(--text-3); font-size: 13px; margin-top: 4px; }
.profile-tabs { border-top: 1px solid var(--border); display: flex; justify-content: center; margin-bottom: 4px; }
.profile-tab { padding: 16px 0; margin-top: -1px; border-top: 1px solid var(--text); font-size: 12px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; display: flex; gap: 6px; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.grid-cell { position: relative; aspect-ratio: 1 / 1; overflow: hidden; background: #efefef; cursor: pointer; }
.grid-cell img { width: 100%; height: 100%; object-fit: cover; }
.grid-cell .grid-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.4); color: #fff; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .15s; padding: 12px; text-align: center; font-weight: 600; word-break: break-word;
}
.grid-cell:hover .grid-overlay { opacity: 1; }
.private-block { text-align: center; padding: 40px 20px; border-top: 1px solid var(--border); }
.private-block .lock { width: 62px; height: 62px; border: 2px solid var(--text); border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.private-block h3 { margin: 0 0 6px; font-size: 16px; }
.private-block p { margin: 0; color: var(--text-3); }

/* ---------- settings ---------- */
.settings { max-width: 640px; margin: 0 auto; padding: 30px 20px 60px; }
.settings h1 { font-size: 24px; font-weight: 600; margin: 0 0 24px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.session-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.session-row:last-child { border-bottom: 0; }
.session-info { flex: 1; min-width: 0; }
.session-info .dev { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-info .meta { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.session-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.danger-zone { border-color: #f6c7cc; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.switch { position: relative; width: 44px; height: 26px; border-radius: 13px; background: #dbdbdb; border: 0; padding: 0; transition: background .2s; flex-shrink: 0; cursor: pointer; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch.on { background: var(--blue); }
.switch.on::after { left: 21px; }

/* ============ MODALS ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff; border-radius: 12px; max-height: calc(100vh - 32px); overflow: hidden;
  display: flex; flex-direction: column; position: relative; animation: zoom .15s ease;
  width: 100%; max-width: 420px;
}
@keyframes zoom { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-close { position: absolute; top: 12px; right: 12px; color: #fff; background: none; border: 0; padding: 8px; cursor: pointer; z-index: 101; line-height: 0; }
.modal-close svg { width: 24px; height: 24px; }
.modal-head { display: flex; align-items: center; justify-content: center; position: relative; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); font-weight: 600; font-size: 16px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-body.no-pad { padding: 0; }

/* menu-list modal (confirm / post menu) */
.menu-modal { max-width: 400px; }
.menu-modal .menu-title { padding: 24px 24px 8px; text-align: center; font-size: 18px; font-weight: 400; }
.menu-modal .menu-text { padding: 0 24px 16px; text-align: center; color: var(--text-3); }
.menu-item {
  display: block; width: 100%; padding: 14px; border: 0; border-top: 1px solid var(--border-soft);
  background: none; text-align: center; font-size: 14px; color: var(--text);
}
.menu-item:hover { background: var(--bg-soft); }
.menu-item.danger { color: var(--red); font-weight: 700; }
.menu-item.primary { color: var(--blue); font-weight: 700; }

/* list modal (followers) */
.list-modal { max-width: 400px; }
.list-modal .modal-body { max-height: 400px; min-height: 120px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.list-row .avatar { width: 44px; height: 44px; }
.list-row .username { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* post modal */
.post-modal { max-width: 1100px; width: 100%; flex-direction: row; height: calc(100vh - 40px); max-height: 800px; border-radius: 4px; }
.pm-img { flex: 1; min-width: 0; background: #000; display: flex; align-items: center; justify-content: center; }
.pm-img img { width: 100%; height: 100%; object-fit: contain; }
.pm-side { width: 500px; max-width: 45%; display: flex; flex-direction: column; border-left: 1px solid var(--border-soft); }
.pm-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border-soft); }
.pm-head .username { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pm-comments { flex: 1; overflow-y: auto; padding: 16px; }
.pm-footer { border-top: 1px solid var(--border-soft); padding: 6px 16px 12px; }
.pm-actions { display: flex; align-items: center; margin: 0 -8px; }
.pm-likes { font-weight: 600; margin: 2px 0 4px; }
.pm-time { color: var(--text-3); font-size: 12px; text-transform: uppercase; letter-spacing: .2px; }
.comment-form { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--border-soft); padding: 10px 16px; }
.comment-form input { flex: 1; border: 0; outline: none; background: none; padding: 6px 0; font-size: 14px; min-width: 0; }
.comment { display: flex; gap: 12px; margin-bottom: 16px; }
.comment-body { flex: 1; min-width: 0; }
.comment-text { word-break: break-word; white-space: pre-wrap; }
.comment-meta { display: flex; gap: 12px; margin-top: 6px; font-size: 12px; color: var(--text-3); }
.comment-meta button { background: none; border: 0; padding: 0; color: var(--text-3); font-size: 12px; font-weight: 600; cursor: pointer; }
.comment-meta button:hover { color: var(--text); }
.comment-edit-form { display: flex; gap: 6px; margin-top: 4px; }
.comment-edit-form input { flex: 1; min-width: 0; }
.no-comments { text-align: center; color: var(--text-3); padding: 40px 0; }
.no-comments h4 { font-size: 20px; font-weight: 600; color: var(--text); margin: 0 0 6px; }

/* create / edit post modal */
.editor-modal { max-width: 860px; }
.editor-body { display: flex; min-height: 420px; }
.dropzone {
  flex: 1; min-width: 0; background: var(--bg-soft); display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; padding: 20px; text-align: center; cursor: pointer; position: relative;
  border-right: 1px solid var(--border-soft);
}
.dropzone.dragover { background: var(--blue-light); }
.dropzone svg { width: 72px; height: 72px; color: var(--text); }
.dropzone p { margin: 0; font-size: 18px; font-weight: 300; }
.dropzone input[type="file"] { display: none; }
.dropzone .preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.editor-side { width: 340px; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.editor-side .me-line { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.editor-side .field { margin-bottom: 10px; }

/* detail modal (session) */
.detail-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; }

/* ============ AI PAGE ============ */
.ai-page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 40px; }
.ai-header { margin-bottom: 20px; }
.page-title { margin: 10px 0 4px; font-size: clamp(28px, 3vw, 38px); line-height: 1.2; }
.page-subtitle { margin: 0; color: var(--text-2); font-size: 15px; }
.ai-grid { display: grid; grid-template-columns: minmax(260px, 360px) minmax(0, 1fr); gap: 20px; }
.ai-upload-card, .ai-chat-card { min-height: 250px; }
.ai-chat-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ai-chat-heading .card-title { margin-bottom: 12px; }
.ai-mobile-back { display: none; }
.ai-upload-form { display: flex; flex-direction: column; gap: 12px; }
.ai-status {
  margin-top: 16px; padding: 10px 12px; border-radius: 8px; background: var(--bg-soft); border: 1px solid var(--border-soft);
  color: var(--text-2); font-size: 13px; line-height: 18px; word-break: break-word;
}
.ai-status.is-loading { color: var(--blue-dark); background: var(--blue-light); }
.ai-chat { display: flex; flex-direction: column; gap: 12px; min-height: 260px; max-height: 420px; overflow-y: auto; padding: 12px; background: var(--bg-soft); border: 1px solid var(--border-soft); border-radius: 10px; }
.ai-message { max-width: 85%; padding: 10px 12px; border-radius: 12px; line-height: 1.5; word-break: break-word; }
.ai-message-user { margin-left: auto; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.ai-message-bot { margin-right: auto; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.ai-message-error { margin-right: auto; background: #fff5f5; border: 1px solid #f7b4bb; color: var(--red); border-bottom-left-radius: 4px; }
.ai-message-system { max-width: 100%; margin: 0; background: var(--blue-light); color: var(--text); border: 1px solid #cfe5ff; }
.ai-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; opacity: .75; margin-bottom: 4px; }
.ai-answer { white-space: pre-wrap; }
.ai-sources { margin-top: 10px; display: grid; gap: 8px; }
.ai-source { padding: 8px 10px; border-radius: 8px; background: #f8f8f8; border: 1px solid var(--border-soft); }
.ai-source span { display: inline-block; font-size: 11px; font-weight: 700; color: var(--blue-dark); margin-bottom: 4px; }
.ai-source p { margin: 0; color: var(--text-2); font-size: 12px; line-height: 1.5; }
.ai-chat-form { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.ai-chat-actions { display: flex; justify-content: flex-end; }
.ai-chat-form textarea { min-height: 110px; }

/* ============ TOASTS ============ */
.toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #262626; color: #8d6363; padding: 12px 18px; border-radius: 8px; font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2); animation: toastin .2s ease; max-width: calc(100vw - 32px);
}
.toast.error { background: var(--red); }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============ RESPONSIVE ============ */
@media (max-width: 1160px) {
  .right-col { display: none; }
  .home { gap: 0; }
}
@media (max-width: 1000px) {
  .sidebar { width: var(--sidebar-w-narrow); padding: 8px 8px 20px; align-items: center; }
  .sidebar .logo { font-size: 0; width: 48px; height: 48px; padding: 0; margin: 20px 0 16px; display: flex; align-items: center; justify-content: center; }
  .sidebar .logo::before { content: "B"; font-size: 30px; font-family: var(--logo-font); }
  .nav-item { justify-content: center; padding: 12px; width: 48px; }
  .nav-label { display: none; }
  .page { margin-left: var(--sidebar-w-narrow); }
  .post-modal { flex-direction: column; height: auto; max-height: calc(100vh - 32px); max-width: 520px; }
  .pm-img { flex: none; aspect-ratio: 1 / 1; max-height: 50vh; }
  .pm-side { width: 100%; max-width: 100%; border-left: 0; flex: 1; min-height: 0; }
  .pm-comments { max-height: 220px; }
  .editor-body { flex-direction: column; }
  .dropzone { min-height: 280px; border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .editor-side { width: 100%; }
}
@media (max-width: 767px) {
  .profile-head { gap: 20px; margin-bottom: 24px; }
  .profile-avatar-col { width: auto; }
  .profile-avatar-col .avatar, .profile-lock { width: 77px; height: 77px; }
  .profile-lock svg { width: 30px; height: 30px; }
  .profile-stats { gap: 20px; }
  .profile-stats .stat { font-size: 14px; }
  .profile-stats .stat b { display: block; }
  .grid { gap: 2px; }
  .result-head { gap: 14px; }
  .result-head .avatar-77 { width: 56px; height: 56px; }
  .ai-page { padding: 20px 16px 32px; }
  .ai-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .ai-grid > * { min-width: 0; }
  .ai-upload-card, .ai-chat-card { min-height: 0; }
  .ai-chat { min-height: 220px; max-height: 45vh; }
}
@media (max-width: 640px) {
  .sidebar {
    width: 100%; height: calc(56px + env(safe-area-inset-bottom)); top: auto; bottom: 0; left: 0; right: 0; flex-direction: row; justify-content: space-around;
    padding: 0 6px env(safe-area-inset-bottom); border-right: 0; border-top: 1px solid var(--border); align-items: stretch;
  }
  .sidebar .logo { display: none; }
  .nav-list { flex-direction: row; flex: 1; min-width: 0; justify-content: space-around; gap: 0; }
  .nav-bottom { margin-top: 0; flex: 0 0 auto; }
  .nav-item { width: auto; min-width: 0; height: 56px; padding: 0 8px; border-radius: 0; }
  .page { margin-left: 0; padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
  .home { padding: 12px 0 24px; }
  .feed { width: 100%; }
  .post-head { padding: 0 12px 10px; }
  .post-actions, .post-likes, .post-caption, .post-desc, .post .link-muted { margin-left: 12px; margin-right: 12px; }
  .post-actions { margin-left: 4px; }
  .post-img-wrap { border-radius: 0; border-left: 0; border-right: 0; }
  .profile, .search-page, .settings { padding: 16px 12px 32px; }
  .profile-head { gap: 14px; }
  .profile-stats { justify-content: space-between; gap: 8px; }
  .profile-row { gap: 8px; margin-bottom: 14px; }
  .profile-row .btn { padding-right: 10px; padding-left: 10px; }
  .result-card { padding: 14px; }
  .ai-page { padding: 16px 12px 24px; }
  .ai-header, .ai-upload-card, .ai-chat-card { padding: 16px; }
  .ai-page[data-ai-step="upload"] .ai-chat-card,
  .ai-page[data-ai-step="chat"] .ai-upload-card { display: none; }
  .ai-mobile-back { display: inline-flex; }
  .ai-chat { max-height: 50vh; padding: 10px; }
  .ai-chat-form textarea { min-height: 84px; }
  .auth-screen { min-height: 100vh; min-height: 100svh; padding: 24px 16px; }
  .auth-card { padding: 26px 20px 20px; border: 0; background: transparent; }
  .auth-card .logo { margin-bottom: 24px; }
  .auth-switch { border: 0; background: transparent; }
  .settings-row { flex-direction: column; align-items: flex-start; }
  .modal-backdrop { padding: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .modal { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px - env(safe-area-inset-bottom)); }
  .post-modal { width: 100%; height: calc(100vh - 16px); height: calc(100dvh - 16px - env(safe-area-inset-bottom)); max-height: 800px; }
  .pm-img { max-height: 38vh; }
  .pm-comments { max-height: none; }
  .editor-body { min-height: 0; overflow-y: auto; }
  .dropzone { min-height: min(32vh, 220px); }
  .editor-side { flex: 0 0 auto; }
  .toast-root { bottom: calc(68px + env(safe-area-inset-bottom)); }
}
@media (max-width: 380px) {
  .nav-item { padding-right: 5px; padding-left: 5px; }
  .profile-head { gap: 10px; }
  .profile-stats .stat { font-size: 13px; }
  .auth-card { padding-right: 12px; padding-left: 12px; }
  .search-page { padding-right: 8px; padding-left: 8px; }
  .result-card { padding: 12px; }
}
