/* OnAndMe Command Center mobile app shell.
 * Desktop rules stay in index.html; this file only changes compact/app layouts.
 */

:root {
  --mobile-nav-height: 72px;
  --mobile-header-height: 60px;
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-safe-top: env(safe-area-inset-top, 0px);
}

.mobile-only,
.mobile-install-banner {
  display: none;
}

@media (max-width: 768px), (hover: none) and (pointer: coarse) and (max-width: 1366px), (display-mode: standalone) and (max-width: 1366px) {
  :root {
    --bg: #f4f6fa;
    --surface: #fff;
    --border: #e8ebf1;
    --text: #172033;
    --sub: #667085;
    --muted: #98a2b3;
    --indigo: #5b5ce2;
    --radius: 18px;
    --shadow: 0 8px 26px rgba(23, 32, 51, .06);
  }

  html {
    background: var(--bg);
    overscroll-behavior: none;
  }

  body {
    min-height: 100dvh;
    height: 100dvh;
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
  }

  body.cmd-mobile-app {
    padding-top: var(--mobile-safe-top);
  }

  .mobile-only {
    display: flex;
  }

  body > header {
    height: var(--mobile-header-height);
    padding: 0 15px;
    border-bottom: 1px solid rgba(226, 232, 240, .82);
    box-shadow: none;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: saturate(160%) blur(18px);
    -webkit-backdrop-filter: saturate(160%) blur(18px);
  }

  body > header .logo {
    min-width: 0;
    gap: 9px;
  }

  body > header .logo img {
    width: 30px !important;
    height: 30px !important;
    border-radius: 9px;
  }

  body > header .logo > span {
    max-width: 52vw;
    overflow: hidden;
    color: var(--text);
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -.025em;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body > header .header-right {
    gap: 7px;
  }

  body > header .credit-pill,
  body > header .clock-pill,
  body > header #header-user-name,
  body > header a[href*="claude.ai"],
  body > header .header-right > .hbtn:not([href="/logout"]) {
    display: none !important;
  }

  body > header .live-pill {
    width: 30px;
    height: 30px;
    justify-content: center;
    overflow: hidden;
    padding: 0;
    border: 0;
    background: #ecfdf3;
    color: transparent;
    font-size: 0;
  }

  body > header .live-dot {
    width: 8px;
    height: 8px;
  }

  body > header a[href="/logout"] {
    width: 34px;
    height: 34px;
    min-height: 34px;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 11px;
    background: #fff1f2;
  }

  .layout {
    min-width: 0;
  }

  #sidebar,
  .sidebar-overlay,
  .mobile-toggle {
    display: none !important;
  }

  .main {
    min-width: 0;
    margin-left: 0 !important;
    padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 8px) !important;
  }

  .tab-bar {
    display: none !important;
  }

  .tab-bar::-webkit-scrollbar {
    display: none;
  }

  .tab-bar .tab {
    min-height: 38px;
    margin: 6px 3px;
    padding: 9px 13px;
    border: 1px solid var(--border) !important;
    border-radius: 999px;
    background: var(--surface);
    color: var(--sub);
    font-size: 12px;
  }

  .tab-bar .tab.active {
    border-color: var(--indigo) !important;
    background: var(--indigo);
    color: #fff;
  }

  .tab-content {
    padding: 12px 12px 20px !important;
    gap: 12px !important;
    overscroll-behavior-y: contain;
    scroll-padding-bottom: calc(var(--mobile-nav-height) + 24px);
  }

  .panel,
  .stat-card,
  .detail-panel,
  .tesla-card {
    border-color: rgba(226, 232, 240, .8) !important;
    border-radius: 18px !important;
    box-shadow: var(--shadow) !important;
  }

  .panel-head {
    min-height: 48px;
    padding: 13px 15px !important;
    border-bottom-color: var(--border);
    font-size: 13px !important;
  }

  .stat-row,
  .cc-stat-row {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  .stat-card {
    min-width: 0;
    min-height: 82px;
    padding: 14px !important;
  }

  .stat-val {
    font-size: 20px !important;
  }

  .two-col,
  .detail-grid,
  .tesla-overview,
  .tesla-main-grid,
  .tesla-section-grid,
  .tesla-side-column,
  .tesla-control-row {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .hbtn,
  button,
  select,
  input,
  textarea {
    border-radius: 12px;
  }

  button,
  .hbtn,
  a.hbtn,
  select {
    min-height: 44px;
  }

  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px !important;
  }

  textarea {
    min-height: 120px;
  }

  [style*="min-width:600px"],
  [style*="min-width: 600px"],
  [style*="min-width:700px"],
  [style*="min-width: 700px"],
  [style*="width:600px"],
  [style*="width: 600px"] {
    min-width: 0 !important;
    width: 100% !important;
  }

  .mobile-table-scroll {
    width: 100%;
    overflow-x: auto;
    border-radius: 14px;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-table-scroll > table {
    min-width: 640px;
  }

  #cal-grid table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  .mobile-nav {
    display: flex !important;
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: calc(8px + var(--mobile-safe-bottom)) !important;
    z-index: 500 !important;
    width: auto;
    height: var(--mobile-nav-height) !important;
    align-items: center;
    justify-content: space-around;
    padding: 7px 6px !important;
    border: 1px solid rgba(226, 232, 240, .9) !important;
    border-radius: 22px;
    background: rgba(255, 255, 255, .96) !important;
    box-shadow: 0 12px 36px rgba(15, 23, 42, .16);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
  }

  .mnav-btn {
    min-width: 0;
    min-height: 56px !important;
    padding: 6px 2px !important;
    border-radius: 16px;
    color: #7b8496 !important;
  }

  .mnav-btn.active {
    background: #eef0ff !important;
    color: var(--indigo) !important;
  }

  .mnav-icon {
    font-size: 20px !important;
  }

  .mnav-label {
    max-width: 100%;
    overflow: hidden;
    font-size: 10px !important;
    font-weight: 750 !important;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .more-sheet-overlay {
    z-index: 600;
    background: rgba(15, 23, 42, .44);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
  }

  .more-sheet {
    z-index: 601;
    max-height: min(82dvh, 760px);
    padding: 10px 14px calc(20px + var(--mobile-safe-bottom));
    overflow-y: auto;
    border-radius: 26px 26px 0 0;
    box-shadow: 0 -20px 60px rgba(15, 23, 42, .2);
  }

  .more-sheet-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 2px 2px 14px;
    font-size: 20px;
    letter-spacing: -.03em;
  }

  .mobile-drawer-section {
    margin: 16px 0 6px;
  }

  .mobile-drawer-section-title {
    margin: 0 4px 8px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
  }

  .mobile-drawer-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 9px;
  }

  .mobile-drawer-item {
    display: flex;
    min-width: 0;
    min-height: 84px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #f8f9fc;
    color: var(--text);
    text-align: left;
  }

  .mobile-drawer-item:active {
    border-color: #c7d2fe;
    background: #eef0ff;
    transform: scale(.98);
  }

  .mobile-drawer-icon {
    font-size: 23px;
  }

  .mobile-drawer-label {
    width: 100%;
    overflow: hidden;
    font-size: 12px;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-install-banner {
    position: fixed;
    right: 12px;
    bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 18px);
    left: 12px;
    z-index: 550;
    align-items: center;
    gap: 11px;
    padding: 12px;
    border: 1px solid #d8dcff;
    border-radius: 18px;
    background: rgba(255, 255, 255, .98);
    box-shadow: 0 16px 40px rgba(23, 32, 51, .18);
  }

  .mobile-install-banner.show {
    display: flex;
  }

  .mobile-install-icon {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border-radius: 13px;
  }

  .mobile-install-copy {
    min-width: 0;
    flex: 1;
  }

  .mobile-install-copy strong,
  .mobile-install-copy span {
    display: block;
  }

  .mobile-install-copy strong {
    margin-bottom: 2px;
    font-size: 13px;
  }

  .mobile-install-copy span {
    color: var(--sub);
    font-size: 11px;
  }

  .mobile-install-action {
    min-height: 38px !important;
    padding: 0 13px;
    border: 0;
    border-radius: 12px;
    background: var(--indigo);
    color: #fff;
    font-size: 12px;
    font-weight: 750;
  }

  .mobile-install-close {
    width: 30px;
    min-height: 30px !important;
    border: 0;
    background: transparent;
    color: var(--muted);
  }

  #_tesla_toast {
    right: 12px !important;
    bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 18px) !important;
    left: 12px !important;
    max-width: none !important;
  }
}

