/* component ที่ใช้ซ้ำได้ทุกหน้า: ปฏิทิน, tooltip, ช่องรหัสผ่าน, combobox, dialog, toast, loading */
/* ---------- ปุ่มเลือกวันที่ ---------- */
.picker-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 170px; font-weight: 500; white-space: nowrap; }
.picker-btn svg { color: var(--primary); flex: none; }
.date-field { width: 100%; min-width: 0; justify-content: flex-start; padding: 12px 16px; font-weight: 400; box-shadow: var(--in); }
.date-field:hover { color: inherit; }

/* ---------- tooltip ---------- */
.tip { position: fixed; z-index: 300; max-width: 220px; padding: 6px 12px; border-radius: 10px; background: var(--toast-bg); color: var(--toast-fg); font-size: 12.5px; font-weight: 500; line-height: 1.4; pointer-events: none; white-space: nowrap; box-shadow: 0 6px 16px rgba(0, 0, 0, .18); animation: tip-in .15s ease-out; }
@keyframes tip-in { from { opacity: 0; transform: translateY(-3px); } }

/* ---------- calendar popover ---------- */
.cal { position: fixed; z-index: 60; width: min(300px, calc(100vw - 16px)); padding: 16px; border-radius: 22px; background: var(--bg); box-shadow: 10px 10px 26px var(--dark), -10px -10px 26px var(--light); animation: pop .15s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head .btn-icon { width: 34px; height: 34px; border-radius: 11px; }
.cal-title { border: 0; background: none; font-weight: 600; font-size: 15px; padding: 6px 14px; border-radius: 11px; cursor: pointer; transition: box-shadow .15s; }
.cal-title:not(:disabled):hover { color: var(--primary); box-shadow: var(--out-sm); }
.cal-title:disabled { cursor: default; color: var(--text); }
.cal-grid { display: grid; gap: 4px; }
.cal-grid.day { grid-template-columns: repeat(7, 1fr); }
.cal-grid.month, .cal-grid.year { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cal .wd { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.cal .wd:first-child { color: var(--expense); }
.cal-grid button { border: 0; background: transparent; border-radius: 11px; cursor: pointer; aspect-ratio: 1; font-size: 14px; transition: box-shadow .12s, color .12s; }
.cal-grid.month button, .cal-grid.year button { aspect-ratio: auto; padding: 12px 0; }
.cal-grid button:hover { box-shadow: var(--out-sm); color: var(--primary); }
.cal-grid button.out { color: var(--faint); }
.cal-grid button.today { color: var(--primary); font-weight: 700; box-shadow: var(--in); }
.cal-grid button.sel { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; font-weight: 600; box-shadow: 4px 4px 10px rgba(124, 92, 255, .35); }
/* ---------- ปุ่มดูรหัสผ่าน ---------- */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 48px; }
.pw-eye { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: color .15s, box-shadow .15s; }
.pw-eye:hover { color: var(--primary); }
.pw-eye:active { box-shadow: var(--in); }
.pw-eye[aria-pressed="true"] { color: var(--primary); }
.pw-eye .i-off, .pw-eye[aria-pressed="true"] .i-on { display: none; }
.pw-eye[aria-pressed="true"] .i-off { display: block; }
input::-ms-reveal { display: none; }

/* ---------- เงื่อนไขรหัสผ่าน ---------- */
.pw-rules { list-style: none; margin: 10px 4px 0; padding: 0; display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.pw-rules li { display: flex; align-items: center; gap: 8px; transition: color .15s; }
.pw-rules li::before { content: ''; width: 16px; height: 16px; flex: none; border-radius: 50%; box-shadow: var(--in); display: grid; place-items: center; font-size: 10px; font-weight: 700; }
.pw-rules li.ok { color: var(--income); }
.pw-rules li.bad { color: var(--expense); }
.pw-rules li.bad::before { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E") center / 10px no-repeat, var(--expense); box-shadow: none; }
.pw-rules li.warn { animation: pw-warn 1.2s ease-out; }
@keyframes pw-warn { 0%, 60% { color: var(--expense); } }
.pw-rules li.ok::before { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / 11px no-repeat, var(--income); box-shadow: none; }

/* ---------- combobox หมวดหมู่ ---------- */
.combo { position: relative; }
.combo input { padding-right: 46px; padding-left: 52px; }
.combo-icon { position: absolute; left: 8px; bottom: 6px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 18px; box-shadow: var(--out-sm); pointer-events: none; }
.opt-ico { width: 32px; height: 32px; flex: none; border-radius: 10px; display: grid; place-items: center; font-size: 17px; box-shadow: var(--in); }
.opt-label { flex: 1; }
.combo-icon, .opt-ico, .tx .ico { color: var(--primary); }
.opt-ico svg { width: 17px; height: 17px; }
.combo-caret { position: absolute; right: 8px; bottom: 7px; width: 32px; height: 32px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: transform .2s, color .15s; }
.combo-caret:hover { color: var(--primary); }
.combo input[aria-expanded="true"] + .combo-caret { transform: rotate(180deg); color: var(--primary); }
.combo-menu { position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 8px); max-height: 240px; overflow-y: auto; overscroll-behavior: contain; padding: 8px; border-radius: 18px; background: var(--bg); box-shadow: 10px 10px 26px var(--dark), -10px -10px 26px var(--light); animation: pop .15s ease-out; scrollbar-width: thin; scrollbar-color: var(--faint) transparent; }
.combo-menu.up { top: auto; bottom: calc(100% + 8px); }
.combo-opt { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; cursor: pointer; transition: box-shadow .12s, color .12s; }
.combo-opt.active { box-shadow: var(--out-sm); color: var(--primary); }
@media (hover: hover) { .combo-opt:hover { box-shadow: var(--out-sm); color: var(--primary); } }
.combo-opt.sel { color: var(--primary); font-weight: 600; }
.combo-opt.sel::after { content: ''; width: 16px; height: 16px; flex: none; background: currentColor; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat; }
.combo-opt.new { color: var(--muted); font-size: 13px; }
.combo-opt.new b { color: var(--primary); }
.cal-foot { display: flex; justify-content: center; margin-top: 14px; }
.cal-foot .btn { padding: 7px 18px; font-size: 14px; }

/* ---------- Recovery Key ---------- */
.mono { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; letter-spacing: .04em; }
.rk-note { margin: -8px 0 16px; font-size: 14px; color: var(--muted); line-height: 1.6; }
.rk-note b { color: var(--text); }
.rk-key { padding: 16px; border-radius: 14px; box-shadow: var(--in); font-size: 15px; font-weight: 600; text-align: center; color: var(--primary); word-break: normal; line-height: 1.7; user-select: all; }
.rk-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 16px; }
.rk-actions .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.rk-check { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-size: 14px; color: var(--text); cursor: pointer; }
#rk-continue:disabled { opacity: .5; cursor: not-allowed; filter: none; }

/* ---------- ดึงลงเพื่อรีเฟรช (แอปบนหน้าจอโฮม) ---------- */
.ptr { position: fixed; z-index: 150; left: 50%; top: calc(env(safe-area-inset-top) - 44px); width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--bg); box-shadow: var(--out); opacity: 0; transform: translate(-50%, 0); pointer-events: none; }
.ptr.ready, .ptr.spin { color: var(--primary); }
.ptr.spin svg { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }
.standalone body { overscroll-behavior-y: none; }

/* ---------- มีอะไรใหม่ ---------- */
.btn-news { position: relative; color: var(--primary); }
.news-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--expense); box-shadow: 0 0 0 2px var(--bg); }
.news-dialog { width: min(520px, calc(100% - 32px)); }
.news-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.news-head h2 { margin: 0; }
.news-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.news-sub .app-version { color: var(--muted); }
.news-badge { width: 48px; height: 48px; flex: none; border-radius: 16px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--primary-2), var(--primary)); box-shadow: 4px 4px 12px rgba(124, 92, 255, .35); }
.news-list { display: grid; gap: 10px; max-height: min(60vh, 520px); overflow-y: auto; margin: 0 -6px 8px; padding: 6px; scrollbar-width: thin; }
.news-ver { border-radius: 16px; box-shadow: var(--out-sm); }
.news-ver[open] { box-shadow: var(--in); }
.news-ver summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 12px 14px; cursor: pointer; }
.news-ver summary::-webkit-details-marker { display: none; }
.news-v { font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.news-latest { padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; color: #fff; background: var(--primary); }
.news-title { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.news-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.news-chevron { display: inline-grid; color: var(--muted); transition: transform .2s; }
.news-ver[open] .news-chevron { transform: rotate(180deg); }
.news-ver ul { list-style: none; margin: 0; padding: 0 14px 12px; display: grid; gap: 8px; }
.news-ver li { display: flex; gap: 10px; font-size: 14px; line-height: 1.5; }
.news-ico { width: 24px; height: 24px; flex: none; border-radius: 8px; display: grid; place-items: center; box-shadow: var(--out-sm); }
.news-new .news-ico { color: var(--primary); }
.news-improve .news-ico { color: var(--loan); }
.news-fix .news-ico { color: var(--income); }
@media (max-width: 480px) { .news-date { display: none; } }

/* ---------- dialog / ฟอร์ม ---------- */
dialog { border: 0; border-radius: 24px; padding: 0; width: min(440px, calc(100% - 32px)); background: var(--bg); color: var(--text); box-shadow: var(--dialog-shadow); }
dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }
dialog form { padding: 28px; }
dialog h2 { margin: 0 0 20px; font-size: 19px; }
.type-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.type-toggle input { display: none; }
.type-toggle label { margin: 0; text-align: center; padding: 11px; border-radius: 14px; cursor: pointer; color: var(--muted); font-size: 15px; box-shadow: var(--out-sm); }
.type-toggle input:checked + label { box-shadow: var(--in); font-weight: 600; }
#t-income:checked + label { color: var(--income); }
#t-expense:checked + label { color: var(--expense); }
.type-caption { margin: 0 0 8px 4px; font-size: 12.5px; color: var(--muted); }
.type-toggle.loan { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-toggle.loan label { padding: 8px 2px; font-size: 13.5px; }
.type-toggle.loan input:checked + label { color: var(--loan); }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 11px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; }
.btn-del { color: var(--expense); margin-right: auto; }
.btn-del:hover { color: var(--expense); }
.btn-copy { display: inline-flex; align-items: center; gap: 6px; }
.btn-del + .btn-copy { margin-right: auto; }
.btn-del:has(+ .btn-copy:not([hidden])) { margin-right: 0; }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--toast-bg); color: var(--toast-fg); padding: 10px 20px; border-radius: 14px; transition: all .25s; pointer-events: none; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%); }
/* ---------- bubble loading ---------- */
.loader { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.loader-card { padding: 30px 40px 22px; border-radius: 26px; background: var(--bg); box-shadow: var(--out); text-align: center; animation: pop .2s ease-out; }
.bubbles { display: flex; gap: 14px; justify-content: center; align-items: flex-end; height: 48px; }
.bubbles span { width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .75), transparent 42%), linear-gradient(135deg, var(--primary-2), var(--primary)); box-shadow: 4px 4px 10px rgba(124, 92, 255, .35), -3px -3px 8px var(--light); animation: bubble 1.1s cubic-bezier(.45, 0, .55, 1) infinite; transform-origin: 50% 100%; }
.bubbles span:nth-child(2) { animation-delay: .15s; }
.bubbles span:nth-child(3) { animation-delay: .3s; }
@keyframes bubble {
  0%, 100% { transform: translateY(0) scale(1.15, .85); }
  15% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-26px) scale(.92, 1.08); }
  85% { transform: translateY(0) scale(1); }
}
.loader-text { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .bubbles span { animation-duration: 2.5s; } }
