/* ══════════════════════════════════════
   base.css — 변수 · 리셋 · 공통 컴포넌트 · 테마
   ══════════════════════════════════════ */

/* ── 디자인 토큰 ── */
:root {
  --ink: #1a1a1a; --paper: #ffffff; --paper2: #f5f3ee; --paper3: #ebe6d8;
  --stamp: #1B2D4F; --stamp-lt: rgba(27,45,79,.09); --stamp-dk: #0f1e35;
  --gold: #b8975a; --sage: #4a8c5c; --sage-lt: #e8f3ec;
  --blue: #2563eb; --muted: #8a8070;
  --bd: rgba(26,26,26,.12); --bd2: rgba(26,26,26,.06);
  --r: 16px; --rs: 10px;
  --st: env(safe-area-inset-top,0px); --sb: env(safe-area-inset-bottom,0px);
  --sh: 0px; --th: 62px;
  --gold-text: #8a6200; --warn: #f59e0b; --letter-muted: #b0a898; --fs-xs: 10px;
  --bg-lg: #ffffff; --text-lg: #1a1a1a;
  --text-lg-muted: rgba(26,26,26,.5); --text-lg-sub: rgba(26,26,26,.35);
}

/* ── 테마: 라이트 ── */
[data-theme="light"] {
  --ink: #1a1a1a; --paper: #ffffff; --paper2: #f5f3ee; --paper3: #ebe6d8;
  --muted: #8a8070; --bd: rgba(26,26,26,.12); --bd2: rgba(26,26,26,.06);
  --bg-lg: #ffffff; --text-lg: #1a1a1a;
  --text-lg-muted: rgba(26,26,26,.5); --text-lg-sub: rgba(26,26,26,.35);
}

/* ── 테마: 다크 ── */
[data-theme="dark"],
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ffffff; --paper: #000000; --paper2: #111111; --paper3: #1a1a1a;
    --muted: #888888; --bd: rgba(255,255,255,.12); --bd2: rgba(255,255,255,.06);
    --stamp: #4a6fa5; --gold: #c9a45c;
    --bg-lg: #000000; --text-lg: #ffffff;
    --text-lg-muted: rgba(255,255,255,.55); --text-lg-sub: rgba(255,255,255,.35);
    --stamp-lt: rgba(74,111,165,.2); --stamp-dk: #2a4a80; --sage-lt: rgba(74,140,92,.2);
    --gold-text: #c9a45c; --letter-muted: #888888;
  }
}
[data-theme="dark"] {
  --ink: #ffffff; --paper: #000000; --paper2: #111111; --paper3: #1a1a1a;
  --muted: #888888; --bd: rgba(255,255,255,.12); --bd2: rgba(255,255,255,.06);
  --stamp: #4a6fa5; --gold: #c9a45c;
  --bg-lg: #000000; --text-lg: #ffffff;
  --text-lg-muted: rgba(255,255,255,.55); --text-lg-sub: rgba(255,255,255,.35);
  --stamp-lt: rgba(74,111,165,.2); --stamp-dk: #2a4a80; --sage-lt: rgba(74,140,92,.2);
  --gold-text: #c9a45c; --letter-muted: #888888;
}