@media (min-width: 700px) and (max-width: 1366px) {
  body.cmd-mobile-app {
    --mobile-nav-height: 76px;
    --mobile-header-height: 64px;
  }

  body.cmd-mobile-app .tab-content {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 18px 20px 28px !important;
    gap: 16px !important;
  }

  body.cmd-mobile-app .stat-row,
  body.cmd-mobile-app .cc-stat-row {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  body.cmd-mobile-app .two-col,
  body.cmd-mobile-app .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body.cmd-mobile-app .mobile-drawer-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  body.cmd-mobile-app .mobile-nav {
    right: auto !important;
    left: 50% !important;
    width: min(720px, calc(100vw - 40px));
    transform: translateX(-50%);
  }

  body.cmd-mobile-app .more-sheet {
    right: auto;
    left: 50%;
    width: min(760px, calc(100vw - 48px));
    border-radius: 26px 26px 0 0;
    transform: translate(-50%, 100%);
  }

  body.cmd-mobile-app .more-sheet.show {
    transform: translate(-50%, 0);
  }

  body.cmd-mobile-app .mobile-install-banner {
    right: auto;
    left: 50%;
    width: min(680px, calc(100vw - 48px));
    transform: translateX(-50%);
  }
}

@media (max-width: 380px) {
  .mobile-drawer-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mnav-label {
    font-size: 9px !important;
  }
}

@media (display-mode: standalone) and (max-width: 1366px) {
  body > header {
    height: calc(var(--mobile-header-height) + 2px);
  }
}
