/* Phone / app layout (Android app + "Install app" from Chrome).
   Loaded last; only applies on narrow screens. */

@media (max-width: 780px) {
  /* No sideways scrolling. Only <html> may be "hidden": hidden on <body> too turns the body into its own
     scroll box, and then the sticky header and Market Watch bar scroll away with the page. */
  html { overflow-x: hidden; }
  body { overflow-x: clip; }
  body { -webkit-tap-highlight-color: transparent; }

  /* ---------- compact header ---------- */
  .terminal-header {
    position: sticky; top: 0; z-index: 50;
    min-height: 54px; height: auto;
    padding: 4px 10px; padding-top: max(4px, env(safe-area-inset-top));
    gap: 8px;
  }
  .brand-area { min-width: 0; flex: 0 0 auto; }
  .biatrader-logo { width: 92px !important; height: 44px !important; flex-basis: 92px !important; object-fit: contain; }
  .header-actions { gap: 6px; flex: 1 1 auto; justify-content: flex-end; min-width: 0; }
  .market-clock, .header-status-dot, .client-chip { display: none !important; }
  .view-switch > span { display: none; }
  .view-switch select { max-width: 112px; font-size: 13px !important; padding: 5px 6px; }
  .theme-toggle { width: 32px; height: 32px; font-size: 15px; }
  .logout-button { min-width: 0 !important; padding: 6px 10px !important; font-size: 11px !important; }

  /* ---------- bottom tab bar (the sidebar becomes app tabs) ---------- */
  .terminal-sidebar {
    display: block !important;
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    z-index: 60; width: 100% !important; height: auto; min-height: 0;
    padding: 0 0 env(safe-area-inset-bottom); margin: 0;
    background: rgba(4, 18, 29, .97);
    border-top: 1px solid rgba(242, 189, 89, .35); border-right: 0;
    box-shadow: 0 -6px 18px rgba(0, 0, 0, .35);
    backdrop-filter: blur(8px);
  }
  .sidebar-session { display: none !important; }
  .terminal-nav {
    display: flex !important; flex-direction: row; gap: 0;
    overflow-x: auto; scrollbar-width: none; padding: 0; margin: 0;
  }
  .terminal-nav::-webkit-scrollbar { display: none; }
  .terminal-nav .nav-item {
    flex: 1 1 0; min-width: 52px; overflow: hidden; text-overflow: ellipsis;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 7px 2px 6px !important; margin: 0;
    font-size: 9px !important; letter-spacing: 0; line-height: 1.1;
    border: 0 !important; border-radius: 0 !important; background: transparent !important;
    color: #9fb6c8; text-align: center; white-space: nowrap;
  }
  .terminal-nav .nav-item .nav-icon { font-size: 18px; width: auto; height: auto; margin: 0; background: none; border: 0; }
  .terminal-nav .nav-item.active { color: #f2bd59 !important; box-shadow: inset 0 2px 0 #f2bd59; }

  .terminal-layout { grid-template-columns: 1fr !important; }
  .terminal-main { padding-bottom: calc(70px + env(safe-area-inset-bottom)); min-width: 0; }

  /* ---------- pages ---------- */
  body .pro-page, body .strategy-page { padding: 14px 12px !important; }
  body .pro-head h1, body .strategy-page-head h1 { font-size: 26px; }

  /* strategy card header: title on top, badges below */
  body .strategy-runtime-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  body .strategy-title-wrap { align-items: flex-start; }
  body .strategy-status-wrap { display: flex; flex-wrap: wrap; gap: 6px; }

  /* runtime tiles: let numbers wrap instead of "₹ 1,839…" */
  body .rt-tile strong { white-space: normal; overflow: visible; font-size: 17px; word-break: break-word; }
  body .rt-tile small { white-space: normal; }

  /* wide tables scroll sideways inside their card */
  body .rt-body table, body .pro-panel table, body .table-scroll table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  body .table-scroll { overflow-x: auto; }

  /* run mode + action buttons stack neatly */
  body .mode-switch { flex-wrap: wrap; gap: 8px; }
  body .mode-switch .mode-option { flex: 1 1 140px; }
  body .strategy-actions { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
  body .strategy-actions > * { width: 100%; text-align: center; justify-content: center; }

  /* bigger touch targets for form controls */
  input, select, textarea { font-size: 16px !important; } /* stops Android/iOS zooming into fields */
}

@media (max-width: 400px) {
  .biatrader-logo { width: 80px !important; flex-basis: 80px !important; }
  .view-switch select { max-width: 92px; }
}

/* Light theme for the tab bar */
@media (max-width: 780px) {
  html[data-theme="light"] .terminal-sidebar { background: rgba(255, 255, 255, .97); border-top-color: #e3c37a; box-shadow: 0 -4px 14px rgba(20, 40, 60, .12); }
  html[data-theme="light"] .terminal-nav .nav-item { color: #5b6f80; }
  html[data-theme="light"] .terminal-nav .nav-item.active { color: #b7791f !important; box-shadow: inset 0 2px 0 #c88329; }
}

/* ---------- sign-in page (all screen sizes) ---------- */
body.signed-out .terminal-sidebar, body.signed-out .header-actions > :not(.theme-toggle) { display: none !important; }
body.signed-out .terminal-layout { grid-template-columns: 1fr !important; }
.login-wrapper { min-height: calc(100vh - 140px); display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; box-sizing: border-box; padding: 28px 24px;
  background: linear-gradient(180deg, #0b2a40, #071d2d); border: 1px solid #29465c; border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; color: #fff; }
.login-card .muted { margin: 0 0 20px; color: #8fa8bb; }
.login-card form { display: grid; gap: 8px; }
.login-card label { color: #9fb6c8; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; margin-top: 6px; }
.login-card input { width: 100%; box-sizing: border-box; padding: 12px 14px; border-radius: 10px; border: 1px solid #315069; background: #041624; color: #fff; font-size: 16px; }
.login-card input:focus { outline: none; border-color: #f2bd59; box-shadow: 0 0 0 3px rgba(242, 189, 89, .18); }
.login-card button { margin-top: 14px; padding: 13px; border-radius: 10px; font-size: 15px; font-weight: 800; letter-spacing: 1px; }
html[data-theme="light"] .login-card { background: #fff; border-color: #d9e2ea; box-shadow: 0 14px 30px rgba(20, 40, 60, .12); }
html[data-theme="light"] .login-card h1 { color: #0b2a40; }
html[data-theme="light"] .login-card input { background: #f6f9fb; border-color: #cfdbe5; color: #0b2a40; }
.login-error { margin: 0 0 12px; padding: 10px 12px; border-radius: 9px; background: rgba(229, 72, 77, .14); border: 1px solid rgba(229, 72, 77, .45); color: #ff9b9e; font-size: 13px; font-weight: 600; }

/* ---------- daily Zebu login banner ---------- */
.zebu-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 12px 18px 0; padding: 10px 14px; border-radius: 10px; font-size: 13px; line-height: 1.45;
  background: rgba(242, 189, 89, .12); border: 1px solid rgba(242, 189, 89, .45); color: #f6dca4; }
.zebu-banner b { color: #ffd67b; }
.zebu-banner-btn { flex: 0 0 auto; padding: 7px 14px; border-radius: 8px; font-weight: 800; font-size: 12.5px; text-decoration: none;
  color: #061722 !important; background: linear-gradient(180deg, #f2bd59, #c88329); border: 1px solid #ffd67b; }
html[data-theme="light"] .zebu-banner { background: #fff7e6; border-color: #e8c272; color: #6b4a0f; }
html[data-theme="light"] .zebu-banner b { color: #8a5a00; }
@media (max-width: 780px) { .zebu-banner { margin: 10px 12px 0; } }

.nav-badge { display: inline-block; min-width: 16px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #ff5a5f; color: #fff; font-size: 10px; line-height: 16px; text-align: center; font-weight: 800; }

/* ---------- BUY / SELL tags (positions, trades, strategies) ---------- */
.bs-tag { display: inline-block; min-width: 34px; text-align: center; font-size: 10.5px; font-weight: 800; letter-spacing: .4px;
  border-radius: 6px; padding: 2px 6px; vertical-align: middle; }
.bs-tag.buy { background: rgba(34, 195, 142, .16); color: #5be3b0; border: 1px solid #1f7358; }
.bs-tag.sell { background: rgba(240, 86, 108, .16); color: #ff8a9a; border: 1px solid #8a3040; }
html[data-theme="light"] .bs-tag.buy { background: #e4f6ee; color: #0a7a54; border-color: #a8dcc5; }
html[data-theme="light"] .bs-tag.sell { background: #fdecef; color: #b0263d; border-color: #f1b6c0; }

/* ---------- new-position alerts (alerts.js) ---------- */
.sound-toggle { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 16px;
  border: 1px solid rgba(242, 189, 89, .45); background: rgba(242, 189, 89, .08); user-select: none; }
.sound-toggle.muted { opacity: .6; border-color: rgba(159, 182, 200, .4); background: transparent; }
.sound-toggle:focus-visible { outline: 2px solid #f2bd59; outline-offset: 2px; }
#bia-toasts { position: fixed; right: 16px; bottom: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; max-width: min(360px, calc(100vw - 32px)); }
.bia-toast { position: relative; padding: 12px 34px 12px 14px; border-radius: 12px; background: #0b2a40; color: #e8f1f7; font-size: 13px; line-height: 1.45;
  border: 1px solid #29465c; border-left: 4px solid #f2bd59; box-shadow: 0 12px 30px rgba(0, 0, 0, .4); animation: bia-toast-in .25s ease-out; transition: opacity .35s, transform .35s; }
.bia-toast.buy { border-left-color: #16c784; }
.bia-toast.sell { border-left-color: #ff5a5f; }
.bia-toast.out { opacity: 0; transform: translateY(8px); }
.bia-toast-title { font-weight: 800; margin-bottom: 4px; }
.bia-toast-sub { color: #9fb6c8; font-size: 12px; margin-top: 3px; }
.bia-toast-live { display: inline-block; padding: 0 6px; border-radius: 5px; background: #ff5a5f; color: #fff; font-size: 10px; vertical-align: middle; }
.bia-toast-x { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: #9fb6c8; font-size: 18px; cursor: pointer; line-height: 1; }
@keyframes bia-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
html[data-theme="light"] .bia-toast { background: #fff; color: #0b2a40; border-color: #d9e2ea; box-shadow: 0 12px 30px rgba(20, 40, 60, .15); }
html[data-theme="light"] .bia-toast-sub, html[data-theme="light"] .bia-toast-x { color: #5b6f80; }
@media (max-width: 780px) {
  #bia-toasts { right: 12px; left: 12px; max-width: none; bottom: calc(78px + env(safe-area-inset-bottom)); }
  .sound-toggle { width: 32px; height: 32px; font-size: 15px; }
}

/* ---------- manual close (position_close.js) ---------- */
.close-pos-btn { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; padding: 3px 9px; border-radius: 7px; cursor: pointer;
  font: 700 11px/1.4 Inter, sans-serif; color: #ffb3bc; background: rgba(240, 86, 108, .12); border: 1px solid #8a3040; white-space: nowrap; vertical-align: middle; }
.close-pos-btn:hover { background: rgba(240, 86, 108, .25); color: #fff; }
.pc-modal { position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center; padding: 16px; background: rgba(2, 10, 18, .72); }
.pc-box { width: 100%; max-width: 440px; background: #0b2a40; color: #e8f1f7; border: 1px solid #29465c; border-radius: 14px; padding: 20px 22px; box-shadow: 0 18px 40px rgba(0, 0, 0, .45); font-size: 13.5px; line-height: 1.5; }
.pc-box h2 { margin: 0 0 10px; font-size: 18px; }
.pc-pos { margin: 0 0 10px; font-size: 14px; }
.pc-pos small { color: #9fb6c8; }
.pc-live { color: #ff8a9a; font-weight: 800; }
.pc-warn { background: #3a1419; border: 1px solid #8a3040; color: #ffc2ca; border-radius: 9px; padding: 8px 11px; font-weight: 600; font-size: 12.5px; }
.pc-note { color: #b9cad8; font-size: 12.5px; }
.pc-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.pc-btn { height: 36px; padding: 0 14px; border-radius: 9px; font-weight: 800; font-size: 12.5px; cursor: pointer; border: 1px solid #315069; }
.pc-btn.ghost { background: transparent; color: #cfe0ec; }
.pc-btn.dark { background: #3a1419; color: #ffc2ca; border-color: #8a3040; }
.pc-btn.gold { background: linear-gradient(180deg, #f2bd59, #c88329); color: #061722; border-color: #ffd67b; }
.pc-btn:disabled { opacity: .55; cursor: wait; }
.pc-msg { margin: 10px 0 0; font-size: 12.5px; color: #9fb6c8; }
.pc-msg.err { color: #ff9b9e; font-weight: 600; }
html[data-theme="light"] .pc-box { background: #fff; color: #0b2a40; border-color: #d9e2ea; }
html[data-theme="light"] .pc-note, html[data-theme="light"] .pc-pos small { color: #5b6f80; }
html[data-theme="light"] .pc-btn.ghost { color: #0b2a40; border-color: #cfdbe5; }
html[data-theme="light"] .close-pos-btn { color: #b0263d; background: #fdecef; border-color: #f1b6c0; }
@media (max-width: 780px) { .pc-actions .pc-btn { flex: 1 1 auto; } }
