/* ปฏิทินจักรวาล — ธีมอวกาศ กระจกฝ้า ออกแบบสำหรับ iPhone เป็นหลัก */
:root {
  --bg: #0b0620;
  --text: #f3f0ff;
  --muted: #b9b2d9;
  --faint: #8a83ad;
  --glass: rgba(255, 255, 255, 0.08);
  --glass-strong: rgba(255, 255, 255, 0.14);
  --border: rgba(255, 255, 255, 0.16);
  --accent: #ff8fd6;
  --accent-2: #8fb4ff;
  --gold: #ffe08a;
  --danger: #ff7a8a;
  --radius: 20px;
  --tap: 44px;               /* ปุ่มกดสูงอย่างน้อย 44px ตามคำแนะนำของ Apple */
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Noto Sans Thai", "Leelawadee UI", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(ellipse 80% 50% at 15% 10%, rgba(140, 80, 255, 0.45), transparent 60%),
    radial-gradient(ellipse 70% 45% at 90% 35%, rgba(70, 120, 255, 0.35), transparent 60%),
    radial-gradient(ellipse 80% 50% at 40% 95%, rgba(255, 90, 190, 0.35), transparent 60%),
    linear-gradient(160deg, #120838 0%, #0b0620 55%, #1a0a35 100%);
  background-attachment: fixed;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

/* ---------- ส่วนหัว ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 16px) 10px calc(var(--safe-left) + 16px);
  background: linear-gradient(to bottom, rgba(11, 6, 32, 0.85), rgba(11, 6, 32, 0.55));
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
.sync-status { font-size: 12px; white-space: nowrap; }
.sync-status:not(:empty)::before { content: "· "; }
.sync-status[data-state="badToken"], .sync-status[data-state="error"] { color: #ffb4a8; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }

main {
  position: relative; z-index: 1;
  padding: 12px calc(var(--safe-right) + 14px) calc(var(--tabbar-h) + var(--safe-bottom) + 90px) calc(var(--safe-left) + 14px);
  max-width: 720px; margin: 0 auto;
  outline: none;
}

.banner {
  position: relative; z-index: 2; margin: 8px 14px 0; padding: 8px 12px;
  border-radius: 12px; background: rgba(255, 200, 90, 0.16); border: 1px solid rgba(255, 200, 90, 0.35); font-size: 14px;
}

/* ---------- การ์ดกระจกฝ้า ---------- */
.card {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 12px 0;
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 0; font-size: 16px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 4px 6px; }
.section-title h2 { margin: 0; font-size: 17px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 14px; }
.empty { color: var(--faint); text-align: center; padding: 14px 0; }

/* ---------- ปุ่ม ---------- */
button, .btn {
  font: inherit; color: inherit; cursor: pointer;
  min-height: var(--tap); border-radius: 14px;
  border: 1px solid var(--border); background: var(--glass-strong);
  padding: 0 16px;
  touch-action: manipulation;
}
button:active { transform: scale(0.97); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.icon-btn { min-width: var(--tap); padding: 0; font-size: 20px; border-radius: 50%; }
.btn-primary { background: linear-gradient(135deg, #b46bff, #ff7cc8); border: none; font-weight: 600; color: #fff; }
.btn-danger { color: var(--danger); border-color: rgba(255, 122, 138, 0.4); }
.btn-ghost { background: transparent; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 14px; }   /* ใช้คู่กับพื้นที่กดรอบ ๆ ที่กว้างพอ */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }

/* ---------- แถบเลือกวัน ---------- */
.daynav { display: flex; align-items: center; gap: 8px; }
.daynav .label { flex: 1; text-align: center; }
.daynav .label strong { display: block; font-size: 18px; }

/* ---------- กิจกรรมตอนนี้ ---------- */
.now-card { border-color: rgba(255, 143, 214, 0.55); background: linear-gradient(135deg, rgba(180, 107, 255, 0.22), rgba(255, 124, 200, 0.16)); }
.now-card .big { font-size: 22px; font-weight: 700; margin: 2px 0; }
.progress { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }

/* ---------- ไทม์ไลน์ตารางประจำวัน ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
/* แถวเดียว: "เวลาเริ่ม–สิ้นสุด | ไอคอน ชื่อกิจกรรม" มีเส้นคั่นบาง ๆ */
.timeline li {
  display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 6px;
  min-height: 50px; padding: 8px 12px; border-radius: 14px;
}
.timeline li + li { border-top: 1px solid rgba(255, 255, 255, 0.07); }
.timeline .t { font-variant-numeric: tabular-nums; color: #8fa8ff; font-size: 14px; white-space: nowrap; }
.timeline .ti { display: flex; align-items: center; gap: 8px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.timeline .ic { font-size: 18px; flex: none; }
.timeline .ti small { font-weight: 400; }
.timeline li.past .ti { color: var(--muted); }
.timeline li.current {
  border-top-color: transparent;
  background: linear-gradient(90deg, rgba(110, 90, 255, 0.28), rgba(150, 110, 255, 0.14));
  box-shadow: inset 0 0 0 1.5px rgba(150, 140, 255, 0.75), 0 0 18px rgba(120, 100, 255, 0.25);
}
.timeline li.current + li { border-top-color: transparent; }
/* หน้าแก้ตาราง: ทั้งแถวเป็นปุ่ม */
.timeline.editable li { display: block; padding: 0; }
.row-btn {
  display: grid; grid-template-columns: 104px 1fr 16px; align-items: center; gap: 6px;
  width: 100%; min-height: 50px; padding: 8px 10px; border: none; background: transparent; border-radius: 12px; text-align: left;
}
.chev { color: var(--faint); font-size: 20px; }
.banner.warn { margin: 10px 0; line-height: 1.6; }
.days-seg { grid-auto-columns: 1fr; }
.days-seg button { padding: 0; min-width: 0; }
.now-pill {
  display: inline-block; margin-left: 6px; padding: 1px 10px; border-radius: 99px; vertical-align: 1px;
  font-size: 12px; font-weight: 600; color: #fff; background: linear-gradient(135deg, #5b7bff, #8f6bff);
}

/* ---------- รายการนัด ---------- */
.appt { display: flex; gap: 12px; align-items: flex-start; padding: 10px 4px; border-radius: 14px; width: 100%; text-align: left; background: none; border: none; min-height: var(--tap); }
.appt + .appt { border-top: 1px solid rgba(255, 255, 255, 0.07); border-radius: 0; }
.appt .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 7px; flex: none; background: var(--cat, var(--gold)); box-shadow: 0 0 10px var(--cat, var(--gold)); }
.appt .body { flex: 1; min-width: 0; }
.appt .title { font-weight: 600; overflow-wrap: anywhere; }
.appt .meta { color: var(--muted); font-size: 14px; }
.appt .note { color: var(--faint); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; background: rgba(255, 255, 255, 0.1); border: 1px solid var(--border); white-space: nowrap; }
.pill.soon { background: rgba(255, 143, 214, 0.2); border-color: rgba(255, 143, 214, 0.5); }
.pill.today { background: rgba(255, 224, 138, 0.22); border-color: rgba(255, 224, 138, 0.6); color: var(--gold); }

/* ---------- ปฏิทินรายเดือน ---------- */
.month-head { display: flex; align-items: center; gap: 8px; }
.month-head h2 { flex: 1; text-align: center; margin: 0; font-size: 18px; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 10px; }
.grid .dow { text-align: center; font-size: 13px; color: var(--faint); padding: 4px 0; }
.grid .dow.sun { color: #ff9db0; }
.day {
  position: relative; aspect-ratio: 1 / 1.05; min-height: var(--tap); padding: 0;
  border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-variant-numeric: tabular-nums;
}
.day.other { opacity: 0.35; }
.day.today { border-color: var(--gold); color: var(--gold); font-weight: 700; }
.day.selected { background: linear-gradient(135deg, rgba(180, 107, 255, 0.55), rgba(255, 124, 200, 0.45)); color: #fff; }
.day.off { background: rgba(95, 211, 141, 0.13); color: #9af0bf; }
.day.off.selected { color: #fff; }
.legend { display: flex; align-items: center; gap: 6px; margin: 10px 2px 0; }
.legend .sw { display: inline-block; flex: 0 0 auto; align-self: center; width: 12px; height: 12px; border-radius: 4px; margin-left: 6px; }
.legend .sw.off { background: rgba(95, 211, 141, 0.45); }
.legend .sw.dot-appt { border-radius: 50%; width: 8px; height: 8px; background: var(--gold); }
.day .dots { display: flex; gap: 3px; height: 6px; }
.day .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--c, var(--gold)); box-shadow: 0 0 6px var(--c, var(--gold)); }

/* ---------- ค้นหา / ฟอร์ม ---------- */
input, select, textarea {
  font: inherit;
  font-size: 16px;           /* 16px ขึ้นไป iOS จะไม่ซูมเข้าเวลาแตะช่องกรอก */
  color: var(--text);
  width: 100%; min-height: var(--tap);
  padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(10, 5, 30, 0.55);
}
textarea { min-height: 84px; resize: vertical; }
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; }
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.check { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: var(--tap); padding: 0 14px; border-radius: 99px; font-size: 15px; }
.chip[aria-pressed="true"] { background: linear-gradient(135deg, rgba(180, 107, 255, 0.7), rgba(255, 124, 200, 0.6)); border-color: transparent; color: #fff; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); }
.seg button { border: none; background: transparent; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--glass-strong); box-shadow: 0 0 0 1px var(--border); font-weight: 600; }

/* ---------- ปุ่มลอยและเมนูล่าง ---------- */
.fab {
  position: fixed; z-index: 6;
  right: calc(var(--safe-right) + 16px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  min-height: 52px; padding: 0 20px; border-radius: 99px; border: none;
  font-weight: 700; font-size: 16px; color: #fff;
  background: linear-gradient(135deg, #9b5cff, #ff6fbf);
  box-shadow: 0 10px 30px rgba(255, 111, 191, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.25) inset;
}
/* เมนูล่างแบบแคปซูลลอย แท็บที่เลือกเป็นปุ่มม่วงไล่สี */
.tabbar {
  position: fixed; z-index: 6;
  left: calc(var(--safe-left) + 10px); right: calc(var(--safe-right) + 10px);
  bottom: calc(var(--safe-bottom) + 8px);
  max-width: 700px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 6px; border-radius: 26px;
  background: rgba(20, 14, 52, 0.78);
  -webkit-backdrop-filter: blur(20px) saturate(150%); backdrop-filter: blur(20px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.tab {
  display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; border: none; background: transparent; border-radius: 20px;
  font-size: 15px; color: var(--muted);
}
.tab span { font-size: 18px; line-height: 1; }
.tab[aria-current="page"] {
  color: #fff; font-weight: 700;
  background: linear-gradient(135deg, #6a5cff, #9a6bff);
  box-shadow: 0 4px 16px rgba(120, 100, 255, 0.5);
}

/* ---------- แผ่นเลื่อน (dialog) ---------- */
.sheet {
  width: 100%; max-width: 640px; max-height: calc(100dvh - var(--safe-top) - 24px);
  margin: auto auto 0; padding: 0; border: none; border-radius: 26px 26px 0 0;
  color: var(--text); background: rgba(24, 14, 58, 0.94);
  -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; animation: up 0.22s ease-out; }
.sheet::backdrop { background: rgba(5, 2, 15, 0.55); }
.sheet .sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.sheet .sheet-head h2 { flex: 1; margin: 0; font-size: 18px; }
.sheet .sheet-body { overflow-y: auto; padding: 4px 16px calc(var(--safe-bottom) + 20px); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.steps { padding-left: 1.3em; margin: 6px 0; }
.steps li { margin: 6px 0; }
kbd { font: inherit; padding: 0 6px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); border: 1px solid var(--border); }

.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 80px);
  padding: 10px 16px; border-radius: 14px; background: rgba(30, 18, 70, 0.95); border: 1px solid var(--border);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ผู้ใช้ตั้งให้ลดการเคลื่อนไหว → ปิดแอนิเมชันทั้งหมด */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
