/* Mobile workspace — lấy nhịp bố cục từ chatnoibo, giữ nguyên ngôn ngữ An Sinh. */
@media (max-width: 900px) {
  :root { --mobile-bar: 64px; }

  html, body { width: 100%; height: 100%; min-height: 100%; overscroll-behavior: none; }
  body { overflow: hidden; -webkit-text-size-adjust: 100%; }
  .app { width: 100%; height: 100dvh; min-height: 0; overflow: hidden; }
  main { min-width: 0; min-height: 0; height: 100dvh; background: var(--bg); }
  .scrollarea { min-height: 0; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; }

  .topbar {
    height: calc(54px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 12px 0;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    position: relative; z-index: 20;
  }
  .topbar h2 { max-width: 54vw; font-size: 15px; letter-spacing: -.01em; }
  .menubtn, .topbar .btn { min-width: 40px; min-height: 40px; }

  .roomstrip {
    min-height: 46px; padding: 7px 12px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
  }
  .roomstrip button { min-height: 32px; padding: 6px 11px; font-size: 11.5px; }

  #tabbar {
    min-height: calc(var(--mobile-bar) + env(safe-area-inset-bottom));
    padding: 5px 7px calc(5px + env(safe-area-inset-bottom)); gap: 3px;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
    box-shadow: 0 -8px 30px rgba(0,0,0,.08); z-index: 30;
  }
  #tabbar button { min-height: 52px; padding: 6px 3px 4px; border-radius: 14px; font-size: 10.5px; }
  #tabbar button .ic { font-size: 20px; }
  #tabbar button.on { background: color-mix(in srgb, var(--accent) 14%, transparent); }
  #tabbar button.on::before {
    content: ""; position: absolute; top: 2px; width: 22px; height: 3px;
    border-radius: 99px; background: var(--accent); box-shadow: var(--glow);
  }

  .wrap { padding: 13px 12px 24px; }
  .card { padding: 14px; margin-bottom: 11px; border-radius: 16px; box-shadow: none; }
  .card > header { margin-bottom: 11px; }
  .card > header h3 { font-size: 14px; }
  .card > header p { font-size: 11.8px; line-height: 1.5; }
  .tiles { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin-bottom: 11px; }
  .tile { min-width: 0; padding: 12px; border-radius: 14px; box-shadow: none; }
  .tile .lab { font-size: 10.5px; }
  .tile .val { margin: 4px 0 1px; font-size: 22px; }
  .tile .hint { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .agrid { grid-template-columns: 1fr; gap: 9px; }
  .acard { padding: 13px; border-radius: 15px; box-shadow: none; }
  .acard .hd { margin-bottom: 10px; }
  .acard .kpis { padding-top: 10px; gap: 6px; }

  .subtabs {
    gap: 6px; overflow-x: auto; padding: 7px 11px; border-bottom: 1px solid var(--border);
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
  }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtabs button {
    min-height: 34px; margin: 0; padding: 7px 11px; border: 1px solid var(--border-2);
    border-radius: 999px; background: var(--surface-2); font-size: 11.5px;
  }
  .subtabs button[aria-selected="true"] {
    color: var(--accent); border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  }

  .btn { min-height: 38px; padding: 8px 12px; }
  input[type=text], input[type=search], select, textarea { font-size: 16px; }
  input[type=text], input[type=search] { min-width: 0; min-height: 42px; padding: 9px 13px; }
  .search, .ktn-toolbar, .lead-desk-bar { gap: 7px; }
  .search > *, .ktn-toolbar > * { min-width: 100% !important; flex: 1 1 100%; }

  .note { padding: 11px; border-radius: 13px; }
  .note .c { font-size: 12.5px; }
  .appr { padding: 13px; border-radius: 14px; }

  .chat-scroll { padding: 13px 12px 6px; }
  .chat-inner { width: 100%; }
  .msg { gap: 8px; padding: 5px 0; }
  .msg .av { width: 30px; height: 30px; }
  .msg .hd .who { font-size: 12px; }
  .msg .hd .tm { font-size: 10px; }
  .msg .txt { font-size: 14px; line-height: 1.55; }
  .msg .acts { opacity: 1; }
  .composer {
    padding: 7px 9px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  }
  .cbox { border-radius: 17px; }
  .cbox textarea { min-height: 40px; max-height: 104px; padding: 10px 11px 3px; font-size: 16px; line-height: 1.4; }
  .cbar { gap: 5px; padding: 5px 6px 6px 8px; flex-wrap: nowrap; overflow-x: auto; }
  .chip { flex: none; min-height: 30px; padding: 5px 9px; font-size: 10.5px; }
  .msg-img { max-width: min(100%, 300px); height: auto; }

  /* Bảng dài chuyển thành các phiếu dữ liệu đọc được bằng một tay. */
  .tbl-wrap, .scroll, .lead-data-wrap { overflow: visible; margin: 0; padding: 0; max-height: none; }
  table[data-mobile-cards="true"] { min-width: 0 !important; border: 0; display: block; }
  table[data-mobile-cards="true"] thead { display: none; }
  table[data-mobile-cards="true"] tbody { display: grid; gap: 9px; }
  table[data-mobile-cards="true"] tr {
    display: block; padding: 5px 12px; border: 1px solid var(--border);
    border-radius: 14px; background: var(--surface); box-shadow: 0 3px 14px rgba(0,0,0,.04);
  }
  table[data-mobile-cards="true"] td {
    display: grid; grid-template-columns: minmax(92px, 34%) minmax(0,1fr); gap: 10px;
    min-width: 0 !important; max-width: none !important; padding: 8px 0 !important;
    border-bottom: 1px solid var(--border) !important; text-align: left !important;
    white-space: normal; overflow-wrap: anywhere; font-size: 12px !important;
    background: transparent !important;
  }
  table[data-mobile-cards="true"] td:last-child { border-bottom: 0 !important; }
  table[data-mobile-cards="true"] td::before {
    content: attr(data-label); color: var(--ink-3); font-size: 9.5px; font-weight: 700;
    line-height: 1.35; letter-spacing: .045em; text-transform: uppercase;
  }
  table[data-mobile-cards="true"] td:empty { display: none; }
  table[data-mobile-cards="true"] td[data-label=""] { grid-template-columns: 1fr; }
  table[data-mobile-cards="true"] td[data-label=""]::before { display: none; }
  .lead-data-table .lead-actions { min-width: 0; flex-direction: row; flex-wrap: wrap; }
  .lead-data-table .lead-progress, .lead-data-table .lead-message, .lead-data-table .lead-source { min-width: 0; max-width: none; }
  .lead-desk { border: 0; margin: 0 -2px; }
  .lead-desk-head { padding: 14px 12px; }
  .lead-desk-title h3 { font-size: 14px; }
  .lead-desk-title p, .lead-desk-rule { font-size: 11px; }
  .lead-kpis { grid-template-columns: repeat(2,1fr); }
  .lead-kpi { padding: 11px 12px; }
  .lead-kpi b { font-size: 18px; }
  .lead-desk-bar { padding: 10px; }
  .lead-desk-bar select { width: 100%; min-height: 40px; }
  .lead-board { grid-template-columns: repeat(4, min(82vw, 292px)); padding: 11px 0 12px; scroll-snap-type: x proximity; }
  .lead-lane { min-width: 0; scroll-snap-align: start; }

  #v-sodo .wrap { padding: 11px 10px 20px; }
  #v-sodo #sodoTiles { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 7px; }
  #v-sodo #sodoTiles .tile { padding: 9px 10px; }
  #v-sodo .card { padding: 10px; overflow: hidden; }
  #flowBox, #archBox { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #flowBox svg, #archBox svg { min-width: 760px; }

  /* Leader nổi: trên mobile là một màn chat đúng nghĩa, không còn cửa sổ lơ lửng. */
  #v-bot.leader-dock { right: 12px; bottom: calc(var(--mobile-bar) + 12px + env(safe-area-inset-bottom)); z-index: 140; }
  .leader-launcher { width: 52px; height: 52px; padding: 5px; border-radius: 18px; }
  .leader-launcher-orb { width: 40px; height: 40px; border-radius: 13px; }
  #v-bot .leader-shell, #v-bot.chat-max .leader-shell {
    position: fixed; inset: 0; width: 100%; height: 100dvh; max-height: none;
    border: 0; border-radius: 0; transform: translateY(16px); background: var(--bg);
  }
  #v-bot.chat-open .leader-shell { transform: none; }
  #v-bot .leader-head {
    min-height: calc(58px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 10px 0;
    flex: 0 0 auto; background: color-mix(in srgb, var(--panel) 93%, transparent);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  }
  #v-bot .leader-head h3 { font-size: 14px; }
  #v-bot .leader-head p { max-width: 47vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #v-bot .leader-head .badge, #leaderMax { display: none; }
  #v-bot .leader-scope {
    flex: 0 0 auto; margin: 6px 10px 0; padding: 6px 9px; overflow: hidden;
    white-space: nowrap; text-overflow: ellipsis; font-size: 10px;
  }
  #v-bot .leader-quick-inline { flex: 0 0 auto; padding: 7px 10px 3px; }
  #v-bot .leader-quick-inline button { min-height: 31px; padding: 5px 10px; font-size: 10px; }
  #v-bot .leader-feed {
    flex: 1 1 auto; min-height: 0; padding: 10px 11px 8px; overflow-y: auto;
    overscroll-behavior-y: contain; background: var(--bg);
  }
  #v-bot .leader-msg { max-width: 86%; margin: 5px 0; padding: 9px 11px; border-radius: 16px; font-size: 14px; line-height: 1.5; }
  #v-bot .leader-msg.agent { border-bottom-left-radius: 5px; }
  #v-bot .leader-msg.human { border-bottom-right-radius: 5px; }
  #v-bot .leader-msg .meta { font-size: 9.5px; }
  #v-bot .leader-compose {
    flex: 0 0 auto; padding: 7px 9px calc(8px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--panel) 95%, transparent);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  }
  #v-bot .leader-modes { margin-bottom: 6px; overflow-x: auto; scrollbar-width: none; }
  #v-bot .leader-modes button { flex: none; min-height: 31px; padding: 5px 10px; font-size: 10.5px; }
  #v-bot .leader-compose textarea {
    min-height: 44px; max-height: 96px; padding: 10px 11px; border: 1px solid var(--border-2);
    border-radius: 16px; background: var(--surface-2); font-size: 16px; line-height: 1.4;
  }
  #v-bot .leader-actions { margin-top: 6px; }
  #v-bot .leader-actions select { min-height: 36px; max-width: 130px; border-radius: 10px; font-size: 12px; }
  #v-bot #leaderSend { min-height: 38px; min-width: 62px; border-radius: 12px; }
  body.leader-chat-open { overflow: hidden; }
  body.leader-chat-open #tabbar { visibility: hidden; }
}

@media (max-width: 420px) {
  .tiles { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .tile .val { font-size: 20px; }
  #tabbar button .nh { font-size: 9.8px; }
  #v-bot .leader-avatar { width: 38px; height: 38px; }
  table[data-mobile-cards="true"] td { grid-template-columns: minmax(84px, 32%) minmax(0,1fr); }
}

@media (max-height: 520px) and (max-width: 920px) and (orientation: landscape) {
  :root { --mobile-bar: 54px; }
  .topbar { height: calc(48px + env(safe-area-inset-top)); }
  .roomstrip { display: none; }
  #tabbar button { min-height: 43px; }
  #v-bot .leader-scope, #v-bot .leader-quick-inline { display: none; }
  #v-bot .leader-head { min-height: calc(50px + env(safe-area-inset-top)); }
  #v-bot .leader-compose textarea { max-height: 58px; }
}

@media (hover: none) and (pointer: coarse) {
  button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
  button:active, .acard:active { transform: scale(.98); }
}
