/* ================================================================
   Private Journal · 全域樣式
   配色：暖系明亮 · 低對比度
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;1,300;1,400&family=DM+Mono:wght@300;400&family=Lora:ital@0;1&display=swap');

/* ── CSS 變數 ────────────────────────────────────────────── */
:root {
  /* 背景層次 */
  --bg:           #faf5ee;   /* 溫暖米白 */
  --surface:      #fff8f0;   /* 暖白表面 */
  --surface-2:    #fffcf8;   /* 次層卡片 */
  --surface-3:    #ffffff;   /* 最亮表面 */

  /* 邊框 */
  --border:       rgba(185, 148, 100, 0.16);
  --border-md:    rgba(185, 148, 100, 0.30);
  --border-focus: rgba(176, 120, 64, 0.45);

  /* 主色（琥珀暖棕）*/
  --accent:       #b07840;
  --accent-light: #cc9a62;
  --accent-dim:   #e2c8a0;
  --accent-pale:  #f6ead8;

  /* 點綴色 */
  --warm-green:   #7a9e7c;   /* 橄欖綠 */
  --warm-rose:    #c98a80;   /* 暖玫瑰 */
  --warm-sky:     #7a9eb0;   /* 霧藍 */

  /* 文字 */
  --text:         #3a2e20;   /* 深暖棕（非純黑）*/
  --text-muted:   #7a6a52;
  --text-dim:     #b8a88a;
  --text-placeholder: #cdbfa6;

  /* 功能色 */
  --success:      #6a9e78;
  --error:        #b85c48;
  --success-bg:   rgba(106, 158, 120, 0.1);
  --error-bg:     rgba(184, 92, 72, 0.08);

  /* 尺寸 */
  --radius:       12px;
  --radius-sm:    8px;
  --radius-lg:    16px;
  --sidebar-w:    252px;

  /* 陰影 */
  --shadow-xs:    0 1px 4px rgba(80, 55, 30, 0.07);
  --shadow-sm:    0 2px 12px rgba(80, 55, 30, 0.09);
  --shadow:       0 4px 28px rgba(80, 55, 30, 0.10);
  --shadow-lg:    0 8px 48px rgba(80, 55, 30, 0.13);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Lora', Georgia, serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── 背景紋理（全域）── */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 60% 45% at 5% 5%,   rgba(220, 175, 120, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse 55% 60% at 95% 95%,  rgba(180, 210, 185, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse 70% 70% at 50% 50%,  rgba(250, 240, 225, 0.4)  0%, transparent 70%);
}

/* 細點紋 */
body::after {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(circle, rgba(160, 120, 70, 0.04) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(ellipse 90% 90% at 50% 50%, black 0%, transparent 75%);
}

/* ── 版面容器 ── */
.layout {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ════════════════════════════════════════════════
   側邊欄
   ════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* 品牌區 */
.sb-brand {
  padding: 1.6rem 1.4rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.sb-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.22rem;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: var(--text);
}
.sb-logo em { font-style: italic; color: var(--accent); }

.sb-user {
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* 三色裝飾條 */
.sb-stripe {
  display: flex;
  height: 3px;
}
.sb-stripe span { flex: 1; }
.sb-stripe span:nth-child(1) { background: var(--warm-rose);  opacity: 0.55; }
.sb-stripe span:nth-child(2) { background: var(--accent-dim); opacity: 0.7;  }
.sb-stripe span:nth-child(3) { background: var(--warm-green); opacity: 0.55; }

/* 統計格 */
.sb-stats {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.sb-stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  box-shadow: var(--shadow-xs);
}
.sb-stat-n {
  font-family: 'DM Mono', monospace;
  font-size: 1.3rem;
  color: var(--accent);
  line-height: 1;
}
.sb-stat-l {
  font-family: 'DM Mono', monospace;
  font-size: 0.56rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* 導覽 */
.sb-nav { padding: 1rem 0.85rem; flex: 1; }

.sb-nav-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.54rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 0.5rem;
  margin-bottom: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  margin-bottom: 0.12rem;
}
.nav-item svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
.nav-item:hover,
.nav-item.active { background: var(--accent-pale); color: var(--accent); }
.nav-item.danger:hover { background: var(--error-bg); color: var(--error); }

.sb-footer {
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--border);
  font-family: 'DM Mono', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.09em;
  color: var(--text-dim);
}

/* ════════════════════════════════════════════════
   頂部欄
   ════════════════════════════════════════════════ */
.topbar {
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
}

.topbar-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.4rem;
  font-weight: 300;
  color: var(--text);
}
.topbar-title em { font-style: italic; color: var(--accent); }

.topbar-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text-muted);
  text-decoration: none;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  transition: color 0.15s;
}
.topbar-back:hover { color: var(--accent); }
.topbar-back svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ════════════════════════════════════════════════
   通知欄
   ════════════════════════════════════════════════ */
.msg-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.75rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.73rem;
  letter-spacing: 0.04em;
}
.msg-bar.success {
  background: var(--success-bg);
  color: var(--success);
  border-bottom: 1px solid rgba(106,158,120,0.18);
}
.msg-bar.error {
  background: var(--error-bg);
  color: var(--error);
  border-bottom: 1px solid rgba(184,92,72,0.16);
}

