.topbar .mobile-menu-btn { display: none; }

/* Tablet (<= 1120px) */
@media (max-width: 1120px) {
  :root {
    --sidebar-w: 214px;
  }
  .topbar {
    padding: 0 20px;
  }
  .content-wrap {
    padding: 22px 20px 40px;
  }
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-main {
    grid-template-columns: 1fr;
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .global-search {
    width: 170px;
  }
}

/* Mobile & iPhone (<= 768px) */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .main-area {
    margin-left: 0;
    width: 100%;
  }

  .topbar {
    height: 58px;
    padding: 0 14px;
  }

  .global-search {
    display: none;
  }

  .demo-pill {
    display: none;
  }

  .role-switcher {
    max-width: 118px;
    font-size: 11.5px;
    padding: 0 6px;
    height: 32px;
  }

  .topbar .mobile-menu-btn {
    display: grid;
  }

  .content-wrap {
    padding: 18px 14px calc(var(--mobile-nav-h) + 24px + env(safe-area-inset-bottom));
  }

  .page-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
  }

  .page-title {
    font-size: 21px;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions .select-control {
    flex: 1;
  }

  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .grid-3, .grid-2, .grid-main {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stat-card {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .stat-value {
    font-size: 19px;
    margin: 9px 0 4px;
  }

  .stat-foot {
    font-size: 11px;
  }

  .panel {
    border-radius: var(--radius-md);
  }

  .panel-head {
    padding: 14px 15px 10px;
  }

  .panel-body {
    padding: 4px 15px 15px;
  }

  .donut-layout {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .donut-layout svg {
    margin: 0 auto;
  }

  /* Switch desktop transaction table to mobile cards */
  .desktop-table-only {
    display: none;
  }

  .tx-card-list {
    display: flex;
    flex-direction: column;
  }

  .tx-date-group-label {
    padding: 8px 15px;
    background: var(--surface-2);
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-size: 11.5px;
    font-weight: 650;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
  }

  .tx-mobile-card {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 13px 15px;
    border-bottom: 1px solid #f1f4f8;
    background: var(--surface);
    cursor: pointer;
  }

  .tx-mobile-card:active {
    background: var(--surface-2);
  }

  .tx-mobile-main {
    flex: 1;
    min-width: 0;
  }

  .tx-mobile-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
  }

  .tx-mobile-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 4px;
    font-size: 11.5px;
    color: var(--muted);
  }

  .filter-bar {
    padding: 12px 14px;
  }

  .filter-bar .select-control,
  .filter-bar .input-control {
    flex: 1 1 130px;
    min-width: 0;
  }

  /* Mobile bottom sheet modal */
  .backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box {
    width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .drawer-box {
    width: 100%;
    height: 92vh;
    border-radius: 20px 20px 0 0;
    margin-top: auto;
    padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  }

  .form-row-2 {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* Mobile Bottom Navigation */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    z-index: 25;
    justify-content: space-around;
    align-items: center;
  }

  .mobile-nav-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 56px;
    min-height: 44px;
    padding: 4px 6px;
    border-radius: 10px;
  }

  .mobile-nav-btn svg {
    width: 20px;
    height: 20px;
  }

  .mobile-nav-btn.active {
    color: var(--accent);
    font-weight: 700;
  }

  .mobile-nav-add {
    background: var(--accent);
    color: #fff;
    width: 46px;
    height: 46px;
    border-radius: 15px;
    min-width: 46px;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.28);
  }

  .toast {
    bottom: calc(var(--mobile-nav-h) + 16px + env(safe-area-inset-bottom));
  }
}

/* Small phones (375px) */
@media (max-width: 390px) {
  .stat-value {
    font-size: 17px;
  }
  .page-title {
    font-size: 19px;
  }
}


/* === Interactive iOS Device Preview Mode (Desktop Evaluator Switcher) === */
.preview-toolbar {
  position: fixed;
  top: 12px;
  right: 20px;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 5px 8px 5px 12px;
  box-shadow: var(--shadow-md);
}

.preview-toolbar-brand {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-2);
  white-space: nowrap;
}

body:not(.iphone-mode) .preview-toolbar {
  top: auto;
  bottom: 16px;
  right: 20px;
}

body:not(.iphone-mode) .ios-statusbar,
body:not(.iphone-mode) .ios-home-indicator {
  display: none;
}

