:root {
  --bg: #eef3f7;
  --card: #fff;
  --ink: #152033;
  --muted: #64748b;
  --line: #d8e0ea;
  --blue: #2563eb;
  --blue-dark: #1746b8;
  --green: #14845a;
  --red: #b42318;
  --yellow: #9a6700;
  --amber-soft: #fff7db;
  --green-soft: #e9f8ef;
  --coral-soft: #fff1ed;
  --shadow: 0 16px 40px rgba(20, 34, 56, .10);
  --shadow-soft: 0 8px 20px rgba(20, 34, 56, .07);
  --radius: 10px;
  --max: 1180px;
}
* { box-sizing: border-box; }
body { margin: 0; background: linear-gradient(180deg, #f8fbfd 0, var(--bg) 360px, #f5f7fa 100%); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.45; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }

.site-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; justify-content: space-between; min-height: 72px; padding: 12px max(18px, calc((100vw - var(--max)) / 2)); background: rgba(255,255,255,.88); border-bottom: 1px solid rgba(216,224,234,.9); backdrop-filter: blur(14px); box-shadow: 0 1px 0 rgba(255,255,255,.8) inset; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; min-width: max-content; }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; color: white; background: linear-gradient(135deg, var(--blue), #14a06f); font-weight: 900; box-shadow: 0 8px 18px rgba(37,99,235,.24); }
.brand small { display: block; color: var(--muted); font-weight: 600; font-size: .76rem; margin-top: 1px; }
.top-nav { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.top-nav a { padding: 8px 12px; border-radius: 999px; color: #475569; font-weight: 750; transition: .16s ease; }
.top-nav a.active, .top-nav a:hover { background: #e8f1ff; color: var(--blue-dark); box-shadow: 0 1px 0 rgba(37,99,235,.08) inset; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.user-menu, .logout-btn { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 8px 12px; font-weight: 750; }
.user-dropdown { position: absolute; right: max(18px, calc((100vw - var(--max)) / 2)); top: 64px; display: none; min-width: 190px; padding: 8px; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.user-dropdown a, .user-dropdown button { display: block; width: 100%; text-align: left; padding: 9px 10px; border: 0; background: white; border-radius: 10px; color: var(--ink); }
.user-dropdown a:hover, .user-dropdown button:hover { background: #f1f5f9; }

main { width: min(var(--max), calc(100% - 28px)); margin: 0 auto; }
.primary-action, .secondary-action, .filter-button, .toggle-btn, .icon-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 9px 14px; border-radius: 999px; border: 1px solid transparent; font-weight: 850; transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease; }
.primary-action { background: linear-gradient(135deg, var(--blue), #1d7d63); color: white; box-shadow: 0 10px 22px rgba(37,99,235,.22); }
.primary-action:hover { background: linear-gradient(135deg, var(--blue-dark), #12664f); transform: translateY(-1px); }
.secondary-action, .filter-button, .toggle-btn, .icon-button { background: white; border-color: var(--line); color: var(--ink); box-shadow: 0 1px 0 rgba(255,255,255,.9) inset; }
.secondary-action:hover, .filter-button:hover, .toggle-btn:hover, .icon-button:hover { background: #f8fafc; border-color: #c7d1dd; transform: translateY(-1px); }
.primary-action:disabled, .secondary-action:disabled { opacity: .58; cursor: not-allowed; transform: none; }
.large { min-height: 46px; padding-inline: 18px; }
.compact { min-height: 34px; padding: 7px 11px; font-size: .9rem; }
.full-width { width: 100%; }

.eyebrow { color: #176b53; font-weight: 900; letter-spacing: .08em; font-size: .78rem; text-transform: uppercase; margin: 0 0 10px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 0 16px; }
.section-heading h2 { margin: 0 0 4px; font-size: clamp(1.35rem, 2vw, 1.9rem); letter-spacing: -.02em; }
.section-heading p { margin: 0; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.home-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 430px); gap: 34px; align-items: center; padding: 64px 0 42px; }
.home-hero h1, .market-hero h1, .auth-shell h1, .messages-hero h1 { margin: 0 0 14px; font-size: clamp(2.2rem, 5vw, 4.3rem); line-height: 1.01; letter-spacing: -.04em; max-width: 900px; }
.home-hero p, .market-hero p, .auth-shell p, .messages-hero p { margin: 0; color: var(--muted); font-size: 1.05rem; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 26px; }
.hero-stats span { display: grid; gap: 1px; min-width: 116px; padding: 12px 14px; background: rgba(255,255,255,.72); border: 1px solid rgba(216,224,234,.9); border-radius: 10px; box-shadow: var(--shadow-soft); }
.hero-stats strong { font-size: 1rem; }
.hero-stats small { color: var(--muted); font-weight: 700; }
.home-preview-card { display: grid; gap: 12px; padding: 18px; border: 1px solid rgba(216,224,234,.95); border-radius: 16px; background: linear-gradient(180deg, #ffffff 0, #f9fbfd 100%); box-shadow: var(--shadow); }
.preview-header, .preview-listing { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.preview-header { color: var(--muted); font-size: .86rem; font-weight: 850; padding-bottom: 4px; }
.preview-listing { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.preview-listing.primary { background: var(--green-soft); border-color: #bee8cd; }
.preview-listing div { min-width: 0; margin-right: auto; }
.preview-listing strong, .preview-listing p { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-listing p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.preview-listing em { color: #176b53; font-style: normal; font-weight: 900; white-space: nowrap; }
.preview-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; background: var(--ink); color: white; font-weight: 950; font-size: .78rem; }
.preview-dot { width: 12px; height: 42px; border-radius: 999px; background: var(--blue); flex: 0 0 auto; }
.preview-dot.textbook { background: #b7791f; }
.preview-dot.request { background: #db6b50; }
.quiet-list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.quiet-list li, .workflow-grid article { background: rgba(255,255,255,.78); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow-soft); }
.workflow, .rules-band { padding: 26px 0 48px; }
.workflow-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.workflow-grid article strong { display: block; margin-bottom: 6px; font-size: 1.02rem; }
.workflow-grid article p { margin: 0; color: var(--muted); }
.rules-band { display: grid; grid-template-columns: .75fr 1fr; gap: 18px; align-items: start; }
.rules-band ul { margin: 0; padding-left: 20px; color: var(--muted); }

.market-shell { padding: 28px 0 58px; }
.market-hero { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; margin-bottom: 18px; }
.market-hero-copy, .hero-search-card, .market-controls, .auth-card, .messages-sidebar, .messages-panel { background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-soft); }
.market-hero-copy, .hero-search-card, .auth-card { padding: 22px; }
.market-hero-copy { background: linear-gradient(135deg, #ffffff 0, #f2f8ff 100%); }
.hero-search, .market-search, .messages-search, input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none; background: white; color: var(--ink); transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
.hero-search, .market-search, .messages-search { border-radius: 999px; min-height: 44px; background: #f8fafc; }
input:focus, select:focus, textarea:focus, .hero-search:focus, .market-search:focus, .messages-search:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(24,119,242,.12); }
.market-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; margin-bottom: 18px; }
.market-context { display: grid; gap: 2px; min-width: 180px; margin-right: auto; }
.market-context strong { font-size: 1rem; }
.market-context span { color: var(--muted); font-size: .88rem; font-weight: 700; }
.market-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: flex-end; }
.segmented-control { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); background: #f8fafc; border-radius: 999px; }
.segmented-control button { border: 0; background: transparent; border-radius: 999px; padding: 8px 12px; font-weight: 850; color: var(--muted); }
.segmented-control button.active { background: white; color: var(--ink); box-shadow: 0 1px 5px rgba(21,32,43,.08); }
.school-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.school-card { display: grid; grid-template-columns: 112px minmax(0,1fr); align-items: center; gap: 14px; width: 100%; min-height: 156px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: white; text-align: left; box-shadow: var(--shadow-soft); transition: .16s ease; }
.school-card:hover { transform: translateY(-2px); border-color: #bfd7ff; box-shadow: var(--shadow); }
.school-art { display: grid; place-items: center; aspect-ratio: 1; border-radius: 10px; background: #f8fafc; border: 1px solid var(--line); overflow: hidden; }
.school-art img { width: 100%; height: 100%; object-fit: cover; }
.school-copy, .product-copy { display: grid; gap: 4px; min-width: 0; }
.school-copy strong, .product-copy strong { color: var(--ink); font-size: 1rem; line-height: 1.25; }
.school-copy span, .product-copy span { color: var(--muted); font-weight: 750; }
.school-copy em, .product-copy em { color: #176b53; font-style: normal; font-size: .86rem; font-weight: 900; }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 28px 20px; padding-top: 4px; }
.product-card { display: grid; gap: 12px; width: 100%; border: 0; background: transparent; text-align: center; padding: 0; transition: transform .16s ease; }
.product-card:hover { transform: translateY(-3px); }
.product-image { width: 100%; aspect-ratio: 1.12; object-fit: contain; border-radius: 10px; background: #f8fafc; }
.product-copy { justify-items: center; padding: 0 8px; }
.product-copy strong { min-height: 40px; }
.listing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.listing-card { overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 18px rgba(21,32,43,.06); transition: .16s ease; cursor: pointer; }
.listing-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: #bfd7ff; }
.listing-image { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: linear-gradient(135deg, #e2e8f0, #f8fafc); }
.listing-content { padding: 14px; display: grid; gap: 8px; }
.listing-content h3 { margin: 0; font-size: 1rem; letter-spacing: -.02em; }
.listing-content p { margin: 0; color: var(--muted); font-size: .92rem; }
.meta-row { display: flex; flex-wrap: wrap; gap: 7px; }
.badge, .category-badge, .intent-badge, .meta-pill { display: inline-flex; width: fit-content; border: 1px solid var(--line); background: #f8fafc; color: #475569; border-radius: 999px; padding: 4px 8px; font-size: .78rem; font-weight: 850; }
.intent-badge { background: #e8f1ff; color: var(--blue-dark); border-color: #bfd7ff; }
.price-chip { display: inline-flex; width: fit-content; background: #12233d; color: white; border-radius: 999px; padding: 5px 9px; font-weight: 900; }

.dialog, dialog { border: 0; border-radius: 14px; padding: 0; width: min(740px, calc(100% - 24px)); background: white; box-shadow: 0 24px 70px rgba(15,23,42,.25); }
dialog::backdrop { background: rgba(15,23,42,.45); }
.dialog-header, .detail-header, .messages-sidebar-header, .active-thread-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.dialog-header h2, .detail-header h2 { margin: 0; }
.listing-form, .auth-form, .message-form, .messages-page-form { padding: 18px; }
.form-grid, .filter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-group { display: grid; gap: 6px; }
.form-grid .wide, .field-wide, textarea { grid-column: 1 / -1; }
label { font-weight: 850; color: #475569; font-size: .88rem; }
textarea { min-height: 110px; resize: vertical; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.form-message { margin: 12px 0 0; white-space: pre-line; font-weight: 700; }
.form-message.error { color: var(--red); }
.form-message.success { color: var(--green); }
.field-hint, .small-copy { color: var(--muted); font-size: .88rem; }

.auth-shell { display: grid; grid-template-columns: minmax(0,.85fr) minmax(340px,460px); gap: 24px; padding: 56px 0 70px; align-items: start; }
.auth-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; background: #f8fafc; border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-bottom: 16px; }
.auth-toggle .toggle-btn { border: 0; background: transparent; }
.auth-toggle .toggle-btn.active { background: white; color: var(--blue-dark); box-shadow: 0 1px 5px rgba(21,32,43,.08); }
.auth-form { display: none; }
.auth-form.active { display: grid; gap: 12px; padding: 0; }

.detail-content { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(0,1fr); gap: 18px; padding: 18px; }
.detail-gallery { overflow: hidden; border-radius: 12px; border: 1px solid var(--line); min-height: 280px; background: #f8fafc; }
.detail-gallery img { width: 100%; height: 100%; object-fit: cover; }
.detail-tags, .detail-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.detail-tags span { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; color: #475569; background: #f8fafc; font-weight: 750; font-size: .86rem; }

.messages-hero { padding: 34px 0 10px; }
.messages-shell { display: grid; grid-template-columns: 330px minmax(0,1fr); gap: 16px; padding: 16px 0 56px; }
.messages-sidebar, .messages-panel { min-height: 540px; overflow: hidden; }
.messages-panel { display: flex; flex-direction: column; }
.thread-list, .messages-page-list { display: grid; gap: 8px; padding: 12px; }
.thread-item { position: relative; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 10px; align-items: center; border: 1px solid var(--line); background: white; text-align: left; border-radius: 14px; padding: 10px 42px 10px 10px; width: 100%; }
.thread-item.active, .thread-item:hover { border-color: #bfd7ff; background: #e8f1ff; }
.thread-thumb { width: 56px; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #f8fafc; }
.thread-copy { display: grid; gap: 3px; min-width: 0; }
.thread-topline { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.thread-topline time, .message-bubble time { color: var(--muted); font-size: .76rem; font-weight: 700; white-space: nowrap; }
.thread-title, .thread-preview { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-preview { color: #334155; font-size: .9rem; }
.message-count { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; min-width: 24px; height: 24px; border-radius: 999px; background: #eff6ff; color: var(--blue-dark); border: 1px solid #bfd7ff; font-size: .76rem; font-weight: 900; }
.active-thread-header { min-height: 86px; background: linear-gradient(180deg, #ffffff 0, #f8fbfd 100%); }
.active-item-preview { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 12px; align-items: center; min-width: 0; }
.active-item-preview img { width: 58px; aspect-ratio: 1; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); background: #f8fafc; }
.active-item-preview strong, #emptyThreadHeading strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; }
.active-item-preview p, #emptyThreadHeading p { margin: 2px 0 0; }
.message-list { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 18px; max-height: 430px; overflow: auto; background: linear-gradient(180deg, #f8fafc 0, #f1f6fb 100%); }
.message-bubble { max-width: 78%; border: 1px solid var(--line); background: white; border-radius: 16px; padding: 10px 12px; overflow-wrap: anywhere; }
.message-bubble strong { display: block; font-size: .82rem; color: #475569; }
.message-bubble p { margin: 4px 0 5px; white-space: pre-wrap; }
.message-bubble.mine { margin-left: auto; background: var(--blue); color: white; border-color: var(--blue); }
.message-bubble.mine strong { color: rgba(255,255,255,.9); }
.message-bubble.mine time { color: rgba(255,255,255,.78); }
.message-form, .messages-page-form { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); background: white; }
.message-form input, .messages-page-form input { border-radius: 999px; }
.messages-page-form textarea { min-height: 48px; max-height: 130px; resize: vertical; border-radius: 16px; background: #f8fafc; }
.messages-page-form button { align-self: flex-end; min-width: 86px; }
.compact-empty { min-height: 150px; padding: 18px; }

.empty-state { display: grid; place-items: center; text-align: center; min-height: 210px; padding: 30px; color: var(--muted); background: rgba(255,255,255,.88); border: 1px dashed #c8d2df; border-radius: var(--radius); }
.empty-state h2, .empty-state h3 { color: var(--ink); margin: 0 0 8px; }
.empty-state p { margin: 0; }

@media (max-width: 880px) {
  .site-header { flex-wrap: wrap; align-items: flex-start; }
  .top-nav { order: 3; width: 100%; overflow-x: auto; }
  .home-hero, .market-hero, .auth-shell, .messages-shell, .detail-content, .rules-band { grid-template-columns: 1fr; }
  .workflow-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  main { width: min(100% - 22px, var(--max)); }
  .home-hero { padding-top: 34px; }
  .home-hero h1, .market-hero h1, .auth-shell h1, .messages-hero h1, .account-shell h1 { font-size: 2.35rem; }
  .hero-stats span { flex: 1 1 120px; }
  .form-grid, .filter-grid, .listing-grid { grid-template-columns: 1fr; }
  .market-controls, .market-actions, .form-actions, .message-form, .messages-page-form { flex-direction: column; align-items: stretch; }
  .primary-action, .secondary-action, .filter-button { width: 100%; }
  .header-actions .primary-action, .header-actions .secondary-action, .header-actions .user-menu { width: auto; }
  .message-bubble { max-width: 94%; }
  .messages-page-form button { align-self: stretch; }
  .active-thread-header { align-items: flex-start; flex-direction: column; }
  .thread-item { grid-template-columns: 48px minmax(0, 1fr); }
  .thread-thumb { width: 48px; }
}

/* QOL additions */
.danger-action { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 9px 14px; border-radius: 999px; border: 1px solid #fecaca; background: #fff1f2; color: #b42318; font-weight: 900; }
.danger-action:hover { background: #ffe4e6; border-color: #fda4af; }
.password-toggle { display: inline-flex; align-items: center; gap: 8px; margin-top: 2px; color: var(--muted); font-size: .9rem; font-weight: 700; }
.password-toggle input { width: auto; box-shadow: none !important; }
.account-shell { display: grid; grid-template-columns: minmax(0,.75fr) minmax(340px, 620px); gap: 24px; padding: 56px 0 70px; align-items: start; }
.account-shell h1 { margin: 0 0 12px; font-size: clamp(2.2rem, 5vw, 4rem); line-height: 1.01; letter-spacing: -.04em; }
.account-card { background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.account-card .form-actions { margin-top: 18px; }
.user-dropdown a[href="account.html"] { font-weight: 800; }
@media (max-width: 880px) { .account-shell { grid-template-columns: 1fr; } }