/* ── 리셋 ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { height: 100%; font-family: 'Noto Sans KR', sans-serif; color: var(--ink); background: var(--paper); }
body { height: 100%; display: flex; flex-direction: column; background: var(--paper); }

/* ── 앱 셸 ── */
.sw  { width: 100%; height: 100dvh; position: fixed; inset: 0; overflow: hidden; }
.shell { width: 100%; height: 100%; background: var(--paper); position: relative; overflow: hidden; display: flex; flex-direction: column; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.si { flex: 1; overflow: hidden; display: flex; flex-direction: column; padding-top: env(safe-area-inset-top,0px); min-height: 0; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.scroll::-webkit-scrollbar { display: none; }

/* ── 로딩 오버레이 ── */
#ld { position: absolute; inset: 0; z-index: 999; background: rgba(250,248,243,.94); display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
#ld.on { display: flex; }
.spin { width: 34px; height: 34px; border: 3px solid var(--bd); border-top-color: var(--stamp); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 토스트 ── */
#toast { position: absolute; bottom: calc(var(--th) + var(--sb) + 14px); left: 50%; transform: translateX(-50%) translateY(12px); background: rgba(26,26,26,.92); color: #fff; padding: 10px 20px; border-radius: 20px; font-size: 12px; z-index: 998; opacity: 0; transition: all .3s; white-space: nowrap; pointer-events: none; max-width: calc(100% - 40px); text-align: center; }
#toast.on  { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.ok  { background: rgba(74,140,92,.92); }
#toast.err { background: rgba(200,71,42,.92); }

/* ── 공통 폼 ── */
.fg   { margin-bottom: 20px; }
.fl   { display: block; font-size: 13px; color: var(--ink); margin-bottom: 8px; font-weight: 700; letter-spacing: -.01em; }
.fi   { width: 100%; padding: 16px; border: none; background: var(--paper2); color: var(--ink); font-family: 'Noto Sans KR', sans-serif; font-size: 15px; outline: none; transition: box-shadow .15s; border-radius: 14px; -webkit-appearance: none; }
.fi:focus { box-shadow: 0 0 0 2px var(--stamp); }
.fhint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.sttl  { font-family: 'Noto Sans KR', sans-serif; font-size: 22px; font-weight: 800; margin-bottom: 6px; letter-spacing: -.03em; }
.ssub  { font-size: 14px; color: var(--muted); margin-bottom: 28px; line-height: 1.7; }

/* ── 버튼 ── */
.btnfull { width: 100%; padding: 17px; background: var(--stamp); color: #fff; border: none; font-family: 'Noto Sans KR', sans-serif; font-size: 16px; font-weight: 700; cursor: pointer; border-radius: 14px; transition: opacity .15s; letter-spacing: -.02em; }
.btnfull:active { opacity: .8; }
.bsm   { padding: 7px 14px; border-radius: 18px; font-size: 11px; font-weight: 500; cursor: pointer; border: none; font-family: 'Noto Sans KR', sans-serif; transition: all .2s; }
.bsm.s { background: var(--stamp); color: #fff; }
.bsm.g { background: var(--sage); color: #fff; }
.bsm.b { background: var(--blue); color: #fff; }
.bsm.o { background: var(--paper); color: var(--ink); border: 1.5px solid var(--bd); }

/* ── 공통 헤더 ── */
.ph   { height: 60px; display: flex; align-items: center; gap: 14px; padding: 0 20px; border-bottom: none; flex-shrink: 0; background: var(--paper); }
.phbk { width: 36px; height: 36px; border-radius: 50%; background: var(--paper2); display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 18px; border: none; }
.phbk:active { opacity: .6; }
.pht  { font-family: 'Noto Sans KR', sans-serif; font-size: 18px; font-weight: 800; flex: 1; letter-spacing: -.03em; }

/* ── 다음/이전 버튼바 ── */
.nbtns { position: absolute; bottom: calc(var(--th,66px) + var(--sb,0px)); left: 0; right: 0; display: flex; gap: 10px; padding: 12px 20px; border-top: none; background: var(--paper); z-index: 10; }
.nbk { flex-shrink: 0; padding: 16px 18px; border: none; background: var(--paper2); color: var(--muted); font-size: 16px; cursor: pointer; border-radius: 14px; }
.nbk:active { opacity: .7; }
.nnx { flex: 1; padding: 17px; background: var(--stamp); color: #fff; border: none; font-family: 'Noto Sans KR', sans-serif; font-size: 16px; font-weight: 700; cursor: pointer; border-radius: 14px; letter-spacing: -.02em; }
.nnx:active { opacity: .8; }

/* ── 배지 ── */
.badge { font-size: 10px; font-weight: 700; padding: 4px 10px; border-radius: 14px; white-space: nowrap; }
.b0 { background: rgba(26,26,26,.08); color: var(--muted); }
.b1 { background: rgba(123,104,238,.12); color: #7b68ee; }
.b2 { background: rgba(184,151,90,.15); color: #8a6200; }
.b3 { background: var(--stamp-lt); color: var(--stamp); }
.b4 { background: rgba(74,140,92,.12); color: var(--sage); }
.b5 { background: var(--stamp-lt); color: var(--stamp); }

/* ── 리스트 아이템 ── */
.slbl { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 500; padding: 0 20px; margin-bottom: 10px; }
.ri   { display: flex; align-items: center; gap: 12px; background: var(--paper2); border: none; border-radius: 16px; padding: 16px; cursor: pointer; transition: opacity .12s; }
.ri:active { opacity: .7; }
.rdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.d0 { background: var(--muted); } .d1 { background: #7b68ee; } .d2 { background: var(--gold); }
.d3 { background: var(--stamp); } .d4 { background: var(--sage); }
.rii  { flex: 1; min-width: 0; }
.rin  { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ris  { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rist { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* ── 탭바 ── */
.tabbar { position: absolute; bottom: 0; left: 0; right: 0; z-index: 80; background: var(--paper); border-top: .5px solid var(--bd2); padding-bottom: var(--sb); }
.tab-two { display: flex; align-items: center; height: 66px; padding: 8px 14px; gap: 10px; box-sizing: border-box; width: 100%; }
.t2-item { flex: 1; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 8px; height: 50px; border-radius: 16px; border: none; background: var(--paper2); cursor: pointer; transition: all .18s cubic-bezier(.34,1.3,.64,1); min-width: 0; overflow: hidden; padding: 0 14px; }
.t2-item:active { transform: scale(.94); opacity: .8; }
.t2-ico { font-size: 20px; line-height: 1; flex-shrink: 0; }
.t2-lbl { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: 'Noto Sans KR', sans-serif; letter-spacing: -.02em; }
.t2-item.on.user-tab { background: var(--ink); border: none; }
.t2-item.on.user-tab .t2-lbl { color: var(--paper); font-weight: 700; }
.t2-item.on.user-tab .t2-ico { filter: invert(0); }
.t2-item.on.adm-tab { background: var(--stamp); border: none; }
.t2-item.on.adm-tab .t2-lbl { color: #fff; font-weight: 700; }
.tbw  { position: relative; display: inline-flex; align-items: center; flex-shrink: 0; }
.tbdg { position: absolute; top: -5px; right: -8px; min-width: 15px; height: 15px; background: var(--stamp); color: #fff; font-size: 10px; border-radius: 8px; display: none; align-items: center; justify-content: center; font-weight: 700; padding: 0 4px; border: 2px solid var(--paper); }
.tbdg.on { display: flex; }

/* ── 모달 공통 ── */
.modal-bg  { position: absolute; inset: 0; z-index: 990; background: rgba(0,0,0,.6); display: none; align-items: flex-end; justify-content: center; }
.modal-bg.on { display: flex !important; }
.modal-box { background: var(--paper); color: var(--ink); border-radius: var(--r) var(--r) 0 0; width: 100%; max-height: 88%; overflow-y: auto; animation: slideUp .25s ease; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-hd { padding: 20px 20px 16px; border-bottom: none; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--paper); z-index: 1; }
.modal-tt { font-family: 'Noto Sans KR', sans-serif; font-size: 18px; font-weight: 800; letter-spacing: -.03em; }
.modal-cl { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-bd { padding: 0 20px 20px; }
/* mbox 타입 모달 */
.mbg  { position: absolute; inset: 0; z-index: 990; background: rgba(0,0,0,.6); display: none; align-items: flex-end; justify-content: center; }
.mbg.on { display: flex !important; }
.mbox { background: var(--paper); color: var(--ink); border-radius: var(--r) var(--r) 0 0; width: 100%; max-height: 92%; overflow-y: auto; animation: slideUp .25s ease; }
.mhd { padding: 20px 20px 16px; border-bottom: none; display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--paper); z-index: 1; }
.mtt { font-family: 'Noto Sans KR', sans-serif; font-size: 18px; font-weight: 800; letter-spacing: -.03em; }
.mcl { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }
.mbd { padding: 0 20px 20px; overflow-y: auto; }
.mft { padding: 12px 20px; border-top: none; display: flex; gap: 10px; }

/* ── 반응형 ── */
@media (min-width: 480px) {
  .shell { max-width: 430px; margin: 0 auto; border-left: .5px solid var(--bd); border-right: .5px solid var(--bd); }
  .sw    { max-width: 430px; left: 50%; transform: translateX(-50%); }
}
@media (min-width: 768px) {
  body   { background: var(--paper3); }
  .shell { box-shadow: 0 0 40px rgba(0,0,0,.12); }
}

/* ── 다크모드 공통 보정 ── */
[data-theme="dark"] .fi,
:root:not([data-theme="light"]):where(@media (prefers-color-scheme:dark)) .fi { background: var(--paper2) !important; color: var(--ink) !important; border-color: var(--bd) !important; }
[data-theme="dark"] .fi::placeholder { color: var(--muted) !important; }
[data-theme="dark"] .fl, [data-theme="dark"] .fhint { color: var(--muted) !important; }
[data-theme="dark"] .bsm.o { background: var(--paper2) !important; color: var(--ink) !important; border-color: var(--bd) !important; }
[data-theme="dark"] .bsm.s { background: var(--stamp) !important; color: #fff !important; }
[data-theme="dark"] .modal-box, [data-theme="dark"] .mbox { background: var(--paper) !important; }
[data-theme="dark"] .modal-hd, [data-theme="dark"] .mhd { background: var(--paper) !important; border-color: var(--bd) !important; }
[data-theme="dark"] .modal-tt, [data-theme="dark"] .mtt { color: var(--ink) !important; }
[data-theme="dark"] .tabbar { background: var(--paper) !important; border-color: var(--bd) !important; }
[data-theme="dark"] .t2-item { background: var(--paper2) !important; border-color: var(--bd) !important; }
[data-theme="dark"] .t2-item.on.user-tab { background: var(--paper3) !important; }
[data-theme="dark"] .t2-item.on.user-tab .t2-lbl { color: var(--ink) !important; }
[data-theme="dark"] input[type="date"] { background: var(--paper2) !important; color: var(--ink) !important; border-color: var(--bd) !important; color-scheme: dark; }
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fi { background: var(--paper2) !important; color: var(--ink) !important; border-color: var(--bd) !important; }
  :root:not([data-theme="light"]) .bsm.o { background: var(--paper2) !important; color: var(--ink) !important; border-color: var(--bd) !important; }
  :root:not([data-theme="light"]) .tabbar { background: var(--paper) !important; border-color: var(--bd) !important; }
  :root:not([data-theme="light"]) .t2-item { background: var(--paper2) !important; border-color: var(--bd) !important; }
  :root:not([data-theme="light"]) .t2-item.on.user-tab { background: var(--paper3) !important; }
  :root:not([data-theme="light"]) .t2-item.on.user-tab .t2-lbl { color: var(--ink) !important; }
  :root:not([data-theme="light"]) input[type="date"] { background: var(--paper2) !important; color: var(--ink) !important; border-color: var(--bd) !important; color-scheme: dark; }
  :root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); }
  :root:not([data-theme="light"]) .modal-box, :root:not([data-theme="light"]) .mbox { background: var(--paper) !important; }
  :root:not([data-theme="light"]) .modal-hd, :root:not([data-theme="light"]) .mhd { background: var(--paper) !important; border-color: var(--bd) !important; }
}
