/* style.css — โครงหน้า/โมดัลของ webapp (สีจาก themes.css, คอมโพเนนต์จาก components.css ซึ่งก๊อปจาก LIFF) */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { background: var(--t-bg); }
body {
  font-family: 'Krub', 'Sarabun', sans-serif; background: var(--t-bg); color: var(--t-text);
  min-height: 100vh; max-width: 480px; margin: auto; transition: background .25s, color .25s;
  /* Krub 400 บางเกินไปบนจอเล็ก → ใช้ 600 เป็นน้ำหนักปกติ (ปรับที่ --fw ตัวเดียว: 400 บาง · 500 ปกติใหม่ · 600 หนา) */
  font-weight: var(--fw, 600); -webkit-font-smoothing: antialiased;
}
a { color: var(--t-accent-text); }
button { font-family: inherit; }
input, textarea, select { font-weight: inherit; }

/* Loading */
#loading { display: flex; flex-direction: column; align-items: center; justify-content: center;
           min-height: 100vh; gap: 12px; color: var(--t-accent-text); }
.spinner { width: 40px; height: 40px; border: 3px solid var(--t-border); border-top-color: var(--t-accent);
           border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* หน้า login / in-app notice */
.screen { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
          gap: 14px; padding: 32px 24px; text-align: center; }
.screen .btn { width: auto; }
.logo { font-size:calc(56px * var(--fs, 1)); line-height: 1; }
.screen h1 { font-size:calc(26px * var(--fs, 1)); }
.lead { font-size:calc(16px * var(--fs, 1)); }
.muted { color: var(--t-muted); }
.small { font-size:calc(13px * var(--fs, 1)); }
.error { color: var(--t-red); min-height: 1.2em; font-size:calc(14px * var(--fs, 1)); }

/* App shell */
#app { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.header { background: var(--t-header); color: var(--t-on-header); border-bottom: 1px solid var(--t-border);
          padding: calc(14px + env(safe-area-inset-top)) 16px 12px; position: sticky; top: 0; z-index: 10; }
.header { display: flex; align-items: center; gap: 8px; }
.header h1 { font-size:calc(18px * var(--fs, 1)); font-weight: 700; }
.header .badge { margin-left: auto; font-size: calc(12px * var(--fs, 1)); background: color-mix(in srgb, currentColor 16%, transparent); padding: 2px 8px; border-radius: 20px; }
#view { padding-bottom: 8px; }

/* หัวหน้าประวัติ: ชิปเลือกรถ (ซ้าย) + ปุ่มดาวน์โหลด/รายงาน (ขวา) */
.header-hist { padding: calc(10px + env(safe-area-inset-top)) 10px 10px 12px; gap: 4px; }
.hdr-car { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer;
           background: var(--t-card2); border: 0; border-radius: 16px; padding: 7px 12px 7px 8px; color: var(--t-text); font-family: inherit; }
.hdr-car:not([data-act]) { cursor: default; }
.hc-ic { width: 40px; height: 40px; flex: none; border-radius: 50%; background: var(--t-card); display: flex; align-items: center;
         justify-content: center; font-size: calc(22px * var(--fs, 1)); }
.hc-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hc-txt b { font-size: calc(18px * var(--fs, 1)); font-weight: 700; line-height: 1.25; }
.hc-txt small { font-size: calc(13px * var(--fs, 1)); opacity: .88; line-height: 1.3; }
.hc-arr svg { width: 24px; height: 24px; display: block; opacity: .9; }
.hdr-ic { width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center;
          background: none; border: 0; border-radius: 50%; color: var(--t-on-header); cursor: pointer; }
.hdr-ic:active { background: color-mix(in srgb, currentColor 16%, transparent); }
.hdr-ic svg { width: 26px; height: 26px; }

/* Bottom nav: ประวัติ | ชาร์จ (ปุ่มกลมใหญ่ลอยเด่น) | ตั้งค่า */
.nav { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px;
       display: flex; align-items: flex-end; background: var(--t-card); border-top: 1px solid var(--t-border);
       padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
.nav-btn { flex: 1; padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px;
           background: none; border: 0; font-size:calc(12px * var(--fs, 1)); color: var(--t-muted); cursor: pointer; }
.nav-btn .icon { width: calc(24px * var(--fs, 1)); height: calc(24px * var(--fs, 1)); }
.nav-btn.active { font-weight: 700; }
.nav-fab { padding-top: 0; margin-top: -30px; gap: 4px; }
.fab-circle { width: 62px; height: 62px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--t-on-charge);
              background: var(--t-charge);
              box-shadow: 0 6px 16px rgba(0,0,0,.28), 0 0 0 5px var(--t-card); transition: transform .15s; }
.fab-circle svg { width: 34px; height: 34px; }
.nav-fab:active .fab-circle { transform: scale(.93); }
.nav-fab { color: var(--t-text); font-weight: 700; }
.nav-btn.active { color: var(--t-accent-text); }

/* คำอธิบายแอปบนหน้าแรก (อ่านได้โดยไม่ต้องล็อกอิน) */
.about { max-width: 480px; margin: 0 auto; padding: 8px 24px 48px; line-height: 1.75; font-size: calc(14px * var(--fs, 1)); }
.about h2 { font-size: calc(16px * var(--fs, 1)); margin-bottom: 6px; }
.about ul { padding-left: 20px; margin: 8px 0; }
.about p { margin-top: 8px; }

