/* =========================================================
   Empirically — one stylesheet for every page
   ========================================================= */
:root {
  --blue: #1a5ca8;
  --blue-dark: #0f3f7a;
  --blue-soft: #e6f0fb;
  --bg: #f1f6fc;
  --card: #ffffff;
  --border: #cfe0f3;
  --text: #1d2b3a;
  --muted: #5b6b7c;
  --danger: #c0392b;
  --success: #1e8449;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 63, 122, .04), 0 4px 16px rgba(15, 63, 122, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: #fff; border-bottom: 2px solid var(--blue);
  height: 64px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}
.icon-btn {
  background: none; border: 0; cursor: pointer; padding: 8px; border-radius: 10px;
  color: var(--blue); display: inline-flex; align-items: center; justify-content: center; position: relative;
}
.icon-btn:hover { background: var(--blue-soft); }
.logo {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--blue-dark); font-weight: 700; font-size: 22px; letter-spacing: -.01em;
}
.logo:hover { text-decoration: none; }
.header-right { display: flex; align-items: center; gap: 8px; }
.badge {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--blue); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
  flex-shrink: 0; text-transform: uppercase;
}
.avatar.sm { width: 26px; height: 26px; font-size: 10px; background: var(--blue-soft); color: var(--blue-dark); }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; }
.avatar.md { width: 64px; height: 64px; font-size: 22px; }

