:root {
  --paper: #f6f5f1;
  --paper-2: #ffffff;
  --ink: #15201d;
  --ink-soft: #4a5860;
  --steel: #2a506e;
  --steel-soft: #6e8aa0;
  --signal: #1f5c44;
  --signal-dark: #143f2e;
  --signal-soft: #dde9e2;
  --grid: #e8e6df;
  --line: #dddbd2;
  --danger: #a33a34;
  --warning: #a66a14;
  --white: #fff;
  --shadow: 0 20px 55px -38px rgba(25, 35, 43, .55);
  --maxw: 1120px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .48;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, #000, transparent 72%);
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-family: "Noto Serif TC", serif; line-height: 1.25; }
p { margin: 0; }
.mono { font-family: "IBM Plex Mono", monospace; }
.wrap { width: min(calc(100% - 40px), var(--maxw)); margin: 0 auto; }
.muted { color: var(--ink-soft); }
.hidden { display: none !important; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid rgba(203, 212, 205, .86);
  background: rgba(244, 246, 243, .9);
  backdrop-filter: blur(12px) saturate(140%);
}
.header-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.brand { font: 700 1.06rem/1.25 "Noto Serif TC", serif; letter-spacing: .15em; }
.brand small { display: block; color: var(--steel-soft); font: 500 .58rem/1.3 "IBM Plex Mono", monospace; letter-spacing: .16em; }
.site-nav { display: flex; align-items: center; gap: 8px; }
.site-nav a { padding: 8px 12px; border-radius: 5px; color: var(--ink-soft); font-size: .88rem; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--signal); background: var(--signal-soft); }
.site-nav .admin-link { border: 1px solid var(--line); }

.hero-small { padding: 76px 0 52px; border-bottom: 1px solid var(--line); }
.eyebrow { color: var(--steel); font: 600 .7rem/1.4 "IBM Plex Mono", monospace; letter-spacing: .2em; text-transform: uppercase; }
.eyebrow::before { content: ""; display: inline-block; width: 26px; height: 1px; margin-right: 10px; vertical-align: middle; background: var(--steel); }
.hero-small h1 { max-width: 760px; margin-top: 16px; font-size: clamp(2.1rem, 5vw, 4rem); letter-spacing: .035em; }
.hero-small p { max-width: 680px; margin-top: 18px; color: var(--ink-soft); font-size: 1.05rem; }

.toolbar { position: relative; margin-top: -1px; padding: 22px 0; border-bottom: 1px solid var(--line); background: var(--paper-2); }
.filter-grid { display: grid; grid-template-columns: minmax(220px, 1fr) 180px 180px auto; gap: 12px; align-items: end; }
.field { display: grid; gap: 7px; }
.field label { color: var(--steel); font: 600 .72rem/1.3 "IBM Plex Mono", monospace; letter-spacing: .05em; }
.input, .textarea, .select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: var(--white);
  color: var(--ink);
  padding: 10px 12px;
  transition: border-color .2s, box-shadow .2s;
}
.textarea { min-height: 120px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--signal); box-shadow: 0 0 0 3px rgba(14, 124, 90, .12); }
.input[type="file"] { padding: 8px; }
.hint { color: var(--ink-soft); font-size: .78rem; }
.required::after { content: " *"; color: var(--danger); }

.btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 6px; padding: 9px 17px; font: 600 .8rem/1.3 "IBM Plex Mono", monospace; transition: transform .15s, background .2s, border-color .2s; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--signal); color: #fff; }
.btn-primary:hover { background: var(--signal-dark); }
.btn-secondary { background: var(--white); border-color: var(--steel); color: var(--steel); }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-danger { background: #fff; border-color: #d8aaa7; color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.content { min-height: 48vh; padding: 48px 0 90px; }
.result-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.result-count { color: var(--ink-soft); font-size: .88rem; }
.document-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.document-card { display: flex; flex-direction: column; min-height: 280px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--paper-2); box-shadow: var(--shadow); transition: transform .2s, border-color .2s; }
.document-card:hover { transform: translateY(-3px); border-color: var(--steel-soft); }
.card-rule { height: 5px; background: linear-gradient(90deg, var(--signal), var(--steel)); }
.card-body { flex: 1; display: flex; flex-direction: column; padding: 23px; }
.card-date { color: var(--signal); font: 600 .69rem/1.4 "IBM Plex Mono", monospace; letter-spacing: .08em; }
.document-card h2 { margin-top: 12px; font-size: 1.12rem; }
.card-description { margin-top: 12px; color: var(--ink-soft); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.tag { border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--steel); padding: 3px 9px; font-size: .72rem; }
.card-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: auto; padding-top: 20px; color: var(--steel-soft); font: 500 .69rem/1.4 "IBM Plex Mono", monospace; }
.card-link { color: var(--signal); font-weight: 600; }
.empty-state, .loading-state { grid-column: 1 / -1; padding: 64px 24px; border: 1px dashed var(--line); border-radius: 9px; background: rgba(251, 252, 250, .75); text-align: center; color: var(--ink-soft); }
.empty-state strong { display: block; margin-bottom: 8px; color: var(--ink); font: 700 1.2rem "Noto Serif TC", serif; }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
.detail-main, .detail-side, .panel { border: 1px solid var(--line); border-radius: 9px; background: var(--paper-2); box-shadow: var(--shadow); }
.detail-main { padding: 34px; }
.detail-title { margin-top: 14px; font-size: clamp(1.7rem, 4vw, 2.7rem); }
.detail-description { margin-top: 22px; color: var(--ink-soft); font-size: 1rem; white-space: pre-line; }
.pdf-frame { width: 100%; height: min(75vh, 880px); min-height: 560px; margin-top: 28px; border: 1px solid var(--line); border-radius: 7px; background: #e8ece9; }
.detail-side { position: sticky; top: 92px; padding: 24px; }
.meta-list { display: grid; gap: 18px; margin: 0 0 24px; }
.meta-list div { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.meta-list dt { color: var(--steel-soft); font: 600 .68rem/1.4 "IBM Plex Mono", monospace; letter-spacing: .08em; }
.meta-list dd { margin: 5px 0 0; }
.detail-actions { display: grid; gap: 10px; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 30px 20px; }
.login-card { width: min(100%, 430px); padding: 34px; border: 1px solid var(--line); border-radius: 12px; background: rgba(251, 252, 250, .96); box-shadow: 0 30px 80px -48px rgba(25, 35, 43, .65); }
.login-card h1 { margin-top: 12px; font-size: 2rem; }
.login-card form { display: grid; gap: 17px; margin-top: 28px; }
.login-card .btn { width: 100%; margin-top: 5px; }
.login-back { display: inline-flex; margin-top: 22px; color: var(--steel); font-size: .86rem; }

.admin-shell { min-height: 100vh; }
.admin-header { border-bottom: 1px solid var(--line); background: var(--ink); color: #fff; }
.admin-header .header-inner { min-height: 70px; }
.admin-brand small { color: #aab7be; }
.admin-nav { display: flex; align-items: center; gap: 10px; }
.admin-nav a, .admin-nav button { border: 0; border-radius: 5px; background: transparent; color: #d8e0e3; padding: 8px 11px; font-size: .85rem; }
.admin-nav a:hover, .admin-nav button:hover { background: rgba(255,255,255,.09); color: #fff; }
.admin-main { padding: 42px 0 80px; }
.admin-titlebar { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.admin-titlebar h1 { font-size: clamp(1.8rem, 4vw, 2.7rem); }
.admin-titlebar p { margin-top: 7px; color: var(--ink-soft); }
.panel { padding: 24px; }
.admin-filters { display: grid; grid-template-columns: minmax(220px, 1fr) 170px auto; gap: 12px; margin-bottom: 20px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--paper-2); }
.data-table { width: 100%; border-collapse: collapse; min-width: 820px; }
.data-table th { background: #edf1ed; color: var(--steel); font: 600 .7rem/1.4 "IBM Plex Mono", monospace; letter-spacing: .05em; text-align: left; }
.data-table th, .data-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table h3 { font: 600 .95rem/1.5 "Noto Sans TC", sans-serif; }
.table-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.table-actions .btn { min-height: 34px; padding: 6px 10px; font-size: .7rem; }
.status { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 4px 9px; font-size: .72rem; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-published { background: var(--signal-soft); color: var(--signal-dark); }
.status-draft { background: #f4e8d2; color: var(--warning); }

.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.form-section { display: grid; gap: 19px; }
.form-section + .form-section { margin-top: 28px; padding-top: 28px; border-top: 1px solid var(--line); }
.form-section h2 { font-size: 1.2rem; }
.form-actions { position: sticky; top: 24px; display: grid; gap: 10px; }
.file-current { padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: #edf1ed; font-size: .84rem; overflow-wrap: anywhere; }
.progress { height: 8px; overflow: hidden; border-radius: 999px; background: #e2e8e3; }
.progress span { display: block; width: 0; height: 100%; background: var(--signal); transition: width .25s; }

.alert { margin-bottom: 18px; border: 1px solid var(--line); border-left-width: 4px; border-radius: 6px; padding: 12px 14px; background: #fff; font-size: .88rem; }
.alert-error { border-left-color: var(--danger); color: #772b27; }
.alert-success { border-left-color: var(--signal); color: var(--signal-dark); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: 390px; border-radius: 7px; background: var(--ink); color: #fff; padding: 12px 16px; box-shadow: 0 16px 50px rgba(0,0,0,.25); font-size: .87rem; }

.site-footer { padding: 34px 0; border-top: 1px solid var(--line); background: var(--paper-2); color: var(--ink-soft); font-size: .8rem; }
.footer-inner { display: flex; justify-content: space-between; gap: 18px; flex-wrap: wrap; }

@media (max-width: 860px) {
  .document-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .detail-layout, .form-layout { grid-template-columns: 1fr; }
  .detail-side, .form-actions { position: static; }
  .admin-filters { grid-template-columns: 1fr 160px; }
  .admin-filters .btn { grid-column: 1 / -1; }
}
@media (max-width: 620px) {
  .wrap { width: min(calc(100% - 28px), var(--maxw)); }
  .header-inner { align-items: flex-start; padding: 13px 0; }
  .site-nav { justify-content: flex-end; flex-wrap: wrap; gap: 2px; }
  .site-nav a { padding: 6px 8px; font-size: .78rem; }
  .hero-small { padding: 54px 0 40px; }
  .filter-grid, .document-grid, .admin-filters { grid-template-columns: 1fr; }
  .admin-filters .btn { grid-column: auto; }
  .content { padding-top: 30px; }
  .detail-main, .panel, .login-card { padding: 22px; }
  .pdf-frame { min-height: 430px; }
  .admin-titlebar { align-items: stretch; flex-direction: column; }
  .admin-titlebar .btn { width: 100%; }
  .admin-header .header-inner { align-items: center; }
  .admin-nav a { display: none; }
}
