/* YNLINIX Responsive UI System
 * Device-agnostic: adapts to viewport, input type, orientation and accessibility preferences.
 * No device-model-specific rules.
 */
:root {
  --ui-max: 1200px;
  --ui-gutter: clamp(12px, 3vw, 28px);
  --ui-radius: clamp(14px, 1.8vw, 20px);
  --ui-control: 44px;
  --ui-safe-top: env(safe-area-inset-top, 0px);
  --ui-safe-right: env(safe-area-inset-right, 0px);
  --ui-safe-bottom: env(safe-area-inset-bottom, 0px);
  --ui-safe-left: env(safe-area-inset-left, 0px);
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100svh;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

img, video, canvas, iframe {
  max-width: 100%;
}

button, a, input, select, textarea {
  -webkit-tap-highlight-color: transparent;
}

button, [role="button"], a.btn, label.btn {
  touch-action: manipulation;
}

/* ---------- Global shell ---------- */
/* Sidebar layout lives in style.css — only soft overrides here */
.topnav {
  padding-top: max(12px, var(--ui-safe-top));
}
.topnav .links {
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  flex-wrap: nowrap;
  scrollbar-width: thin;
}
.topnav .links a { white-space: nowrap; min-height: 44px; }
.topnav .user-chip, .topnav .btn-logout { min-height: 40px; white-space: nowrap; }

.shell {
  width: min(100%, var(--ui-max));
  padding-left: max(var(--ui-gutter), var(--ui-safe-left));
  padding-right: max(var(--ui-gutter), var(--ui-safe-right));
  padding-bottom: max(48px, calc(48px + var(--ui-safe-bottom)));
}

.card, .stat-card, .login-card, .modal, .pub-card {
  overflow-wrap: anywhere;
}

/* Keep controls comfortable for touch without making desktop UI oversized. */
.btn, .btn-google, .icon-btn, .cal-btn,
.login-tabs button, .topnav .links a {
  min-height: 40px;
}

.form-control {
  min-height: 44px;
}

/* ---------- Responsive grids ---------- */
.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr));
}

.form-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scan-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr);
}

/* ---------- Modals become bottom sheets on compact touch viewports ---------- */
.modal-overlay {
  padding: max(12px, var(--ui-safe-top)) max(12px, var(--ui-safe-right)) max(12px, var(--ui-safe-bottom)) max(12px, var(--ui-safe-left));
  overscroll-behavior: contain;
}

.modal {
  max-height: min(90svh, 760px);
  overscroll-behavior: contain;
}

/* ---------- Calendar ---------- */
.cal-card, .cal-shell {
  min-width: 0;
}
.cal-grid {
  min-width: 0;
}