body.iphone-mode {
  background: radial-gradient(circle at 20% 10%, #e5ecfa 0%, #eef0f5 48%, #e8e8ee 100%);
  min-height: 100vh;
}

body.iphone-mode .preview-toolbar {
  position: sticky;
  top: 0;
  right: auto;
  justify-content: center;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  padding: 10px 16px;
}

body.iphone-mode .device-stage {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px 16px 36px;
}

body.iphone-mode .device-bezel {
  width: 414px;
  height: 868px;
  background: #1c1c1e;
  border-radius: 54px;
  padding: 12px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.24), inset 0 0 0 2px #3a3a3c;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

body.iphone-mode.iphone-se .device-bezel {
  width: 399px;
  height: 720px;
  border-radius: 40px;
}

body.iphone-mode .ios-statusbar {
  height: 44px;
  background: #ffffff;
  border-radius: 42px 42px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  flex: none;
  position: relative;
  z-index: 30;
}

body.iphone-mode.iphone-se .ios-statusbar {
  height: 30px;
  border-radius: 28px 28px 0 0;
}

body.iphone-mode .ios-time {
  font-size: 13px;
  font-weight: 700;
  color: #1d1d1f;
}

body.iphone-mode .ios-island {
  width: 96px;
  height: 24px;
  background: #000;
  border-radius: 99px;
}

body.iphone-mode.iphone-se .ios-island {
  display: none;
}

body.iphone-mode .ios-indicators {
  font-size: 11px;
  font-weight: 700;
  color: #1d1d1f;
}

body.iphone-mode .device-viewport {
  flex: 1;
  background: var(--bg);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.iphone-mode .ios-home-indicator {
  height: 22px;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 0 0 42px 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

body.iphone-mode.iphone-se .ios-home-indicator {
  border-radius: 0 0 28px 28px;
}

body.iphone-mode .ios-home-indicator span {
  width: 126px;
  height: 5px;
  border-radius: 99px;
  background: #1d1d1f;
  opacity: 0.85;
}

/* Force Mobile iOS Layout inside iPhone Preview Frame */
body.iphone-mode .app-shell {
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

body.iphone-mode .sidebar { display: none; }
body.iphone-mode .main-area { margin-left: 0; width: 100%; min-height: 100%; }
body.iphone-mode .topbar { height: 52px; padding: 0 14px; position: sticky; top: 0; }
body.iphone-mode .global-search,
body.iphone-mode .demo-pill { display: none; }
body.iphone-mode .topbar .mobile-menu-btn { display: grid; }
body.iphone-mode .role-switcher { max-width: 116px; font-size: 11.5px; padding: 0 6px; height: 32px; }
body.iphone-mode .content-wrap { padding: 14px 13px 86px; }
body.iphone-mode .page-header { align-items: flex-start; flex-direction: column; gap: 10px; margin-bottom: 14px; }
body.iphone-mode .page-title { font-size: 20px; }
body.iphone-mode .page-subtitle { font-size: 12px; }
body.iphone-mode .page-actions { width: 100%; }
body.iphone-mode .page-actions .select-control { flex: 1; }
body.iphone-mode .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
body.iphone-mode .grid-3,
body.iphone-mode .grid-2,
body.iphone-mode .grid-main { grid-template-columns: 1fr; gap: 12px; }
body.iphone-mode .stat-card { padding: 13px; border-radius: var(--radius-md); }
body.iphone-mode .stat-value { font-size: 18px; margin: 8px 0 4px; }
body.iphone-mode .stat-foot { font-size: 11px; }
body.iphone-mode .panel { border-radius: var(--radius-md); }
body.iphone-mode .panel-head { padding: 13px 14px 10px; }
body.iphone-mode .panel-body { padding: 4px 14px 14px; }
body.iphone-mode .donut-layout { flex-direction: column; align-items: stretch; gap: 14px; }
body.iphone-mode .donut-layout svg { margin: 0 auto; }
body.iphone-mode .desktop-table-only { display: none; }
body.iphone-mode .tx-card-list { display: flex; flex-direction: column; }
body.iphone-mode .tx-date-group-label {
  padding: 8px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}
body.iphone-mode .tx-mobile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #f1f4f8;
  background: var(--surface);
  cursor: pointer;
}
body.iphone-mode .tx-mobile-main { flex: 1; min-width: 0; }
body.iphone-mode .tx-mobile-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
body.iphone-mode .tx-mobile-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 4px; font-size: 11px; color: var(--muted); }
body.iphone-mode .filter-bar { padding: 10px 12px; }
body.iphone-mode .filter-bar .select-control,
body.iphone-mode .filter-bar .input-control { flex: 1 1 130px; min-width: 0; }
body.iphone-mode .form-row-2 { grid-template-columns: 1fr; gap: 0; }

/* Pin Bottom Nav, Bottom Sheets & Toast inside the iPhone Viewport */
body.iphone-mode .mobile-nav {
  display: flex;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 62px;
  padding: 5px 6px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 25;
  justify-content: space-around;
  align-items: center;
}

body.iphone-mode .mobile-nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 52px;
  min-height: 44px;
  padding: 4px 6px;
  border-radius: 10px;
}

body.iphone-mode .mobile-nav-btn svg { width: 20px; height: 20px; }
body.iphone-mode .mobile-nav-btn.active { color: var(--accent); font-weight: 700; }
body.iphone-mode .mobile-nav-add {
  background: var(--accent);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  min-width: 44px;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.28);
}

body.iphone-mode .backdrop {
  position: absolute;
  align-items: flex-end;
  padding: 0;
}

body.iphone-mode .modal-box,
body.iphone-mode .drawer-box {
  width: 100%;
  height: auto;
  max-height: 90%;
  border-radius: 20px 20px 0 0;
  padding: 16px 15px 18px;
}

body.iphone-mode .toast {
  position: absolute;
  bottom: 72px;
  max-width: 90%;
}

/* On real mobile screens, never show the simulator bezel or toolbar */
@media (max-width: 768px) {
  .preview-toolbar,
  .ios-statusbar,
  .ios-home-indicator {
    display: none !important;
  }
}
