/* ============ Design tokens ============
   Color:
   --ink        #1F3A3D  深墨綠 (主色，帳冊封面感)
   --ink-soft   #48605D  副文字
   --paper      #F6F2E7  暖白紙張
   --paper-alt  #ECE4D0  紙張陰影/次要底色
   --brass      #B8862B  黃銅（強調/按鈕）
   --brass-deep #8C6A22
   --red        #9A3324  硃紅（過年紅包專用強調色）
   --line       #D9CFB6  分隔線
   Type:
   Noto Serif TC  -> 標題／數字帳冊感
   Noto Sans TC   -> 內文／表單
*/

:root {
  --ink: #1F3A3D;
  --ink-soft: #48605D;
  --paper: #F6F2E7;
  --paper-alt: #ECE4D0;
  --brass: #B8862B;
  --brass-deep: #8C6A22;
  --red: #9A3324;
  --line: #D9CFB6;
  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Noto Sans TC', sans-serif;
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: 'Noto Serif TC', serif;
  margin: 0;
  color: var(--ink);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
}

/* ============ Layout: rail + stage ============ */
body {
  display: flex;
  min-height: 100vh;
}

.rail {
  width: 132px;
  flex-shrink: 0;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 28px 0 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-mark {
  font-family: 'Noto Serif TC', serif;
  font-size: 28px;
  text-align: center;
  color: var(--brass);
  border: 1px solid var(--brass);
  width: 44px;
  height: 44px;
  line-height: 44px;
  border-radius: 50%;
  margin: 0 auto 32px;
}

.rail-tab {
  background: none;
  border: none;
  color: rgba(246,242,231,0.62);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: color .15s ease, border-color .15s ease, background .15s ease;
}

.rail-tab-glyph {
  font-family: 'Noto Serif TC', serif;
  font-size: 22px;
  width: 38px;
  height: 38px;
  line-height: 38px;
  text-align: center;
  border: 1px solid rgba(246,242,231,0.3);
  border-radius: 50%;
}

.rail-tab-label {
  font-size: 13px;
  letter-spacing: 0.05em;
}

.rail-tab:hover {
  color: var(--paper);
  background: rgba(246,242,231,0.06);
}

.rail-tab.is-active {
  color: var(--paper);
  border-left-color: var(--brass);
  background: rgba(184,134,43,0.14);
}

.rail-tab.is-active .rail-tab-glyph {
  border-color: var(--brass);
  color: var(--brass);
}

.stage {
  flex: 1;
  min-width: 0;
  padding: 44px 48px 80px;
  max-width: 920px;
}

.panel { display: none; }
.panel.is-active { display: block; }

.panel-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 24px;
}

.panel-head h1 {
  font-size: 30px;
  font-weight: 700;
}

