/* BIM Portal — single stylesheet for every portal page (light + dark via prefers-color-scheme). */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #1c2430;
  --muted: #5f6b7a;
  --line: #e2e6eb;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fd;
  --good: #1f8a4c;
  --good-soft: #e6f5ec;
  --warn: #a8670a;
  --warn-soft: #fdf3e2;
  --bad: #c2382f;
  --bad-soft: #fcebea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1a2028;
    --surface-2: #222a34;
    --text: #e6eaef;
    --muted: #97a3b2;
    --line: #2d3641;
    --accent: #6ea0ff;
    --accent-text: #0d1420;
    --accent-soft: #1d2c46;
    --good: #5cc98b;
    --good-soft: #17301f;
    --warn: #e6b45a;
    --warn-soft: #33281a;
    --bad: #f07b72;
    --bad-soft: #3a1d1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; }
p { margin: 0 0 .8em; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Header / footer ─────────────────────────────────────────── */
.site-header { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header-inner { max-width: 1160px; margin: 0 auto; padding: 0 16px; min-height: 60px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.main-nav { display: flex; gap: 4px; flex: 1; }
.main-nav a { color: var(--muted); padding: 8px 12px; border-radius: 8px; font-weight: 500; }
.main-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.main-nav a.active { color: var(--accent); background: var(--accent-soft); }
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.account-menu { position: relative; }
.account-menu > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid var(--line); }
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu > summary .name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.account-menu .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, .15); padding: 6px; display: flex; flex-direction: column; }
.account-menu .menu a, .account-menu .menu button { text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.account-menu .menu a:hover, .account-menu .menu button:hover { background: var(--surface-2); text-decoration: none; }
.account-menu .menu .sep { height: 1px; background: var(--line); margin: 4px 0; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.site-footer { margin-top: auto; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .88rem; }
.site-footer-inner { max-width: 1160px; margin: 0 auto; padding: 18px 16px; display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; }
.site-footer a { color: var(--muted); }

/* ── Layout ──────────────────────────────────────────────────── */
.page { width: 100%; max-width: 1160px; margin: 0 auto; padding: 24px 16px 40px; flex: 1; }
.page.narrow { max-width: 760px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.center { text-align: center; }
.hidden { display: none !important; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-link { display: flex; flex-direction: column; color: var(--text); padding: 0; overflow: hidden; }
.card-link:hover { text-decoration: none; border-color: var(--accent); }
.card-media { aspect-ratio: 16 / 9; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-body h3 { margin: 0; }
.card-body p { margin: 0; color: var(--muted); font-size: .92rem; }
.card-foot { margin-top: auto; padding-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }

.hero { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 24px; align-items: center; margin-bottom: 28px; }
.hero .kicker { color: var(--accent); font-weight: 600; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.hero h1 { font-size: 2rem; margin: 6px 0 10px; }
.hero p { color: var(--muted); font-size: 1.02rem; }
.hero img { border-radius: 10px; max-height: 260px; object-fit: cover; width: 100%; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 28px 0 12px; }
.section-title h2 { margin: 0; }

/* ── Controls ────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: .86rem; }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; min-height: 0; }
.btn-link:hover { background: none; text-decoration: underline; }

.form { display: grid; gap: 14px; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field > label, .field > .label { font-size: .86rem; font-weight: 600; color: var(--text); }
.field small { color: var(--muted); font-size: .8rem; }
.input, .field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea, select.input {
  width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit;
}
.field textarea { min-height: 110px; resize: vertical; }
.field textarea.tall { min-height: 240px; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .92rem; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.notice { padding: 12px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--text); border: 1px solid transparent; }
.notice.good { background: var(--good-soft); }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.toast-wrap { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgba(0, 0, 0, .2); font-size: .92rem; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td, .table tr.selected td { background: var(--accent-soft); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; font: inherit; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

details.disclosure { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
details.disclosure > summary { cursor: pointer; padding: 12px 16px; font-weight: 600; }
details.disclosure > div { padding: 0 16px 16px; }

/* ── Markdown content ────────────────────────────────────────── */
.md { overflow-wrap: anywhere; }
.md h2, .md h3, .md h4 { margin: 1.2em 0 .5em; }
.md img { border-radius: 8px; display: block; margin: 12px 0; }
.md ul, .md ol { padding-left: 1.4em; margin: 0 0 .8em; }

/* ── Product / instruction pages ─────────────────────────────── */
.product-head { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 24px; align-items: start; margin-bottom: 24px; }
.product-head .cover { border-radius: 12px; background: var(--surface-2); aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted); }
.product-head .cover img { width: 100%; height: 100%; object-fit: cover; }
.gallery { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.gallery a { display: block; border-radius: 8px; overflow: hidden; aspect-ratio: 4 / 3; background: var(--surface-2); }
.gallery img { width: 100%; height: 100%; object-fit: cover; }
.video { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: #000; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.article-cover { width: 100%; max-height: 420px; object-fit: cover; border-radius: 12px; margin-bottom: 18px; }
.download-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; border-radius: var(--radius); background: var(--accent-soft); margin-top: 20px; }

.auth-box { max-width: 420px; margin: 24px auto; }

/* ── Admin ───────────────────────────────────────────────────── */
.admin { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.admin-nav { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 2px; }
.admin-nav a { color: var(--text); padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.admin-nav a:hover { background: var(--surface-2); text-decoration: none; }
.admin-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.split { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 16px; align-items: start; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-item { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; text-align: left; font: inherit; color: var(--text); width: 100%; }
.list-item:hover { border-color: var(--accent); }
.list-item.active { border-color: var(--accent); background: var(--accent-soft); }
.list-item .meta { font-size: .82rem; color: var(--muted); }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.message { border-left: 3px solid var(--line); padding: 6px 10px; margin: 6px 0; background: var(--surface-2); border-radius: 0 6px 6px 0; }
.message.staff { border-left-color: var(--accent); }

@media (max-width: 860px) {
  .admin, .split, .product-head, .hero, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .admin-nav { position: static; flex-direction: row; overflow-x: auto; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
  .admin-nav a { white-space: nowrap; }
  .hero { padding: 22px; }
}
@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .site-header-inner { gap: 6px 12px; padding-top: 8px; padding-bottom: 8px; }
  .main-nav { order: 3; flex-basis: 100%; }
  .main-nav a { padding: 6px 10px; }
  .account-menu > summary .name { display: none; }
  .page { padding: 16px 12px 32px; }
  .card { padding: 14px; }
  .hero h1 { font-size: 1.5rem; }
  h1 { font-size: 1.4rem; }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dd { margin-bottom: 6px; }
  .table th, .table td { padding: 8px; }
}
