/*
 * reset ตัวอักษร โครงหน้า และคุณภาพพื้นฐานที่ทุกหน้าต้องมี
 * ห้ามมีค่าสีในไฟล์นี้ ใช้ var(--…) เท่านั้น
 */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

h1 { font-size: var(--text-xl); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
h2 { font-size: var(--text-lg); font-weight: var(--weight-semibold); line-height: var(--leading-tight); }
h3 { font-size: var(--text-md); font-weight: var(--weight-semibold); }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

img, svg { max-width: 100%; }

/* ตัวเลขทุกตัวในแอปใช้ฟอนต์ความกว้างเท่ากัน หลักจึงตรงกันทุกแถว */
.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  letter-spacing: -0.01em;
}

/* หางสตางค์ — บาทเต็มน้ำหนัก สตางค์เล็กลงจางลง */
.num-tail {
  font-size: 0.78em;
  color: var(--text-3);
}

.num-positive { color: var(--positive); }
.num-negative { color: var(--negative); }

/* focus ที่มองเห็นชัดทุกที่ ห้ามลบทิ้ง */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- โครงหน้า ---- */

.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.app-nav {
  border-right: 1px solid var(--border);
  background: var(--surface-1);
  padding: var(--space-5) var(--space-3);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

/* คอลัมน์ขวาของโครงหน้า — min-width: 0 กันตารางกว้างๆ ดันกริดให้ล้นจอ */
.app-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-main {
  padding: var(--space-6);
  max-width: 1280px;
  width: 100%;
}

/* ---- แถบสถานะการซิงก์ ----
 * ขึ้นเฉพาะตอนมีอะไรให้รู้จริงๆ สถานะปกติต้องเงียบ
 * ไม่งั้นมันจะกลายเป็นของประดับที่ไม่มีใครอ่าน แล้วตอนสำคัญจริงก็ถูกมองข้าม
 */
.sync-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-6);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: var(--text-sm);
}
.sync-bar[hidden] { display: none; }
.sync-bar-offline { background: var(--warning-soft); color: var(--warning); }
.sync-bar-conflict { background: var(--negative-soft); color: var(--negative); }
.sync-bar-error { background: var(--negative-soft); color: var(--negative); }

/* ---- หน้าจอระหว่างรอตรวจข้อมูลคลาวด์ ---- */
.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 100vh;
  color: var(--text-2);
}
.boot-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  color: var(--text-1);
}
.boot-note { font-size: var(--text-sm); }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
}

.page-head p {
  color: var(--text-2);
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}

.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-2); }
/* ปุ่มในแถวเดียวกันต้องขึ้นบรรทัดใหม่ได้ ไม่งั้นบนมือถือมันจะดันหน้าให้กว้างเกินจอ */
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

@media (max-width: 1199px) {
  .app { grid-template-columns: 64px minmax(0, 1fr); }
  .app-nav { padding: var(--space-4) var(--space-2); }
  .app-main { padding: var(--space-5) var(--space-4); }
  .sync-bar { padding: var(--space-2) var(--space-4); }
}

@media (max-width: 767px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    height: auto;
    max-height: 64px;
    display: flex;
    align-items: center;
    gap: var(--space-1);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-right: 0;
    border-top: 1px solid var(--border);
    padding: var(--space-2);
    z-index: 20;
  }
  .app-nav .nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .app-main { padding: var(--space-4) var(--space-3) var(--space-8); }
  .sync-bar { padding: var(--space-2) var(--space-3); flex-wrap: wrap; }
  .page-head { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- หน้าล็อก ----
 * เต็มจอและไม่มีทางออกอื่น — ปุ่มเดียวที่มีคือปลดล็อก
 * ไม่มีลิงก์ "ข้ามไปก่อน" เพราะม่านที่เปิดข้ามได้ก็ไม่ใช่ม่าน
 */

.lock-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-5);
  background: var(--surface-0);
}

.lock-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 320px;
  padding: var(--space-7) var(--space-6);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  text-align: center;
}

.lock-title { font-size: var(--text-2xl); font-weight: var(--weight-semibold); }
.lock-note { font-size: var(--text-sm); color: var(--text-2); }

.lock-input {
  text-align: center;
  letter-spacing: .4em;
  font-size: var(--text-xl);
  min-height: 48px;
}

.lock-message { font-size: var(--text-sm); min-height: 1.4em; }
