:root {
  --primary: #0891b2;
  --primary-dark: #0e7490;
  --primary-light: #ecfeff;
  --primary-border: #a5f3fc;
  --bg: #f8fafc;
  --card: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --thead: #f1f5f9;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.04);
  --shadow-hover: 0 4px 20px rgba(15,23,42,.10), 0 1px 4px rgba(15,23,42,.06);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif; letter-spacing: 0; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

/* ── Shell & sidebar ── */
.shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 240px; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: #fff; }
.brand { height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 20px; border-bottom: 1px solid var(--border); background: #fff; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius); background: var(--primary-light); color: var(--primary-dark); border: 1px solid var(--primary-border); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: 2px; color: var(--muted); }
.sidebar nav { flex: 1; padding: 16px 12px; }
.sidebar nav a { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 10px 12px; border-radius: var(--radius); color: #475569; font-size: 14px; font-weight: 700; transition: background .15s ease, color .15s ease; }
.sidebar nav a:hover, .sidebar nav a.active { background: var(--primary-light); color: var(--primary-dark); }
.sidebar-foot { display: flex; align-items: center; gap: 12px; padding: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.sidebar-foot strong, .sidebar-foot small { display: block; }
.sidebar-foot strong { color: var(--text); font-size: 14px; }
.sidebar-foot small { color: var(--muted); }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 999px; background: #f1f5f9; color: #334155; font-weight: 800; }
/* Sidebar brand gradient */
.sidebar .brand { background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%); border-bottom-color: transparent; }
.sidebar .brand-mark { background: rgba(255,255,255,.18); color: #fff; border-color: rgba(255,255,255,.25); }
.sidebar .brand strong { color: #fff; }
.sidebar .brand small { color: rgba(255,255,255,.75); }

/* ── Layout ── */
.main { min-height: 100vh; margin-left: 240px; }
.public-main { max-width: 1100px; margin: 0 auto; padding: 28px; }
.public-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.public-brand { height: auto; padding: 0; border: 0; background: transparent !important; }
.topbar { position: sticky; top: 0; z-index: 10; height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 28px; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.96); backdrop-filter: blur(10px); }
.crumb { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: 14px; }
.crumb strong { color: var(--text); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.search-box { width: 270px; height: 38px; display: flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: #94a3b8; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: #475569; }
.icon-button:hover { background: #f8fafc; }
.admin-chip { white-space: nowrap; color: var(--muted); font-size: 14px; }
.admin-chip a { margin-left: 10px; color: var(--primary-dark); font-weight: 700; }
.content { padding: 28px; }
.page-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; }
.page-head p, .muted { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

/* ── Grid ── */
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wide { grid-template-columns: minmax(0, 1.5fr) minmax(320px, .8fr); }
.form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

/* ── Cards & panels ── */
.panel, .stat, .public-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.panel { margin-bottom: 20px; }
.panel-head { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.panel-body { padding: 20px; }

/* ── Stat cards ── */
.stat { position: relative; padding: 20px; overflow: hidden; }
.stat small { color: var(--muted); font-weight: 700; font-size: 13px; }
.stat strong { display: block; margin-top: 4px; font-size: 34px; line-height: 1; }
.stat p { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.stat-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; margin-bottom: 14px; }
.stat-green  .stat-icon { background: #d1fae5; color: #047857; }
.stat-blue   .stat-icon { background: #cffafe; color: #0e7490; }
.stat-red    .stat-icon { background: #fee2e2; color: #dc2626; }
.stat-yellow .stat-icon { background: #fef3c7; color: #b45309; }
.stat-orange .stat-icon { background: #ffedd5; color: #c2410c; }

/* ── Table ── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table { width: 100%; min-width: 760px; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 14px; background: var(--thead); color: #334155; text-align: left; }
td { padding: 12px 14px; border-top: 1px solid var(--border); color: #334155; vertical-align: middle; }
tbody tr:nth-child(even) td { background: #f8fafc; }
tr:hover td { background: var(--primary-light); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.available { color: #047857; background: #d1fae5; }
.badge.loaned    { color: #0e7490; background: #cffafe; }
.badge.danger    { color: #dc2626; background: #fee2e2; }
.badge.warning   { color: #b45309; background: #fef3c7; }
.badge.printed   { color: #7c3aed; background: #ede9fe; }
.badge.neutral   { color: #64748b; background: #f3f4f6; }

/* ── Utilities ── */
.code { font-family: Consolas, "SFMono-Regular", monospace; color: var(--text); font-weight: 800; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: #cbd5e1; }
.actions a, .actions button { border: 0; background: transparent; color: var(--primary-dark); font-weight: 800; cursor: pointer; }

/* ── Tabs ── */
.category-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.category-tabs a { display: inline-flex; align-items: center; min-height: 36px; padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: #475569; font-size: 14px; font-weight: 800; }
.category-tabs a:hover, .category-tabs a.active { border-color: var(--primary-border); background: var(--primary-light); color: var(--primary-dark); }
.detail-tabs { margin-bottom: 22px; }
.detail-section { scroll-margin-top: 82px; margin-bottom: 8px; }
.section-heading { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; }
.section-heading::before { content: ""; width: 4px; height: 20px; border-radius: 999px; background: var(--primary); }
.section-heading h2 { margin: 0; font-size: 18px; }

/* ── Buttons ── */
.btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border: 1px solid var(--primary); border-radius: var(--radius); background: var(--primary); color: #fff; font-size: 14px; font-weight: 800; cursor: pointer; transition: background .15s ease, border-color .15s ease, color .15s ease; }
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.secondary { border-color: var(--primary-border); background: #fff; color: var(--primary-dark); }
.btn.secondary:hover { background: var(--primary-light); border-color: #67e8f9; }
.btn.danger { border-color: #dc2626; background: #dc2626; color: #fff; }
.btn.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.ghost { border-color: transparent; background: transparent; color: #475569; }
.btn.ghost:hover { background: #f1f5f9; }

/* ── Forms ── */
.field { display: block; }
.field span { display: block; margin-bottom: 6px; color: #334155; font-size: 14px; font-weight: 800; }
.field b { margin-left: 4px; color: #dc2626; }
.field input, .field select, .field textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; outline: 0; transition: border-color .15s, box-shadow .15s; }
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #cffafe; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #f8fafc; }
.info-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; }
.info-grid strong { display: block; margin-top: 4px; }

/* ── Toast ── */
.toast { position: fixed; right: 16px; top: 16px; z-index: 99; max-width: min(380px, calc(100vw - 32px)); padding: 12px 16px; border-radius: var(--radius); background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow); font-weight: 800; }
.toast.error { color: #991b1b; border-color: #fecaca; background: #fef2f2; }

/* ── Login ── */
.login-wrap { min-height: calc(100vh - 56px); display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }

/* ── Public hero ── */
.public-hero { padding: 32px; border: 1px solid var(--primary-border); border-radius: var(--radius); background: linear-gradient(135deg, #ecfeff 0%, #cffafe 65%, #a5f3fc 100%); box-shadow: 0 4px 24px rgba(8,145,178,.12); }
.public-hero h1 { margin: 0; font-size: 28px; color: #0e4f5e; }

/* ── Public cards ── */
.public-card { padding: 18px; transition: transform .15s ease, box-shadow .15s ease; }
.public-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }

/* ── Fish status grid ── */
.fish-status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.fish-status-card { padding: 16px; border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); transition: box-shadow .15s; }
/* Status colour strips */
.fish-status-card.status-available { border-left-color: #10b981; }
.fish-status-card.status-loaned    { border-left-color: #0891b2; }
.fish-status-card.status-danger    { border-left-color: #ef4444; }
.fish-status-card.status-warning   { border-left-color: #f59e0b; }
.fish-status-card.status-printed   { border-left-color: #7c3aed; }
.fish-status-card.status-neutral   { border-left-color: #94a3b8; }
.fish-status-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.fish-status-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #f1f5f9; }
.fish-status-meta span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; }
.fish-status-meta strong { display: block; margin-top: 4px; color: var(--text); font-size: 14px; overflow-wrap: anywhere; }
/* Clickable borrowed cards */
.fish-status-card.is-borrowed { cursor: pointer; }
.fish-status-card.is-borrowed:hover { border-color: var(--primary-border); background: #f0fdff; box-shadow: var(--shadow-hover); }
.fish-loan-details > summary { list-style: none; cursor: pointer; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.fish-loan-details > summary::-webkit-details-marker { display: none; }
.expand-hint { color: var(--muted); line-height: 1; transition: transform .2s ease; margin-top: 2px; }
.fish-loan-details[open] .expand-hint { transform: rotate(90deg); }

/* ── Misc ── */
.fish-mini-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.fish-mini-list > span { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.upload-note { padding: 12px; border: 1px dashed #cbd5e1; border-radius: var(--radius); background: #f8fafc; color: var(--muted); }
.empty-state { display: grid; place-items: center; gap: 10px; min-height: 220px; padding: 28px; border: 1px dashed #cbd5e1; border-radius: var(--radius); background: #f8fafc; text-align: center; color: #64748b; }
.empty-state h3 { margin: 0; color: var(--text); font-size: 17px; }
.empty-state p { max-width: 520px; margin: 0; line-height: 1.7; }

/* ── PDF print ── */
.pdf-paper { width: 210mm; min-height: 297mm; margin: 0 auto; padding: 16mm; background: #fff; font-family: DFKai-SB, KaiTi, PMingLiU, serif; color: #111827; box-shadow: var(--shadow); font-size: 13px; line-height: 1.65; }
.pdf-title { position: relative; padding-bottom: 16px; border-bottom: 2px solid #111827; text-align: center; }
.qrbox { position: absolute; right: 0; top: 0; width: 120px; height: 120px; display: grid; place-items: center; border: 1px solid #111827; font-size: 11px; }
.pdf-table { min-width: 0; }
.pdf-table th, .pdf-table td { border: 1px solid #334155; padding: 5px 7px; }
.pdf-table th { background: #f1f5f9; color: #111827; }
.icon { flex: 0 0 auto; }

/* ── Responsive ── */
@media (max-width: 1100px) { .stats, .two, .wide { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) { .search-box { display: none; } .top-actions { gap: 6px; } }
@media (max-width: 800px) {
  .sidebar { position: static; width: auto; }
  .sidebar .brand { background: linear-gradient(135deg, #0891b2 0%, #0e7490 100%); }
  .main { margin-left: 0; }
  .topbar { padding: 0 14px; }
  .content, .public-main { padding: 16px; }
  .stats, .two, .wide, .form-grid, .info-grid, .fish-status-meta { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .page-head, .topbar, .public-top { align-items: flex-start; flex-direction: column; height: auto; padding-top: 12px; padding-bottom: 12px; }
  .admin-chip { white-space: normal; }
}
@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .pdf-paper, .pdf-paper * { visibility: visible; }
  .pdf-paper { position: absolute; inset: 0; box-shadow: none; }
  .sidebar, .topbar, .no-print { display: none; }
}

/* ── Bulk actions ── */
.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}
.bulk-action-field { min-width: 220px; }
.bulk-hint { flex-basis: 100%; margin: 0; font-size: 13px; }
.select-col { width: 84px; white-space: nowrap; }
.check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 800; color: #475569; }
.select-col input[type="checkbox"], .check-inline input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* ── Bulk PDF download ── */
.bulk-download-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}
.bulk-download-box p { margin: 0; }
.bulk-pdf-status { min-height: 22px; }
.bulk-pdf-list { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.bulk-pdf-list li { line-height: 1.7; }
