/* ======================= Thành phần chuẩn iPhone (UIKit / SwiftUI), dùng cho MỌI trang và cả hai kiểu giao diện.
   Quy tắc: webapp chỉ dùng loại thành phần mà công cụ lập trình app iPhone có (xem docs/UI_STYLE_GUIDE.md §11). Nạp sau style.css / ios-app.css. */

/* UIAlertController (ios-ui.js) thay hộp thoại của trình duyệt */
.ios-alert-back{position:fixed;inset:0;z-index:1200;display:flex;align-items:center;justify-content:center;padding:24px;background:#0000005c;-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px);animation:ios-alert-dim .2s ease}
.ios-alert{width:100%;max-width:300px;max-height:85vh;display:flex;flex-direction:column;margin:0;border-radius:14px;overflow:hidden;background:#f7f7f7f7;color:#000;text-align:center;box-shadow:0 12px 40px #0004;animation:ios-alert-in .25s cubic-bezier(.32,.72,0,1);font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI Variable Text","Segoe UI",system-ui,Roboto,sans-serif}
.ios-alert-body{padding:19px 16px 16px;overflow:auto}
.ios-alert h3{margin:0;font-size:17px;font-weight:600;line-height:1.3;letter-spacing:-.01em;text-transform:none;color:inherit}
.ios-alert p{margin:4px 0 0;font-size:13px;line-height:1.4;white-space:pre-line;overflow-wrap:anywhere;color:inherit}
.ios-alert p:first-child{margin:0;font-size:15px}
.ios-alert .ios-alert-body input{display:block;width:100%;min-height:34px;margin:14px 0 0;padding:6px 10px;border:.5px solid #3c3c4349;border-radius:8px;background:#fff;color:#000;font:inherit;font-size:16px;outline:0}
.ios-alert-actions{display:flex;flex:none;border-top:.5px solid #3c3c4349}
.ios-alert .ios-alert-actions button{flex:1;width:auto;min-width:0;min-height:44px;margin:0;padding:0 8px;border:0;border-radius:0;outline:0;background:transparent;box-shadow:none;color:#007aff;font:inherit;font-size:17px;font-weight:400;cursor:pointer;transition:background-color .15s}
.ios-alert .ios-alert-actions button+button{border-left:.5px solid #3c3c4349}
.ios-alert .ios-alert-actions button.ios-default{font-weight:600}
.ios-alert .ios-alert-actions button.ios-destructive{color:#ff3b30;font-weight:600}
.ios-alert .ios-alert-actions button:active{background:#7878802e;transform:none;filter:none}
.ios-alert .ios-alert-actions button:focus-visible{background:#7878801f}
@keyframes ios-alert-dim{from{opacity:0}}
@keyframes ios-alert-in{from{opacity:0;transform:scale(1.12)}}
@media (prefers-color-scheme:dark){
  .ios-alert{background:#252527f7;color:#fff}
  .ios-alert .ios-alert-body input{background:#1c1c1e;color:#fff;border-color:#545458a6}
  .ios-alert-actions,.ios-alert .ios-alert-actions button+button{border-color:#545458a6}
  .ios-alert .ios-alert-actions button{color:#0a84ff}
  .ios-alert .ios-alert-actions button.ios-destructive{color:#ff453a}
}

/* UIMenu / pull-down button thay mũi tên select của trình duyệt (trên iPhone danh sách chọn là của iOS) */
select:not([multiple]):not([size]){-webkit-appearance:none;appearance:none;padding-right:34px!important;border-radius:10px;cursor:pointer;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 18' fill='none' stroke='%238e8e93' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.5 6 3l3.5 3.5M2.5 11.5 6 15l3.5-3.5'/%3E%3C/svg%3E")!important;
  background-repeat:no-repeat!important;background-position:right 11px center!important;background-size:12px 18px!important}

/* UIDatePicker kiểu "compact": viên xám bo góc */
input[type=date],input[type=time],input[type=datetime-local],input[type=month]{-webkit-appearance:none;appearance:none;min-height:36px;padding:6px 12px!important;border:0;border-radius:8px;background-color:var(--fill,#7878801f);color:var(--fg,inherit);font:inherit;font-size:17px;font-variant-numeric:tabular-nums;text-align:center}
input::-webkit-calendar-picker-indicator{opacity:.45;cursor:pointer}
input::-webkit-date-and-time-value{text-align:center;min-height:1.3em}

/* UITextField số: không có mũi tên tăng giảm của trình duyệt */
input[type=number]{-moz-appearance:textfield;appearance:textfield}
input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}
input[type=search]::-webkit-search-decoration{-webkit-appearance:none}

/* UISlider: giữ thanh trượt gốc (trên iPhone chính là UISlider), chỉ tô phần đã kéo bằng màu nhấn */
input[type=range]{accent-color:var(--acc,#007aff)}

/* UISwitch thay ô đánh dấu (trừ chỗ đã tự vẽ công tắc / nút ngày trong tuần) */
input[type=checkbox]:where(:not(.al-sw input):not(.gl-days input)){-webkit-appearance:none;appearance:none;width:51px;height:31px;flex:none;margin:0;border:0;border-radius:31px;background:#e9e9ea;position:relative;cursor:pointer;vertical-align:middle;transition:background-color .25s}
input[type=checkbox]:where(:not(.al-sw input):not(.gl-days input))::after{content:"";position:absolute;top:2px;left:2px;width:27px;height:27px;border-radius:50%;background:#fff;box-shadow:0 3px 8px #00000026,0 1px 1px #0000001a;transition:transform .3s cubic-bezier(.34,1.4,.5,1)}
input[type=checkbox]:checked:where(:not(.al-sw input):not(.gl-days input)){background:#34c759}
input[type=checkbox]:checked:where(:not(.al-sw input):not(.gl-days input))::after{transform:translateX(20px)}
input[type=checkbox]:disabled{opacity:.5}
@media (prefers-color-scheme:dark){input[type=checkbox]:not(:checked):where(:not(.al-sw input):not(.gl-days input)){background:#39393d}}

#rs-body label{color:var(--fg,inherit);font-size:17px;font-weight:400}
#rs-body label .muted{font-size:13px}

/* nút chọn tệp (nếu hiện ra) = nút tinted */
input[type=file]::file-selector-button{min-height:36px;margin-right:10px;padding:0 14px;border:0;border-radius:10px;background:var(--accbg,#007aff14);color:var(--acc,#007aff);font:inherit;font-weight:600;cursor:pointer}

/* ======================= Cài đặt: mỗi mục là một hàng thu gọn / mở rộng (DisclosureGroup) — settings-tabs.js ======================= */
.set-fold>h2:first-child{display:flex;align-items:center;gap:12px;margin:0;cursor:pointer;user-select:none;-webkit-user-select:none}
.set-fold>h2:first-child::after{content:"›";margin-left:auto;font-size:24px;font-weight:400;line-height:1;color:#c7c7cc;transition:transform .25s cubic-bezier(.32,.72,0,1)}
.set-fold.open>h2:first-child{margin-bottom:8px}
.set-fold.open>h2:first-child::after{transform:rotate(90deg)}
.set-fold:not(.open)>:not(h2:first-child){display:none!important}
.set-fold>h2:first-child:focus-visible{outline:2px solid var(--acc,#007aff);outline-offset:2px;border-radius:8px}
html body.ui-simple #tab-set .panel.set-fold{padding:2px 16px;margin-bottom:12px}
html body.ui-simple #tab-set .panel.set-fold.open{padding-bottom:12px}
html body.ui-simple #tab-set .panel.set-fold>h2:first-child{margin:0;gap:14px;min-height:48px;font-size:17px;font-weight:400;text-transform:none;letter-spacing:-.01em;color:var(--fg)}
html body.ui-simple #tab-set .panel.set-fold.open>h2:first-child{margin:0 0 4px;font-weight:600}
html body.ui-simple #tab-set details.sec-card{margin-bottom:12px;padding:2px 16px}
html body.ui-simple .set-fold>h2:first-child:active{opacity:.5}
/* ô biểu tượng màu đầu hàng, như app Cài đặt */
html body.ui-simple #tab-set .set-fold>h2:first-child::before{content:"";width:29px;height:29px;flex:none;border-radius:7px;background:#8e8e93 var(--set-ic,url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M5 7h14M5 12h14M5 17h9'/%3E%3C/svg%3E")) center/19px no-repeat}
#tab-set #support-link{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M4 5h16v11H10l-5 4v-4H4z'/%3E%3C/svg%3E")}
#tab-set #acct{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c1.5-4 4.5-5.5 8-5.5s6.5 1.5 8 5.5'/%3E%3C/svg%3E")}
#tab-set #alert-call-panel{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M6 3h4l1.5 5-2.5 1.5a12 12 0 0 0 5.5 5.5L16 12.5l5 1.5v4a2 2 0 0 1-2 2A16 16 0 0 1 4 5a2 2 0 0 1 2-2z'/%3E%3C/svg%3E")}
#tab-set #push-panel{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 16V11a6 6 0 0 1 12 0v5l2 2H4zM10 21h4'/%3E%3C/svg%3E")}
#tab-set #gw-set,#tab-set #gw-cfg,#tab-set #gw-code-link{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round'%3E%3Crect x='3' y='13' width='18' height='7' rx='2'/%3E%3Cpath d='M8 9a6 6 0 0 1 8 0M10.5 11.5a2.5 2.5 0 0 1 3 0M7 16.5h.01'/%3E%3C/svg%3E")}
#tab-set #color-panel{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='8'/%3E%3Cpath d='M12 4v16a8 8 0 0 0 0-16z' fill='white'/%3E%3C/svg%3E")}
#tab-set #ver-panel{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 12a8 8 0 1 1-2.3-5.6M20 4v4h-4'/%3E%3C/svg%3E")}
#tab-set #uimode-panel{--set-ic:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='7' y='3' width='10' height='18' rx='2.5'/%3E%3Cpath d='M11 18h2'/%3E%3C/svg%3E")}
html body.ui-simple #tab-set #color-panel>h2::before{background-color:#007aff}
html body.ui-simple #tab-set #uimode-panel>h2::before{background-color:#34c759}
html body.ui-simple #tab-set #support-link>h2::before{background-color:#34c759}
html body.ui-simple #tab-set #acct>h2::before{background-color:#007aff}
html body.ui-simple #tab-set #alert-call-panel>h2::before,html body.ui-simple #tab-set #push-panel>h2::before{background-color:#ff3b30}
html body.ui-simple #tab-set #gw-set>h2::before,html body.ui-simple #tab-set #gw-code-link>h2::before{background-color:#5856d6}
html body.ui-simple #tab-set #sub-panel>h2::before{background-color:#ff9500}

/* ======================= Chuyển động kiểu iPhone ======================= */
.ios-morphing{overflow:hidden!important}
html body .set-fold.ios-closing>h2:first-child::after{transform:none}
html body details.ios-closing>summary::after{transform:none}
/* UIAlertController đóng: mờ dần */
.ios-alert-back.out{pointer-events:none;opacity:0;transition:opacity .2s ease}
.ios-alert-back.out .ios-alert{transform:scale(.96);transition:transform .2s ease}
@media (prefers-reduced-motion:no-preference){
  /* công tắc: núm giãn khi đang giữ */
  input[type=checkbox]:where(:not(.al-sw input):not(.gl-days input)):active:not(:disabled)::after{width:33px}
  input[type=checkbox]:checked:where(:not(.al-sw input):not(.gl-days input)):active:not(:disabled)::after{transform:translateX(14px)}
  input[type=checkbox]:where(:not(.al-sw input):not(.gl-days input))::after{transition:transform .35s cubic-bezier(.34,1.4,.5,1),width .2s cubic-bezier(.32,.72,0,1)}
  /* hàng danh sách sáng xám khi nhấn rồi nhạt dần */
  html body.ui-simple #tab-set .set-fold>h2:first-child{border-radius:8px;transition:background-color .45s ease,opacity .45s ease}
  html body.ui-simple #tab-set .set-fold>h2:first-child:active{background:var(--fill);opacity:1;transition-duration:0s}
  /* bảng đóng: trượt xuống khỏi màn hình thay vì biến mất (trình duyệt cũ: đóng ngay như trước) */
  body.ui-simple .chat-view,body.ui-simple .mq,body.ui-simple .qs{transition:translate .36s cubic-bezier(.32,.72,0,1),display .36s allow-discrete}
  body.ui-simple .chat-view[hidden],body.ui-simple .mq[hidden],body.ui-simple .qs[hidden]{translate:0 100%;pointer-events:none}
  body.ui-simple .ctl-modal,body.ui-simple .qr-res{transition:opacity .26s ease,display .26s allow-discrete}
  body.ui-simple .ctl-modal[hidden],body.ui-simple .qr-res[hidden]{opacity:0;pointer-events:none}
  /* trang đăng nhập: đổi khung trượt ngang, ô vừa mở hiện dần */
  body.ui-simple #pane-register:not([hidden]),body.ui-simple #step-recover:not([hidden]){animation:ios-slide-r .36s cubic-bezier(.32,.72,0,1)}
  body.ui-simple #pane-login:not([hidden]),body.ui-simple #step-creds:not([hidden]){animation:ios-slide-l .36s cubic-bezier(.32,.72,0,1)}
  body.ui-simple #step-creds:not(.pw-closed)>label{animation:ios-drop .36s cubic-bezier(.32,.72,0,1)}
}
@keyframes ios-slide-r{from{opacity:0;transform:translateX(28px)}}
@keyframes ios-slide-l{from{opacity:0;transform:translateX(-28px)}}
@keyframes ios-drop{from{opacity:0;transform:translateY(-8px)}}
/* chuyển trang (cross-document view transition): đẩy / quay lại như thanh điều hướng iPhone */
@media (prefers-reduced-motion:no-preference){
  @view-transition{navigation:auto}
  ::view-transition-old(root),::view-transition-new(root){animation-duration:.38s;animation-timing-function:cubic-bezier(.32,.72,0,1);animation-fill-mode:both;mix-blend-mode:normal}
  ::view-transition-old(root){animation-name:ios-nav-under}
  ::view-transition-new(root){animation-name:ios-nav-push;box-shadow:-8px 0 24px #0002}
  html[data-nav=back]::view-transition-old(root){animation-name:ios-nav-pop;z-index:2}
  html[data-nav=back]::view-transition-new(root){animation-name:ios-nav-return;box-shadow:none}
}
@keyframes ios-nav-push{from{transform:translateX(100%)}}
@keyframes ios-nav-under{to{transform:translateX(-28%);filter:brightness(.92)}}
@keyframes ios-nav-pop{to{transform:translateX(100%)}}
@keyframes ios-nav-return{from{transform:translateX(-28%);filter:brightness(.92)}}

/* mục mở rộng nhỏ ("Có mã mời nhà máy?", ghi chú chat): mũi tên › bên phải thay tam giác của trình duyệt */
.more-device>summary,.sup-note>summary{list-style:none;display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:44px;cursor:pointer}
.more-device>summary::-webkit-details-marker,.sup-note>summary::-webkit-details-marker{display:none}
.more-device>summary::after,.sup-note>summary::after{content:"›";font-size:22px;line-height:1;color:#8e8e93;transition:transform .25s cubic-bezier(.32,.72,0,1)}
.more-device[open]:not(.ios-closing)>summary::after,.sup-note[open]:not(.ios-closing)>summary::after{transform:rotate(90deg)}
/* thanh chọn phân đoạn: mục chưa chọn dùng màu chữ thường như UISegmentedControl */
html body.ui-simple .auth-tabs button:not(.on){color:var(--fg)!important}

/* ======================= Màn đợi khi mở app (index.html #splash) ======================= */
#splash{position:fixed;inset:0;z-index:1100;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;padding:24px;background:#fff;color:#000;text-align:center;font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI Variable Text","Segoe UI",system-ui,Roboto,sans-serif;transition:opacity .35s ease,transform .35s cubic-bezier(.32,.72,0,1)}
#splash img{border-radius:18px;box-shadow:0 8px 24px #0002}
#splash b{font-size:22px;font-weight:700;letter-spacing:-.02em}
#splash span{font-size:15px;color:#8e8e93}
#splash a{margin-top:6px;font-size:15px;color:#007aff;text-decoration:none;opacity:0;visibility:hidden;animation:splash-late .4s ease 6s forwards}
#splash.out{opacity:0;transform:scale(1.04);pointer-events:none}
@keyframes splash-late{to{opacity:1;visibility:visible}}
/* UIActivityIndicatorView: 8 vạch mờ dần quay tròn */
.ios-spin{width:28px;height:28px;margin-top:10px;border-radius:50%;
  background:conic-gradient(#8e8e9326,#8e8e93);
  -webkit-mask:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M12 2.5v5M12 16.5v5M2.5 12h5M16.5 12h5M5.3 5.3l3.5 3.5M15.2 15.2l3.5 3.5M5.3 18.7l3.5-3.5M15.2 8.8l3.5-3.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' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M12 2.5v5M12 16.5v5M2.5 12h5M16.5 12h5M5.3 5.3l3.5 3.5M15.2 15.2l3.5 3.5M5.3 18.7l3.5-3.5M15.2 8.8l3.5-3.5'/%3E%3C/svg%3E") center/contain no-repeat;
  animation:ios-spin .8s steps(8) infinite}
@keyframes ios-spin{to{transform:rotate(360deg)}}
@media (prefers-color-scheme:dark){#splash{background:#000;color:#fff}#splash a{color:#0a84ff}}
