/* shell.css — เปลือก "มีเธอ (Meturr)" · mobile-first (375 ก่อน) ตาม nav-spec ยู
   component ทั่วไป (card/btn/inp/badge/av/logo) มาจาก /assets/nova.css แล้ว
   กฎ: สีจาก NOVA token/var เท่านั้น (ห้าม hardcode hex) · Tabler icon · light+dark
   ─────────────────────────────────────────────────────────────────────────
   โครง DOM (nav-spec §3.1):
     .me-shell[data-view="hub|module"]
       ├─ aside.me-rail      (switcher · แสดง ≥768)
       ├─ header.me-topbar   (กลับ hub · แสดง <768 ตอน data-view="module")
       └─ main.me-content → section.me-hub  +  #module-root
   1 element (data-view) คุม state → CSS จัด show/hide ตาม view + breakpoint */

/* ===== base (mobile <768 = ฐาน) ===== */
#app { min-height: 100dvh; }
.me-shell { min-height: 100dvh; }
.me-content { min-height: 100dvh; }

/* hub เห็นตอน view=hub · module-root เห็นตอน view=module (สลับด้วย data-view) */
.me-shell[data-view="hub"]    #module-root { display: none; }
.me-shell[data-view="module"] .me-hub      { display: none; }

/* ===== login (กลาง · reuse ค่าที่พิสูจน์แล้วจาก MeDay) ===== */
.login-wrap {
  max-width: 380px; margin: 0 auto; padding: 56px 24px;
  min-height: 100dvh; display: flex; flex-direction: column; justify-content: center;
}
.login-logo { width: 56px; height: 56px; font-size: 26px; margin: 0 auto 12px; }
.brand-mark { display: grid; place-items: center; }
.login-wrap h1 { text-align: center; }
.login-wrap .lead { text-align: center; margin: 6px 0 28px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--text-2); font-size: 12px; margin: 18px 0; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }
.eye-wrap { position: relative; }
.eye-wrap .inp { padding-right: 44px; }
.eye-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border: none; background: transparent; color: var(--text-2);
  cursor: pointer; display: grid; place-items: center; font-size: 18px;
}
.login-links { text-align: center; margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.spin { display: inline-block; animation: me-spin .8s linear infinite; }
@keyframes me-spin { to { transform: rotate(360deg); } }

/* ===== topbar (mobile · เห็นเฉพาะตอนอยู่ในโมดูล) — nav-spec §3.2 ===== */
.me-topbar { display: none; }
.me-shell[data-view="module"] .me-topbar {
  display: flex; align-items: center; gap: 8px;
  position: fixed; inset: 0 0 auto 0; height: 48px; padding: 0 8px 0 4px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  z-index: 50;   /* < sheet(4000)/modal(2000) ของโมดูล เสมอ */
}
.me-shell[data-view="module"] #module-root { padding-top: 48px; }  /* กันเนื้อหาลอดใต้ topbar */
.topbar-back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; padding: 0 8px; border: none; background: transparent;
  color: var(--text); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.topbar-back i { font-size: 20px; color: var(--text-2); }
.topbar-title { flex: 1; min-width: 0; display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title i { color: var(--primary-solid); }
.topbar-slot { margin-left: auto; display: inline-flex; align-items: center; }

/* ===== rail (switcher · ซ่อนบน mobile · เห็น ≥768) ===== */
.me-rail { display: none; }

/* ===== home hub ===== */
.me-hub { max-width: 720px; margin: 0 auto; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.hub-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.hub-greet { flex: 1; min-width: 0; }
.hub-hello { margin: 0; font-size: 20px; font-weight: 600; }
.hub-date  { margin: 2px 0 0; color: var(--text-2); font-size: 13px; }

.hub-grid { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: stretch; }

/* การ์ดโมดูล (nav-spec §3.3 · DS Card) — ทั้งการ์ด = ปุ่ม · ❌ ห้าม border-left accent */
.hub-card {
  display: flex; flex-direction: column; gap: 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
  font: inherit; color: var(--text); cursor: pointer; min-height: 44px;
  transition: border-color .12s, transform .05s;
}
.hub-card:hover  { border-color: var(--border-strong); }
.hub-card:active { transform: scale(.99); }
:root[data-theme="dark"] .hub-card { box-shadow: none; }
.hub-card-head { display: flex; align-items: center; gap: 12px; }
.hub-card-title { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; }
.hub-card-body { color: var(--text-2); }
.hub-card.is-edit { cursor: default; }
.hub-card.is-edit:active { transform: none; }
.me-summary-line { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.me-summary-line i { color: var(--primary-solid); }

/* ===== net worth card (เฟส 2a · "ทรัพย์สินสุทธิ" บนสุด hub · design §7) =====
   neutral: ตัวเลขล้วน ไม่ตัดสิน · หนี้ใช้ --alert แค่แยกประเภท ไม่ใช่ "ดุ"
   ❌ ห้าม border-left accent · สี CSS var ล้วน (light+dark) */
.networth-slot { margin-bottom: 16px; }
.networth-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
:root[data-theme="dark"] .networth-card { box-shadow: none; }
.nw-head { display: flex; align-items: center; gap: 8px; }
.nw-title { font-size: 13px; font-weight: 500; color: var(--text-2); }
.nw-info { display: inline-flex; align-items: center; color: var(--text-2); cursor: help; }
.nw-info i { font-size: 16px; }
.nw-total {
  font-size: 24px; font-weight: 600; margin: 6px 0 0; color: var(--text);
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.nw-asof { margin: 4px 0 0; font-size: 11px; color: var(--text-2); overflow-wrap: anywhere; }
.nw-divider { height: 1px; background: var(--border); margin: 16px 0; }
.nw-breakdown { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.nw-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 14px; }
.nw-row-label { color: var(--text-2); min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.nw-row-amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.nw-row.is-debt .nw-row-amt { color: var(--alert); }
.nw-delay {
  display: inline-block; font-size: 11px; color: var(--warm);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; margin-left: 4px;
  white-space: nowrap; vertical-align: middle;
}

/* ปุ่มจัดเรียง (หัว hub) */
.hub-edit {
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer; font-size: 18px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
}
.hub-edit:hover { border-color: var(--border-strong); color: var(--text); }

/* reorder ▲▼ (edit-mode · hit-area ≥44px) */
.hub-move { display: inline-flex; gap: 4px; margin-left: auto; }
.hub-move-btn {
  width: 44px; height: 44px; border-radius: 10px; cursor: pointer; font-size: 18px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.hub-move-btn:hover { border-color: var(--border-strong); }
.hub-move-btn:disabled { opacity: .4; cursor: default; }

/* skeleton card (loading me_core · nav-spec §3.5) */
.hub-card.is-skeleton { pointer-events: none; }
.sk-line { display: block; height: 12px; border-radius: 6px; }
.hub-card-head .sk-line { flex: 1; }
.sk-line.short { width: 60%; height: 11px; }
.hub-ico.sk { border-radius: 10px; }

/* icon-box = tint จาง (decorative · PROTOTYPE-TEMP รอ token สีโมดูล nav-spec §5 Q1) */
.hub-ico {
  width: 40px; height: 40px; border-radius: 10px; font-size: 20px;
  color: var(--tint, var(--primary-solid));
  background: color-mix(in srgb, var(--tint, var(--primary-solid)) 12%, transparent);
}

/* empty state (T2 · nav-spec §3.5) — tone เป็นมิตร ไม่ตัดสิน */
.hub-empty { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hub-empty-ico { width: 56px; height: 56px; border-radius: 16px; font-size: 28px;
  color: var(--primary-solid); background: color-mix(in srgb, var(--primary-solid) 12%, transparent); }
.hub-empty .lead { max-width: 320px; }

/* ===== ≥768 (tablet) — rail 72px ถาวร + hub 2 คอลัมน์ ===== */
@media (min-width: 768px) {
  .me-shell { display: flex; }
  .me-content { flex: 1; min-width: 0; }

  .me-rail {
    display: flex; flex-direction: column; align-items: stretch; gap: 4px;
    width: 72px; flex-shrink: 0; position: sticky; top: 0; height: 100dvh;
    padding: 12px 8px; background: var(--surface); border-right: 1px solid var(--border);
  }
  .rail-modules { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .rail-foot { display: flex; flex-direction: column; gap: 4px; margin-top: auto; }

  .rail-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    min-height: 56px; padding: 8px 4px; border: none; border-radius: 12px; cursor: pointer;
    background: transparent; color: var(--text-2); font: inherit;
  }
  .rail-item:hover { background: var(--surface-2); }
  .rail-ico { display: grid; place-items: center; width: 28px; height: 28px; font-size: 22px;
    color: var(--tint, inherit); }
  .rail-label { font-size: 11px; font-weight: 500; line-height: 1.1; text-align: center;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rail-mini { min-height: 44px; }
  .rail-mini .rail-ico { font-size: 20px; }
  .rail-item.active {
    color: var(--primary-solid); font-weight: 600;
    background: color-mix(in srgb, var(--primary-solid) 12%, transparent);
  }
  .rail-item.active .rail-ico { color: var(--primary-solid); }

  /* ≥768 กลับ hub ด้วย rail → ไม่ใช้ topbar (แม้ view=module) */
  .me-shell[data-view="module"] .me-topbar { display: none !important; }
  .me-shell[data-view="module"] #module-root { padding-top: 0; }

  .me-hub { max-width: 880px; padding: 32px 24px; }
  .hub-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}

/* ===== ≥1024 (desktop) — hub 2–3 คอลัมน์ + พื้นที่กว้าง ===== */
@media (min-width: 1024px) {
  .me-hub { max-width: 1040px; }
  .hub-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ===== transition เข้าโมดูล (nav-spec §3.4) ===== */
/* mobile <768 = slide-in (drill-down) · ≥768 = fade (crossfade content) */
.me-enter { animation: me-enter-slide .22s ease; }
@keyframes me-enter-slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 768px) {
  .me-enter { animation: me-enter-fade .15s ease; }
  @keyframes me-enter-fade { from { opacity: 0; } to { opacity: 1; } }
}

/* ===== a11y: ลด motion ===== */
@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 1.6s; }
  .hub-card { transition: none; }
  .me-enter { animation: none; }   /* ตัด slide/fade → เข้าทันที */
}

/* focus ring (keyboard · a11y) — teal ตาม DS */
.rail-item:focus-visible, .hub-card:focus-visible, .topbar-back:focus-visible, .eye-btn:focus-visible {
  outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-solid) 30%, transparent);
}
