@font-face {
  font-family: 'JF Open Huninn';
  src: url('../fonts/jf-openhuninn.ttf') format('truetype');
  font-display: swap;
}
:root {
  --brick: #A0483E; --gold: #C5A059; --ink: #1A1410; --ash: #5C5247;
  --cream: #F4EFE6; --white: #FAFAF6; --font: 'JF Open Huninn','Noto Sans TC',sans-serif;
  --r: 4px; --sidebar-w: 248px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: #EEEAE3; color: var(--ink); min-height: 100vh; }
a { color: inherit; text-decoration: none; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--ink); padding: 24px; position: relative; overflow: hidden; }
.login-page::before { content: ''; position: absolute; inset: 0; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60'%3E%3Ccircle cx='30' cy='30' r='29' fill='none' stroke='rgba(255,255,255,0.03)' stroke-width='1'/%3E%3C/svg%3E") repeat; background-size: 60px 60px; }
.login-card { background: var(--white); border-radius: 12px; padding: 48px 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 64px rgba(0,0,0,0.35); position: relative; z-index: 1; }
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo .mark { width: 56px; height: 56px; background: var(--brick); border-radius: 14px; display: flex; align-items: center; justify-content: center; font-size: 1.6rem; margin: 0 auto 14px; color: white; }
.login-logo h1 { font-size: 1.1rem; color: var(--ink); font-weight: normal; }
.login-logo p  { font-size: 0.76rem; color: var(--ash); margin-top: 4px; }
.fg { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.fg label { font-size: 0.8rem; color: var(--ash); }
.fg input { padding: 11px 14px; border: 1px solid rgba(209,209,199,0.9); border-radius: var(--r); font-family: var(--font); font-size: 0.9rem; color: var(--ink); background: white; outline: none; transition: border-color 0.2s; }
.fg input:focus { border-color: var(--gold); }
.btn-login { width: 100%; padding: 13px; background: var(--brick); color: white; border: none; border-radius: var(--r); font-family: var(--font); font-size: 0.95rem; cursor: pointer; transition: background 0.2s; margin-top: 8px; }
.btn-login:hover { background: #7A3530; }
.login-err { color: var(--brick); font-size: 0.82rem; text-align: center; margin-top: 12px; display: none; }
.login-note { text-align: center; font-size: 0.72rem; color: var(--ash); margin-top: 20px; opacity: 0.6; }

/* Dashboard Layout */
.dash { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--ink); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; overflow-y: auto; }
.sidebar__brand { padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,0.07); display: flex; align-items: center; gap: 10px; }
.sidebar__brand .mark { width: 34px; height: 34px; background: var(--brick); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; color: white; }
.sidebar__brand .name { font-size: 0.85rem; color: rgba(255,255,255,0.88); line-height: 1.3; }
.sidebar__brand .sub  { font-size: 0.65rem; color: rgba(255,255,255,0.38); display: block; }
.sidebar__nav { padding: 14px 0; flex: 1; }
.sidebar__section { padding: 10px 20px 4px; font-size: 0.65rem; letter-spacing: 0.2em; color: rgba(255,255,255,0.25); text-transform: uppercase; }
.sidebar__nav a { display: flex; align-items: center; gap: 10px; padding: 10px 20px; font-size: 0.875rem; color: rgba(255,255,255,0.52); transition: all 0.2s; border-left: 3px solid transparent; }
.sidebar__nav a:hover { color: rgba(255,255,255,0.88); background: rgba(255,255,255,0.04); }
.sidebar__nav a.active { color: var(--gold); border-left-color: var(--gold); background: rgba(197,160,89,0.07); }
.sidebar__nav .ni { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar__foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,0.07); font-size: 0.76rem; color: rgba(255,255,255,0.28); }
.sidebar__foot a { color: rgba(255,255,255,0.38); }
.sidebar__foot a:hover { color: var(--gold); }

/* Main */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar { background: white; border-bottom: 1px solid rgba(209,209,199,0.7); padding: 0 28px; height: 58px; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 50; box-shadow: 0 1px 0 rgba(209,209,199,0.5); }
.topbar h2 { font-size: 0.95rem; font-weight: normal; color: var(--ink); }
.topbar__user { display: flex; align-items: center; gap: 10px; font-size: 0.82rem; color: var(--ash); }
.content { padding: 28px; flex: 1; }