.panel-sub {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

/* ============ Toolbar ============ */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.toolbar select,
.toolbar input[type="search"] {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.toolbar input[type="search"] {
  flex: 1;
  min-width: 180px;
}

.btn {
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary {
  background: var(--brass);
  color: #fff;
  border-color: var(--brass-deep);
}
.btn-primary:hover { background: var(--brass-deep); }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--paper-alt); }

.btn-danger {
  background: transparent;
  border-color: var(--red);
  color: var(--red);
}
.btn-danger:hover { background: rgba(154,51,36,0.08); }

/* ============ Stat strip ============ */
.stat-strip {
  display: flex;
  gap: 24px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.stat-chip {
  border-left: 2px solid var(--brass);
  padding-left: 10px;
}

.stat-chip .num {
  font-family: 'Noto Serif TC', serif;
  font-size: 22px;
  display: block;
}

.stat-chip .label {
  font-size: 12px;
  color: var(--ink-soft);
}

/* ============ Ledger list (outings) ============ */
.ledger {
  border-top: 1px solid var(--line);
}

.ledger-row {
  display: grid;
  grid-template-columns: 96px 100px 1fr 120px;
  gap: 16px;
  align-items: start;
  padding: 14px 4px;
  border-bottom: 1px dashed var(--line);
  cursor: pointer;
}

.ledger-row:hover { background: var(--paper-alt); }

.ledger-date {
  font-family: 'Noto Serif TC', serif;
  font-size: 15px;
  white-space: nowrap;
}
.ledger-date .weekday { color: var(--ink-soft); font-size: 12px; margin-left: 4px; }

.ledger-cat {
  font-size: 12px;
  color: var(--brass-deep);
  border: 1px solid var(--brass);
  border-radius: 999px;
  padding: 2px 10px;
  height: fit-content;
  white-space: nowrap;
}

.ledger-main .item-name {
  font-weight: 700;
  margin-bottom: 2px;
}
.ledger-main .item-meta {
  font-size: 13px;
  color: var(--ink-soft);
}

.ledger-price {
  text-align: right;
  font-family: 'Noto Serif TC', serif;
}
.ledger-price .participants {
  display: block;
  font-family: 'Noto Sans TC', sans-serif;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ============ Timeline (trips) ============ */
.timeline {
  border-left: 2px solid var(--line);
  margin-left: 8px;
  padding-left: 24px;
}

.trip-card {
  position: relative;
  padding: 4px 0 26px;
  cursor: pointer;
}

.trip-card::before {
  content: '';
  position: absolute;
  left: -29px;
  top: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brass);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 2px var(--brass);
}

.trip-dates {
  font-family: 'Noto Serif TC', serif;
  color: var(--ink-soft);
  font-size: 13px;
}

.trip-title {
  font-size: 19px;
  font-weight: 700;
  margin: 2px 0 6px;
}

.trip-tag {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 9px;
  margin-right: 6px;
  color: var(--ink-soft);
}

.trip-meta {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 4px;
}

/* ============ Red envelope ============ */
.envelope-year {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
}

.envelope-year-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--paper-alt);
  padding: 12px 18px;
  cursor: pointer;
}

.envelope-year-head h3 {
  font-size: 20px;
}

.envelope-year-total {
  font-family: 'Noto Serif TC', serif;
  color: var(--red);
  font-size: 18px;
}

.envelope-year-body {
  padding: 14px 18px;
  display: none;
}
.envelope-year.is-open .envelope-year-body { display: block; }

.envelope-side {
  margin-bottom: 12px;
}
.envelope-side-title {
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.envelope-entry-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

.envelope-denoms {
  margin-top: 10px;
  font-size: 12px;
  color: var(--ink-soft);
}

/* ============ Empty state ============ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
}

/* ============ Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(31,58,61,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal[hidden] { display: none; }

.modal-card {
  background: var(--paper);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  padding: 24px 26px 26px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}

.modal-card-wide { max-width: 620px; }

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink-soft);
}

#outing-form label, #trip-form label, #envelope-form label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 12px;
}

#outing-form input, #outing-form select, #outing-form textarea,
#trip-form input, #trip-form select, #trip-form textarea,
#envelope-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.form-actions-right {
  display: flex;
  gap: 10px;
}

/* map picker */
.map-field { margin-bottom: 12px; }
.map-search-row {
  display: flex;
  gap: 8px;
}
.map-search-row input { flex: 1; }
#outing-map {
  height: 220px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.map-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 6px 0 2px;
}
.map-coords {
  font-size: 12px;
  color: var(--brass-deep);
  margin: 2px 0 0;
}

/* red envelope entries editor */
.entries-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 6px 0 8px;
}
.entry-edit-row {
  display: grid;
  grid-template-columns: 90px 1fr 1fr 32px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.entry-edit-row input, .entry-edit-row select {
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.entry-remove {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 16px;
}

/* ============ Responsive ============ */
@media (max-width: 720px) {
  body { flex-direction: column; }
  .rail {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    padding: 14px 12px;
    overflow-x: auto;
    gap: 4px;
  }
  .rail-mark { display: none; }
  .rail-tab { flex-direction: row; padding: 8px 12px; border-left: none; border-bottom: 3px solid transparent; }
  .rail-tab.is-active { border-left: none; border-bottom-color: var(--brass); }
  .rail-tab-glyph { width: 28px; height: 28px; line-height: 28px; font-size: 16px; }
  .stage { padding: 24px 16px 60px; }
  .ledger-row { grid-template-columns: 1fr; gap: 4px; }
  .ledger-price { text-align: left; }
  .form-row { grid-template-columns: 1fr; }
}