/* จอเล็ก/tablet: หน้า login เป็นคอลัมน์ — ปุ่ม "แจ๋วปลั๊กคืออะไร" เลื่อนการ์ดอธิบายลงมาใต้ฟอร์ม (ขยายด้วย grid rows 0fr→1fr) */
body[data-screen="login"] { display: flex; flex-direction: column; }
body[data-screen="login"] #login { flex: 1 0 auto; min-height: 0; }
.login-note { margin-top: 4px; }
.login-links { margin-top: -6px; }
.login-links .link-btn { text-decoration: none; font-weight: 600; padding: 4px 2px; }
#about { max-width: 480px; margin: 0 auto; width: 100%; padding: 0 16px; }
.about-clip { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .35s ease; }
.about-clip > .about-card { overflow: hidden; min-height: 0; opacity: 0; transform: translateY(-8px);
  transition: opacity .3s ease, transform .35s ease; }
#about.open .about-clip { grid-template-rows: 1fr; }
#about.open .about-card { opacity: 1; transform: none; }
#about.open { padding-bottom: 28px; }
.about-card { padding: 0 20px; }
.about-card > h2 { margin-top: 18px; }
.about-card > :last-child { margin-bottom: 18px; }
.about-card { background: var(--t-card); border: 1px solid var(--t-border); border-radius: 18px;
  box-shadow: 0 8px 28px rgba(0,0,0,.08); text-align: left; }
@media (prefers-reduced-motion: reduce) { .about-clip, .about-card { transition: none; } }

/* หน้า login ตามขนาดจอ (หน้าตัวแอปหลังล็อกอินยังเป็นคอลัมน์เดียวตามเดิม)
   tablet: คอลัมน์เดียวกว้างขึ้น · desktop: แผงแนะนำแอปซ้าย + ฟอร์ม login ขวา */
@media (min-width: 600px) and (max-width: 899.98px) {
  body[data-screen="login"] { max-width: 560px; }
}
@media (min-width: 900px) {
  body[data-screen="login"] { max-width: none; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
  body[data-screen="login"] #login { grid-column: 2; grid-row: 1; }
  body[data-screen="login"] #about {
    grid-column: 1; grid-row: 1; max-width: none; margin: 0; padding: 64px clamp(40px, 6vw, 96px);
    display: flex; flex-direction: column; justify-content: center; font-size: calc(16px * var(--fs, 1));
    background: var(--t-card); border-right: 1px solid var(--t-border);
  }
  /* desktop: การ์ดกลายเป็นเนื้อหาของแผงซ้าย เปิดตลอด ไม่ต้องมีปุ่ม */
  .about-link { display: none; }
  body[data-screen="login"] #about .about-clip { grid-template-rows: 1fr; }
  body[data-screen="login"] #about .about-card { opacity: 1; transform: none; background: transparent; border: 0; box-shadow: none; padding: 0; overflow: visible; }
  body[data-screen="login"] #about .about-card > h2 { margin-top: 0; }
  body[data-screen="login"] #about .about-card > :last-child { margin-bottom: 0; }
  body[data-screen="login"] #about h2 { font-size: calc(26px * var(--fs, 1)); margin-bottom: 12px; line-height: 1.3; text-wrap: balance; }
  body[data-screen="login"] #about ul { list-style: none; padding: 0; margin: 18px 0; }
  body[data-screen="login"] #about li { background: var(--t-card2); border-radius: 12px; padding: 11px 16px; margin: 8px 0; }
}

/* Misc */
.empty { text-align: center; padding: 36px 16px; color: var(--t-muted); }
.empty .big { font-size:calc(40px * var(--fs, 1)); margin-bottom: 6px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--t-card2); object-fit: cover; }
.mono { font-family: monospace; font-size:calc(12px * var(--fs, 1)); color: var(--t-muted); }
.pill { display: inline-block; margin-top: 4px; padding: 3px 10px; border-radius: 20px; font-size:calc(12px * var(--fs, 1)); font-weight: 700; }
textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--t-border); border-radius: 10px;
           background: var(--t-card2); color: var(--t-text); font-size:calc(15px * var(--fs, 1)); font-family: inherit; resize: vertical; }

.form-error { display: none; color: var(--t-red); font-size:calc(13px * var(--fs, 1)); font-weight: 600; margin-bottom: 12px; }
.form-error.show { display: block; }
.link-btn { background: none; border: 0; color: var(--t-accent-text); font-size:calc(13px * var(--fs, 1)); cursor: pointer; text-decoration: underline; }

/* Modal (picker / confirm) */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; justify-content: center; align-items: flex-end; }
.overlay.center { align-items: center; padding: 24px; }
.sheet { background: var(--t-card); color: var(--t-text); width: 100%; max-width: 480px; max-height: 80vh; overflow-y: auto;
         border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.overlay.center .sheet { border-radius: 20px; max-width: 340px; text-align: center; }
.sheet h3 { font-size:calc(16px * var(--fs, 1)); margin-bottom: 8px; }
.sheet .sheet-icon { font-size:calc(36px * var(--fs, 1)); margin-bottom: 6px; }
.sheet p { white-space: pre-line; margin-bottom: 14px; color: var(--t-muted); font-size:calc(14px * var(--fs, 1)); }
.picker-row { display: flex; align-items: center; gap: 10px; padding: 13px 12px; border-radius: 12px; cursor: pointer; }

#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
         background: var(--t-text); color: var(--t-card); padding: 10px 16px; border-radius: 12px; font-size:calc(14px * var(--fs, 1));
         opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90%; }
#toast.show { opacity: 1; }

/* หน้า privacy / terms */
.doc { padding: 24px 20px 48px; line-height: 1.7; }
.doc h1 { font-size:calc(22px * var(--fs, 1)); margin-bottom: 4px; }
.doc h2 { font-size:calc(16px * var(--fs, 1)); margin: 20px 0 6px; }
.doc ul { padding-left: 20px; }