/* ════════════════════════════════════════════════
   按鈕
   ════════════════════════════════════════════════ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.7rem 1.6rem;
  background: linear-gradient(160deg, #c48c50, #b07840);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff8f0;
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 2px 10px rgba(160,100,50,0.22), 0 1px 0 rgba(255,255,255,0.15) inset;
  transition: background 0.2s, box-shadow 0.2s, transform 0.12s;
  white-space: nowrap;
}
.btn-primary:hover {
  background: linear-gradient(160deg, #d49a60, #c08048);
  box-shadow: 0 4px 18px rgba(160,100,50,0.28);
  transform: translateY(-1px);
}
.btn-primary:active { transform: none; }
.btn-primary svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  background: none;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 0.67rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--accent-dim); color: var(--accent); background: var(--accent-pale); }

/* ════════════════════════════════════════════════
   表單通用
   ════════════════════════════════════════════════ */
.field { margin-bottom: 1.1rem; }

.field-label {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.42rem;
  transition: color 0.2s;
}
.field:focus-within .field-label { color: var(--accent); }

.field-hint {
  font-family: 'DM Mono', monospace;
  font-size: 0.58rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}

/* 通用 input */
.input {
  width: 100%;
  padding: 0.68rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 1px 3px rgba(120,80,40,0.04) inset;
}
.input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(176,120,64,0.1), 0 1px 3px rgba(120,80,40,0.04) inset;
}
.input::placeholder { color: var(--text-placeholder); }
.input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface-2) inset;
  -webkit-text-fill-color: var(--text);
}

/* input with icon */
.input-wrap { position: relative; }
.input-wrap .input { padding-left: 2.4rem; }
.input-wrap .input-icon {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 15px; height: 15px;
  stroke: var(--text-dim); fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
  pointer-events: none;
  transition: stroke 0.2s;
}
.input-wrap:focus-within .input-icon { stroke: var(--accent); }

/* ════════════════════════════════════════════════
   Badge / 標籤
   ════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.16rem 0.55rem;
  border-radius: 5px;
  font-family: 'DM Mono', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-create { background: rgba(122,158,124,0.12); color: var(--warm-green); border: 1px solid rgba(122,158,124,0.22); }
.badge-update { background: var(--accent-pale);     color: var(--accent);      border: 1px solid var(--accent-dim); }
.badge-delete { background: rgba(201,138,128,0.12); color: var(--warm-rose);   border: 1px solid rgba(201,138,128,0.25); }
.badge-ok     { background: var(--success-bg);      color: var(--success);     border: 1px solid rgba(106,158,120,0.22); }
.badge-fail   { background: var(--error-bg);         color: var(--error);       border: 1px solid rgba(184,92,72,0.18); }

/* ════════════════════════════════════════════════
   分頁
   ════════════════════════════════════════════════ */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1.25rem 1.75rem 1.75rem;
}
.pager a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px; height: 34px;
  padding: 0 0.45rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 0.72rem;
  text-decoration: none;
  transition: all 0.15s;
}
.pager a:hover,
.pager a.on { border-color: var(--border-md); background: var(--accent-pale); color: var(--accent); }
.pager a.on { pointer-events: none; }

/* ════════════════════════════════════════════════
   Modal
   ════════════════════════════════════════════════ */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 100;
  background: rgba(60, 45, 28, 0.35);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  max-width: 370px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: modal-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-pop {
  from { transform: scale(0.96) translateY(4px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.modal h3 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.15rem;
  font-weight: 400;
  margin-bottom: 0.65rem;
}
.modal p { font-size: 0.84rem; color: var(--text-muted); line-height: 1.55; margin-bottom: 1.4rem; }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

.btn-cancel {
  padding: 0.55rem 1.1rem;
  border-radius: 7px;
  border: 1px solid var(--border-md);
  background: none;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-cancel:hover { border-color: var(--border-focus); color: var(--text); }

.btn-danger-confirm {
  padding: 0.55rem 1.1rem;
  border-radius: 7px;
  border: 1px solid rgba(184,92,72,0.3);
  background: var(--error-bg);
  color: var(--error);
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-danger-confirm:hover { background: rgba(184,92,72,0.15); }

/* ════════════════════════════════════════════════
   搜尋欄
   ════════════════════════════════════════════════ */
.search-wrap { position: relative; flex: 1; max-width: 320px; }
.search-wrap .s-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; stroke: var(--text-dim); fill: none;
  stroke-width: 1.6; pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 0.58rem 0.9rem 0.58rem 2.1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Lora', serif;
  font-size: 0.84rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(176,120,64,0.08); }
.search-input::placeholder { color: var(--text-placeholder); }

/* ════════════════════════════════════════════════
   Section label
   ════════════════════════════════════════════════ */
.section-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.9rem;
}
.section-label span { color: var(--accent-light); margin-left: 0.4rem; }

/* ════════════════════════════════════════════════
   捲軸美化
   ════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent-dim); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-light); }

/* ════════════════════════════════════════════════
   響應式
   ════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar  { padding: 1rem; }
}

/* ════════════════════════════════════════════════
   動畫 keyframes
   ════════════════════════════════════════════════ */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