/* Components */
.panel { background: white; border-radius: var(--r); border: 1px solid rgba(209,209,199,0.7); margin-bottom: 22px; overflow: hidden; }
.panel__head { padding: 14px 20px; border-bottom: 1px solid rgba(209,209,199,0.6); display: flex; align-items: center; justify-content: space-between; background: rgba(244,239,230,0.5); }
.panel__title { font-size: 0.9rem; color: var(--ink); }
.panel__title span { color: var(--ash); font-size: 0.76rem; margin-left: 8px; }
.panel__body { padding: 20px; }

.stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.sc { background: white; border: 1px solid rgba(209,209,199,0.7); border-radius: var(--r); padding: 18px; display: flex; align-items: center; gap: 12px; }
.sc__icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; }
.sc__icon.r { background: rgba(160,72,62,0.1); }
.sc__icon.g { background: rgba(197,160,89,0.12); }
.sc__icon.b { background: rgba(80,140,200,0.1); }
.sc__icon.gr{ background: rgba(80,160,100,0.1); }
.sc__num { font-size: 1.6rem; color: var(--ink); line-height: 1; }
.sc__lbl { font-size: 0.74rem; color: var(--ash); margin-top: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--r); font-family: var(--font); font-size: 0.84rem; cursor: pointer; transition: all 0.2s; border: 1px solid transparent; line-height: 1; }
.btn-sm { padding: 5px 11px; font-size: 0.76rem; }
.btn-primary { background: var(--brick); color: white; border-color: var(--brick); }
.btn-primary:hover { background: #7A3530; }
.btn-gold { background: var(--gold); color: white; border-color: var(--gold); }
.btn-gold:hover { background: #b08c48; }
.btn-ghost { background: transparent; color: var(--ash); border-color: rgba(209,209,199,0.9); }
.btn-ghost:hover { background: var(--cream); }
.btn-danger { background: transparent; color: #c0392b; border-color: #e74c3c; }
.btn-danger:hover { background: #c0392b; color: white; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.tbl th { background: rgba(244,239,230,0.6); color: var(--ash); padding: 12px 14px; text-align: left; font-weight: normal; font-size: 0.76rem; border-bottom: 1px solid rgba(209,209,199,0.7); }
.tbl td { padding: 12px 14px; border-bottom: 1px solid rgba(209,209,199,0.5); color: var(--ink); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(244,239,230,0.4); }
.tag-badge { display: inline-block; padding: 2px 8px; border-radius: 2px; font-size: 0.7rem; background: rgba(160,72,62,0.1); color: var(--brick); }
.tcell-title { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions { display: flex; gap: 6px; }

/* Forms */
.fg-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fg-set { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.fg-set label { font-size: 0.78rem; color: var(--ash); }
.fg-set input, .fg-set textarea, .fg-set select { padding: 9px 12px; border: 1px solid rgba(209,209,199,0.9); border-radius: var(--r); font-family: var(--font); font-size: 0.88rem; color: var(--ink); background: white; outline: none; transition: border-color 0.2s; }
.fg-set input:focus, .fg-set textarea:focus, .fg-set select:focus { border-color: var(--gold); }
.fg-set textarea { resize: vertical; min-height: 88px; }
.form-actions { display: flex; gap: 10px; padding-top: 6px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Modal */
.mo { position: fixed; inset: 0; background: rgba(26,20,16,0.52); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity 0.22s; }
.mo.open { opacity: 1; pointer-events: all; }
.mo__box { background: white; border-radius: 10px; width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(26,20,16,0.25); transform: translateY(16px); transition: transform 0.25s; }
.mo.open .mo__box { transform: translateY(0); }
.mo__head { padding: 18px 22px; border-bottom: 1px solid rgba(209,209,199,0.7); display: flex; align-items: center; justify-content: space-between; }
.mo__head h3 { font-size: 0.95rem; font-weight: normal; }
.mo__close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--ash); padding: 4px; }
.mo__body { padding: 22px; }
.mo__foot { padding: 14px 22px; border-top: 1px solid rgba(209,209,199,0.7); display: flex; gap: 10px; justify-content: flex-end; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--ink); color: rgba(250,250,246,0.9); padding: 12px 18px; border-radius: var(--r); font-size: 0.84rem; z-index: 9999; box-shadow: 0 4px 20px rgba(26,20,16,0.22); transform: translateY(80px); opacity: 0; transition: all 0.3s; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.ok  { border-left: 4px solid var(--gold); }
.toast.err { border-left: 4px solid var(--brick); }

@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .fg-row { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}