/* ---------- drawer (burger menu) ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 30, 50, .35); z-index: 90; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 290px; max-width: 85vw; background: #fff; z-index: 100;
  transform: translateX(-100%); transition: transform .2s ease; display: flex; flex-direction: column;
  visibility: hidden;
}
.drawer.open { transform: translateX(0); visibility: visible; box-shadow: 4px 0 24px rgba(0,0,0,.08); }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawer nav { padding: 10px; overflow-y: auto; flex: 1; }
.drawer nav a, .drawer nav button {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px;
  color: var(--text); font-size: 15px; width: 100%; text-align: left; background: none; border: 0; cursor: pointer; font-family: inherit;
}
.drawer nav a:hover, .drawer nav button:hover { background: var(--blue-soft); text-decoration: none; }
.drawer nav a.active { background: var(--blue-soft); color: var(--blue-dark); font-weight: 600; }
.drawer .nav-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 6px; font-weight: 600; }
.soon { margin-left: auto; font-size: 11px; background: var(--blue-soft); color: var(--blue); padding: 2px 8px; border-radius: 10px; }

/* ---------- layout ---------- */
.container { max-width: 1140px; margin: 0 auto; padding: 28px 20px 80px; }
.container.narrow { max-width: 760px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 26px 28px; margin-bottom: 22px; box-shadow: var(--shadow);
}
.panel h2, .panel h3 { color: var(--blue-dark); margin: 0 0 14px; font-size: 18px; }
h1.page-title { color: var(--blue-dark); font-size: 28px; margin: 0 0 6px; letter-spacing: -.01em; }
.page-sub { color: var(--muted); margin: 0 0 24px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 34px 0 14px; }
.section-head:first-child { margin-top: 0; }
.section-head h2 { display: flex; align-items: center; gap: 10px; margin: 0; color: var(--blue); font-size: 20px; }
.section-label {
  display: flex; align-items: center; gap: 14px; margin: 30px 0 14px;
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.see-all { font-weight: 600; font-size: 14px; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border-radius: 10px; font-weight: 600; font-size: 15px; cursor: pointer;
  border: 1.5px solid var(--blue); background: var(--blue); color: #fff; font-family: inherit;
  transition: background .15s, border-color .15s, color .15s; white-space: nowrap;
}
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); text-decoration: none; }
.btn.outline { background: #fff; color: var(--blue); border-color: var(--border); }
.btn.outline:hover { border-color: var(--blue); background: var(--blue-soft); }
.btn.outline.on { background: var(--blue-soft); border-color: var(--blue); color: var(--blue-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f0c8c3; }
.btn.danger:hover { background: #fdf0ee; border-color: var(--danger); }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label.field { display: block; margin-bottom: 16px; }
label.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; color: var(--blue-dark); }
label.field small { color: var(--muted); font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
textarea { resize: vertical; min-height: 100px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.error-text { color: var(--danger); font-size: 14px; margin: 8px 0; }
.ok-text { color: var(--success); font-size: 14px; margin: 8px 0; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 26px; text-align: center; cursor: pointer;
  color: var(--muted); background: #fafcff;
}
.dropzone:hover, .dropzone.drag { border-color: var(--blue); background: var(--blue-soft); }
.dropzone strong { color: var(--blue-dark); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 16px; border-radius: 999px; border: 1.5px solid var(--border); background: #fff;
  color: var(--text); cursor: pointer; font-size: 14px; font-family: inherit;
}
.chip:hover { border-color: var(--blue); }
.chip.on { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); font-weight: 600; }
.tag { display: inline-block; padding: 3px 12px; border-radius: 999px; border: 1px solid var(--border); font-size: 13px; color: var(--muted); background: #fff; }
.field-pill {
  display: inline-block; padding: 3px 10px; border-radius: 8px; background: var(--blue-soft); color: var(--blue-dark);
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.status-pill { display: inline-block; padding: 2px 9px; border-radius: 8px; font-size: 11px; font-weight: 700; background: #fff4dc; color: #8a5a00; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; }
.cards.row { grid-auto-flow: column; grid-auto-columns: minmax(270px, 320px); grid-template-columns: none; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x mandatory; }
.cards.row .card { scroll-snap-align: start; }
.cards.row:has(> .empty), .cards.row:has(> .loading) { display: block; }
.card {
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px 22px;
  display: flex; flex-direction: column; gap: 10px; cursor: pointer; transition: border-color .15s, transform .15s, box-shadow .15s;
  box-shadow: var(--shadow); min-width: 0;
}
.card:hover { border-color: var(--blue); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15, 63, 122, .1); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h3 { margin: 0; font-size: 16.5px; line-height: 1.35; color: var(--blue-dark); overflow-wrap: anywhere; }
.card p { margin: 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.byline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.byline a { color: var(--muted); }
.stats { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: auto; padding-top: 4px; flex-wrap: wrap; }
.stats span { display: inline-flex; align-items: center; gap: 5px; }
.meta-box { display: flex; gap: 18px; background: var(--bg); border-radius: 10px; padding: 10px 14px; font-size: 13px; }
.meta-box div small { display: block; color: var(--muted); }
.meta-box div strong { color: var(--blue-dark); }

.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-radius: 10px; background: var(--bg); margin-bottom: 8px; cursor: pointer;
}
.list-item:hover { background: var(--blue-soft); }
.list-item .t { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.list-item .s { font-size: 13px; color: var(--muted); }

/* ---------- empty state ---------- */
.empty {
  border: 2px dashed var(--border); border-radius: var(--radius); background: rgba(255,255,255,.6);
  padding: 44px 24px; text-align: center; grid-column: 1 / -1;
}
.empty .emoji { font-size: 42px; line-height: 1; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--blue-dark); font-size: 18px; }
.empty p { margin: 0 0 16px; color: var(--muted); }
.empty.compact { padding: 24px 14px; border-width: 0; background: none; }
.empty.compact .emoji { font-size: 30px; }
.empty.compact h3 { font-size: 15px; font-weight: 500; color: var(--muted); }

.loading { text-align: center; color: var(--muted); padding: 30px; grid-column: 1 / -1; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- detail pages ---------- */
.detail-head h1 { color: var(--blue-dark); font-size: 30px; margin: 12px 0 14px; line-height: 1.25; overflow-wrap: anywhere; }
.author-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.author-row .name { font-weight: 700; color: var(--blue-dark); }
.author-row .sub { font-size: 13px; color: var(--muted); }
.action-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; border-top: 1px solid var(--border); padding-top: 18px; margin-top: 18px; }
.action-bar .spacer { flex: 1; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--blue-soft); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv strong { text-align: right; overflow-wrap: anywhere; }
.pdf-frame { width: 100%; height: 78vh; min-height: 480px; border: 1px solid var(--border); border-radius: 10px; background: #f6f8fb; }
.file-row { display: flex; align-items: center; gap: 14px; }
.file-row .fi { font-size: 32px; }
.file-row .fn { font-weight: 600; overflow-wrap: anywhere; }
.file-row .fs { font-size: 13px; color: var(--muted); }
.cite-box { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--bg); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; overflow-wrap: anywhere; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; }

.comment { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--blue-soft); }
.comment .c-head { font-size: 13px; color: var(--muted); }
.comment .c-head strong { color: var(--blue-dark); }
.comment .c-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.comment-form { display: flex; gap: 12px; align-items: flex-start; }
.comment-form .grow { flex: 1; }

/* survey */
.question { border: 1.5px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; background: #fff; }
.question .q-title { font-weight: 600; margin-bottom: 10px; }
.question label.opt { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.scale { display: flex; gap: 8px; flex-wrap: wrap; }
.scale label { border: 1.5px solid var(--border); border-radius: 10px; padding: 8px 14px; cursor: pointer; }
.scale input { display: none; }
.scale input:checked + span { color: var(--blue-dark); font-weight: 700; }
.scale label:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }
.bar { height: 10px; border-radius: 6px; background: var(--blue-soft); overflow: hidden; margin: 4px 0 10px; }
.bar > i { display: block; height: 100%; background: var(--blue); }
.q-builder { border: 1.5px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: #fafcff; }
.q-builder .q-top { display: grid; grid-template-columns: 1fr 190px auto; gap: 10px; margin-bottom: 10px; }
@media (max-width: 600px) { .q-builder .q-top { grid-template-columns: 1fr; } }

/* my page */
.profile-card { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.profile-card .info { flex: 1; min-width: 200px; }
.profile-card h1 { margin: 0; color: var(--blue-dark); font-size: 26px; }
.profile-card .handle { color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 26px; }
.stat { background: #fff; border: 1.5px solid var(--border); border-radius: 14px; padding: 18px; text-align: center; }
.stat b { display: block; font-size: 28px; color: var(--blue-dark); line-height: 1.1; }
.stat small { color: var(--muted); }
.widgets { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }
.widget { background: #fff; border: 1.5px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; }
.widget-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.widget-head h3 { margin: 0; color: var(--blue-dark); font-size: 17px; }
.widget .btn { margin-top: auto; }
.widget .list { margin-bottom: 12px; }

/* notifications */
.notif { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; cursor: pointer; }
.notif:hover { background: var(--bg); }
.notif.unread { background: var(--blue-soft); }
.notif .n-time { font-size: 12px; color: var(--muted); }
.notif .n-text { overflow-wrap: anywhere; }
.notif .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); margin-top: 8px; flex-shrink: 0; }

/* auth */
.auth-wrap { min-height: calc(100vh - 64px); display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.auth-card { width: 100%; max-width: 440px; }
.tabs { display: flex; background: var(--bg); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.tabs button { flex: 1; padding: 10px; border: 0; background: none; border-radius: 9px; font-weight: 600; cursor: pointer; color: var(--muted); font-family: inherit; font-size: 15px; }
.tabs button.on { background: #fff; color: var(--blue-dark); box-shadow: var(--shadow); }

/* toolbar on browse pages */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar .grow { flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }

/* faq */
details.faq { background: #fff; border: 1.5px solid var(--border); border-radius: 12px; padding: 14px 18px; margin-bottom: 10px; }
details.faq summary { cursor: pointer; font-weight: 600; color: var(--blue-dark); }
details.faq p { margin: 10px 0 0; color: var(--text); }

/* toast + banner */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--blue-dark); color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 200;
  transition: all .2s; pointer-events: none; max-width: 90vw; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }
.setup-banner { background: #fff4dc; color: #6b4600; border-bottom: 1px solid #f0d9a4; padding: 12px 20px; text-align: center; font-size: 14px; }
.setup-banner code { background: #fff; padding: 1px 6px; border-radius: 4px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 30, 50, .4); z-index: 150; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); padding: 24px; width: 100%; max-width: 520px; max-height: 85vh; overflow-y: auto; }
.modal h3 { margin-top: 0; color: var(--blue-dark); }
.pick { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1.5px solid var(--border); border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.pick:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }

.muted { color: var(--muted); }
.mt0 { margin-top: 0; }
.hero {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue)); color: #fff; border-radius: var(--radius);
  padding: 28px 32px; margin-bottom: 30px; display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
}
.hero h1 { margin: 0 0 6px; font-size: 26px; }
.hero p { margin: 0; opacity: .9; }
.hero .btn { background: #fff; color: var(--blue-dark); border-color: #fff; }
.hero .btn.ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.6); }