/* ---------- Tables ---------- */
.table-wrap {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

/* ---------- Public profile ---------- */
.pub-wrap {
  min-height: 100svh !important;
  padding: max(16px, var(--ui-safe-top)) max(16px, var(--ui-safe-right)) max(16px, var(--ui-safe-bottom)) max(16px, var(--ui-safe-left)) !important;
}
.pub-card {
  width: min(100%, 560px) !important;
}

/* ---------- Chat: responsive architecture ---------- */
body.chat-page {
  min-height: 100svh;
}
body.chat-page .shell {
  width: min(100%, 1240px);
}

body.chat-page .wa {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: min(calc(100svh - 110px), 900px);
  max-height: none;
}

body.chat-page .sidebar,
body.chat-page .panel,
body.chat-page #panelChat,
body.chat-page .side-list,
body.chat-page .msgs {
  min-width: 0;
  min-height: 0;
}

body.chat-page .room-item,
body.chat-page .panel-head,
body.chat-page .side-head {
  padding-left: clamp(10px, 1.5vw, 16px);
  padding-right: clamp(10px, 1.5vw, 16px);
}

body.chat-page .msgs {
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
}

body.chat-page .compose {
  padding-bottom: max(8px, var(--ui-safe-bottom));
}

/* ---------- Tablet / compact desktop ---------- */
@media (max-width: 1024px) {
  .topnav .links { margin-left: 0; }
  .topnav .brand span { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  body.chat-page .wa {
    grid-template-columns: minmax(280px, 34%) minmax(0, 1fr);
  }

  body.chat-page .msg {
    max-width: min(90%, 620px);
  }
}

/* ---------- Touch/tablet ---------- */
@media (max-width: 800px) {
  .topnav {
    gap: 8px;
  }
  .topnav .links {
    order: initial;
    width: auto;
    flex: 1 1 100%;
  }
  .topnav .spacer { display: none; }

  .shell {
    padding-top: 20px;
  }

  .page-head h1 {
    font-size: clamp(28px, 8vw, 38px);
  }

  .form-row, .scan-grid {
    grid-template-columns: 1fr;
  }

  .modal-overlay {
    align-items: flex-end;
  }
  .modal {
    max-width: 680px;
    border-radius: 20px 20px 14px 14px;
    width: 100%;
    max-height: min(88svh, 760px);
    padding: clamp(18px, 4vw, 24px);
    animation: ui-sheet-in .22s cubic-bezier(.2,.8,.2,1) both;
  }
  .modal-actions {
    flex-wrap: wrap;
  }
  .modal-actions .btn {
    flex: 1 1 120px;
  }

  body.chat-page .page-head {
    display: none !important;
  }
  /* Sidebar tetap drawer di mobile chat; tidak force-hide */
  body.chat-page .shell {
    padding: 0 !important;
    width: 100%;
    max-width: none;
  }
  body.chat-page .wa {
    grid-template-columns: 1fr;
    height: 100svh;
    min-height: 100svh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.chat-page .wa:not(.show-chat) .panel { display: none; }
  body.chat-page .wa.show-chat .sidebar { display: none; }
  body.chat-page .wa.show-chat .panel { display: flex; }
  body.chat-page .side-head { padding-top: max(12px, var(--ui-safe-top)); }
  body.chat-page .panel-head { padding-top: max(8px, var(--ui-safe-top)); }
  body.chat-page .msgs { padding-left: 8px; padding-right: 8px; }
  body.chat-page .msg { max-width: min(94%, 680px); }
}

/* ---------- Small phones ---------- */
@media (max-width: 480px) {
  .topnav {
    padding-top: max(8px, var(--ui-safe-top));
    padding-bottom: 8px;
  }
  .topnav .brand { min-width: 0; }
  .topnav .brand-mark { width: 34px; height: 34px; }
  .topnav .user-chip { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
  .topnav .btn-logout { padding-inline: 10px; }

  .shell { padding-top: 16px; }
  .card, .stat-card { border-radius: 16px; box-shadow: 3px 3px 0 var(--ink); }
  .card { padding: 16px; }
  .card-header { align-items: flex-start; }
  .card-header .btn { width: 100%; }

  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: clamp(24px, 8vw, 30px); }

  .login-wrap { padding: max(14px, var(--ui-safe-top)) 12px max(14px, var(--ui-safe-bottom)); }
  .login-card {
    padding: 22px 16px;
    border-radius: 20px;
    box-shadow: 4px 4px 0 var(--ink);
  }
  .login-card h1 { font-size: 25px; }
  .login-tabs button { min-height: 44px; }

  .modal-actions { gap: 8px; }
  .modal-actions .btn { min-height: 44px; }

  body.chat-page .side-actions { display: grid; grid-template-columns: 1fr 1fr; }
  body.chat-page .side-actions .btn { width: 100%; }
  body.chat-page .room-item { min-height: 72px; }
  body.chat-page .room-item .av { width: 48px; height: 48px; }
  body.chat-page .room-item .s { max-width: calc(100vw - 120px); }
  body.chat-page .panel-head .av { width: 40px; height: 40px; }
  body.chat-page .head-actions { gap: 0; }
  body.chat-page .icon-btn { width: 42px; height: 42px; }
  body.chat-page .msgs { padding-bottom: 4px; }
}

/* ---------- Very short landscape phones ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .topnav { min-height: 48px; padding-block: 5px; }
  .shell { padding-top: 10px; padding-bottom: 24px; }
  .page-head { margin-bottom: 12px; }
  .modal { max-height: 94svh; }
  body.chat-page .wa { height: 100svh; }
  body.chat-page .side-head { padding-top: 6px; padding-bottom: 6px; }
  body.chat-page .room-item { padding-block: 7px; }
  body.chat-page .room-item .av { width: 42px; height: 42px; }
}

/* ---------- Pointer-aware interaction ---------- */
@media (hover: hover) and (pointer: fine) {
  .btn:hover,
  .btn-google:hover,
  .topnav .btn-logout:hover,
  .login-tabs button:hover,
  .soc:hover {
    transform: translateY(-1px);
  }
}

@media (hover: none) and (pointer: coarse) {
  .btn:hover,
  .btn-google:hover,
  .topnav .btn-logout:hover,
  .login-tabs button:hover,
  .soc:hover,
  .stat-card:hover::after {
    transform: none !important;
  }
  .btn:active, .icon-btn:active, .topnav .links a:active {
    transform: scale(.98);
  }
}

/* ---------- Motion budget ----------
   Animate compositor-friendly properties only: transform/opacity.
*/
@keyframes ui-sheet-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* Respect low-data preference where supported: remove decorative effects. */
@media (prefers-reduced-data: reduce) {
  body {
    background-image: none !important;
  }
  .topnav, .modal, .login-card {
    backdrop-filter: none !important;
  }
}

/* Keyboard focus remains visible for keyboard, switch and accessibility users. */
:where(button, a, input, select, textarea):focus-visible {
  outline: 3px solid rgba(239, 106, 24, .55);
  outline-offset: 2px;
}


/* Compact/touch performance guardrails for decorative motion and glass effects. */
@media (hover: none) and (pointer: coarse) {
  .login-wrap::before, .login-wrap::after { animation: none !important; }
  .topnav { backdrop-filter: blur(8px) saturate(130%); }
  body.chat-page .side-head,
  body.chat-page .chat-head,
  body.chat-page .panel-head,
  body.chat-page .reaction-popover,
  body.chat-page .message-sheet { backdrop-filter: blur(8px) saturate(125%); }
}

@media (prefers-reduced-data: reduce), (max-width: 480px) {
  body.chat-page .side-head,
  body.chat-page .chat-head,
  body.chat-page .panel-head,
  body.chat-page .reaction-popover,
  body.chat-page .message-sheet { backdrop-filter: none !important; }
}

.chat-avatar-image { width:100%; height:100%; object-fit:cover; border-radius:inherit; display:block; }

/* v4.1 visual refinement — fluid, touch-first, no device-specific sizing */
body.chat-page{background:#f5f6f6}
body.chat-page .wa{border:1px solid #d9dfe2;border-radius:18px;box-shadow:0 12px 40px rgba(16,24,40,.10);overflow:hidden}
body.chat-page .sidebar{background:#fff}
body.chat-page .side-head{padding:18px 18px 12px;background:#fff;border-bottom:0;grid-template-columns:1fr auto;align-items:center}
body.chat-page .side-head h2{font-size:24px;line-height:1.1}
body.chat-page .side-actions{justify-content:flex-end;gap:6px}
body.chat-page .side-actions .btn{min-width:38px;height:38px;padding:0 13px}
body.chat-page .chat-toolbar-search{padding:7px 12px 12px;background:#fff;border-bottom:1px solid #eef0f2}
body.chat-page .chat-toolbar-search input{height:40px;padding:0 14px;background:#f1f3f5;font-size:14px}
body.chat-page .room-item{padding:11px 16px;border-bottom:1px solid #f1f2f3;transition:background .14s ease,transform .14s ease}
body.chat-page .room-item:active{transform:scale(.995)}
body.chat-page .room-item.on{background:#f1f3f4}
body.chat-page .room-item .av{width:52px;height:52px}
body.chat-page .room-item .t{font-size:15px;font-weight:750}
body.chat-page .room-item .s{font-size:13px}
body.chat-page .draft-line{color:#e53935!important}
body.chat-page .draft-line strong{font-weight:750}
body.chat-page .panel{background:#efeae2}
body.chat-page .panel-head{background:rgba(240,242,245,.96);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}
body.chat-page .compose{background:rgba(240,242,245,.96);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px)}
body.chat-page .compose-row textarea{border:1px solid #e0e4e7!important;background:#fff!important}
body.chat-page .msg .bubble{border-radius:12px;box-shadow:0 1px 1px rgba(11,20,26,.10)}
body.chat-page .msg.mine .bubble{border-top-right-radius:3px}
body.chat-page .msg:not(.mine) .bubble{border-top-left-radius:3px}

.mobile-chat-home-head,.mobile-chat-nav{display:none}

@media(max-width:800px){
  body.chat-page{background:#fff}
  body.chat-page .wa{height:100svh;height:100dvh;border:0;border-radius:0;box-shadow:none;position:relative;padding-bottom:calc(64px + env(safe-area-inset-bottom,0px))}
  body.chat-page .mobile-chat-home-head{display:flex;align-items:center;justify-content:space-between;padding:max(14px,env(safe-area-inset-top,0px)) 16px 10px;background:#fff;min-height:68px;z-index:10}
  body.chat-page .mobile-chat-title{font-size:30px;line-height:1;font-weight:800;letter-spacing:-.045em;color:#111b21}
  body.chat-page .mobile-chat-actions{display:flex;align-items:center;gap:10px}
  body.chat-page .mobile-circle-btn{width:38px;height:38px;border:0;border-radius:50%;display:grid;place-items:center;background:#f1f3f4;color:#111b21}
  body.chat-page .mobile-circle-btn.primary{background:#25d366;color:#fff}
  body.chat-page .mobile-circle-btn .svg-icon,body.chat-page .mobile-circle-btn svg{width:21px;height:21px}
  body.chat-page .sidebar{height:calc(100% - 0px);border-right:0}
  body.chat-page .side-head{display:none}
  body.chat-page .chat-toolbar-search{padding:5px 12px 10px;border-bottom:0}
  body.chat-page .chat-toolbar-search input{height:38px}
  body.chat-page .room-item{padding:10px 16px;min-height:72px}
  body.chat-page .room-item .av{width:52px;height:52px}
  body.chat-page .side-list{padding-bottom:8px}
  body.chat-page .mobile-chat-nav{position:absolute;display:grid;grid-template-columns:repeat(3,1fr);left:0;right:0;bottom:0;height:calc(64px + env(safe-area-inset-bottom,0px));padding-bottom:env(safe-area-inset-bottom,0px);background:rgba(255,255,255,.96);backdrop-filter:blur(18px);-webkit-backdrop-filter:blur(18px);border-top:1px solid #e7eaec;z-index:50}
  body.chat-page .mobile-chat-nav button{border:0;background:transparent;color:#667781;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;font:inherit;min-width:0}
  body.chat-page .mobile-chat-nav button.active{color:#111b21}
  body.chat-page .mobile-chat-nav .svg-icon,body.chat-page .mobile-chat-nav svg{width:23px;height:23px}
  body.chat-page .mobile-chat-nav small{font-size:11px;font-weight:650}
  body.chat-page .wa.show-chat{padding-bottom:0}
  body.chat-page .wa.show-chat .mobile-chat-home-head,body.chat-page .wa.show-chat .mobile-chat-nav{display:none}
  body.chat-page .wa.show-chat .panel{height:100%;min-height:0}
  body.chat-page .wa.show-chat .panel-head{padding-top:max(7px,env(safe-area-inset-top,0px));min-height:62px}

  /* compact iOS-like reaction surface */
  body.chat-page .reaction-popover{left:auto!important;right:auto!important;width:auto;max-width:calc(100vw - 32px);padding:5px 7px;gap:1px;border-radius:999px;background:rgba(38,38,38,.96);border:1px solid rgba(255,255,255,.08);box-shadow:0 12px 36px rgba(0,0,0,.28);backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px)}
  body.chat-page .reaction-popover button{width:38px;height:38px;font-size:22px;color:#fff}
  body.chat-page .reaction-popover .add-reaction{color:#e8edf0}
  body.chat-page .message-sheet{width:min(430px,calc(100vw - 44px));max-width:min(430px,calc(100vw - 44px));padding:7px!important;border-radius:18px!important;margin:0 auto 12px;box-shadow:0 20px 55px rgba(0,0,0,.28)}
  body.chat-page .message-sheet .sheet-preview{padding:11px 13px;border-radius:13px;margin-bottom:4px}
  body.chat-page .message-sheet .sheet-action{min-height:50px;padding:10px 13px;font-size:15px;border-radius:11px}
  body.chat-page .message-sheet .sheet-action .svg-icon,body.chat-page .message-sheet .sheet-action .svg-icon svg{width:20px;height:20px}
  body.chat-page .msg.selected .bubble{outline:2px solid rgba(18,140,126,.35);outline-offset:2px}
}

@media(min-width:801px){
  body.chat-page .mobile-chat-home-head,body.chat-page .mobile-chat-nav{display:none!important}
}

@media(prefers-reduced-motion:reduce){
  body.chat-page .room-item,body.chat-page .mobile-chat-nav button,body.chat-page .mobile-circle-btn{transition:none!important}
}

/* ── Profile mobile polish ── */
@media (max-width: 768px) {
  .profile-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }
  #bannerBox {
    height: 120px !important;
    border-radius: 12px !important;
  }
  .avatar-row {
    flex-wrap: wrap;
    gap: 12px !important;
  }
  .avatar, .avatar-fallback {
    width: 72px !important;
    height: 72px !important;
  }
  .profile-qr img {
    max-width: min(220px, 70vw) !important;
  }
  .id-box {
    font-size: 20px !important;
    letter-spacing: 0.12em !important;
  }
  .shell {
    padding: 12px !important;
  }
  .page-head h1 {
    font-size: 22px !important;
  }
  .topnav {
    padding: 10px 12px !important;
    gap: 8px !important;
  }
  .topnav .brand {
    font-size: 14px !important;
  }
  .topnav .links a {
    padding: 8px !important;
  }
  .topnav .user-chip {
    display: none !important;
  }
}

/* Chat mobile clarity */
@media (max-width: 768px) {
  body.chat-page .wa {
    height: 100dvh !important;
    min-height: 100dvh !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  body.chat-page .shell {
    padding: 0 !important;
    max-width: none !important;
  }
  body.chat-page .page-head {
    display: none !important;
  }
  .compose-row {
    padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
  }
}
