/* ===========================================================================
   Mobile layer for the Election CaRe System. Loaded AFTER ceras-theme.css on every page.
   Phones and small tablets only; nothing here changes the desktop layout.
   - top bar collapses to a menu button (mobile.js adds it)
   - tables become one card per row, labelled from the column headings (mobile.js adds the labels)
   - forms, filters and buttons become single-column with thumb-sized targets
   =========================================================================== */
html { -webkit-text-size-adjust: 100%; }
img, video, canvas, svg { max-width: 100%; }
.m-nav-btn { display: none; }
.m-bars, .m-bars::before, .m-bars::after { display: block; width: 20px; height: 2.5px; border-radius: 2px; background: currentColor; transition: transform .18s, background .18s; }
.m-bars { position: relative; }
.m-bars::before, .m-bars::after { content: ''; position: absolute; left: 0; }
.m-bars::before { top: -6px; } .m-bars::after { top: 6px; }
.m-nav-btn.is-open .m-bars { background: transparent; }
.m-nav-btn.is-open .m-bars::before { top: 0; transform: rotate(45deg); }
.m-nav-btn.is-open .m-bars::after { top: 0; transform: rotate(-45deg); }
.m-val { min-width: 0; }

/* ============================================================
   TOP NAVIGATION: dark blue bar, gold line underneath, white pill on the
   active tab, gold avatar. (Desktop; the phone menu is further down.)
   ============================================================ */
.topnav {
  background: linear-gradient(90deg, #14335f 0%, #1c4379 55%, #1a3f74 100%) !important;
  height: 72px; padding: 0 28px; gap: 32px;
  border-bottom: 3px solid #e8a84a !important;
  box-shadow: 0 6px 18px rgba(10,24,52,0.25) !important;
}
.topnav-brand { gap: 12px; }
.topnav-brand .header-logo { height: 48px !important; }
.topnav-brand-name { display: flex; flex-direction: column; color: #fff !important; font-size: 21px; font-weight: 700; letter-spacing: 0; line-height: 1.15; }
.topnav-brand-name::after { content: 'ELECTION COMMISSION OF BHUTAN'; font-size: 11.5px; font-weight: 500; letter-spacing: 0.09em; color: rgba(255,255,255,0.72); margin-top: 3px; }
.topnav-links { gap: 6px; }
.topnav-links::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.28); }
.topnav-link { color: rgba(255,255,255,0.92) !important; font-size: 16px; font-weight: 500; padding: 11px 22px; border-radius: 999px; }
.topnav-link:hover { background: rgba(255,255,255,0.12) !important; color: #fff !important; }
.topnav-link.active { background: #fff !important; color: #14335f !important; font-weight: 700; box-shadow: none !important; }
.topnav-avatar { width: 48px !important; height: 48px !important; background: #e8a84a !important; color: #14335f !important; font-size: 18px; font-weight: 800; box-shadow: 0 0 0 3px rgba(232,168,74,0.35) !important; }
.topnav-user-menu { top: 60px !important; }

@media (max-width: 900px) {
  /* ---------- top bar: brand, menu button, avatar ---------- */
  .topnav { padding: 0 14px !important; gap: 10px !important; height: 60px !important; }
  .topnav-brand .header-logo { height: 34px !important; }
  .topnav-brand-name { display: none !important; }
  .topnav-links { display: none !important; }
  .topnav-user { margin-left: auto; }
  .topnav-avatar { width: 40px !important; height: 40px !important; }
  .m-nav-btn {
    display: inline-flex; align-items: center; justify-content: center; order: 3;
    width: 42px; height: 42px; border-radius: 12px; border: 1.5px solid var(--border, #d9e0ee);
    background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.4); color: #fff; font-size: 18px; cursor: pointer; flex: 0 0 auto;
  }
  .topnav-user { order: 4; margin-left: 0 !important; }
  .topnav-brand { margin-right: auto; }
  body.m-menu-open .topnav-links {
    display: flex !important; flex-direction: column; align-items: stretch; gap: 4px !important;
    position: fixed; top: 60px; left: 0; right: 0; height: auto !important; max-height: calc(100vh - 60px);
    max-height: calc(100dvh - 60px); overflow-y: auto; background: #14335f; padding: 10px 12px 16px;
    border-bottom: 3px solid #e8a84a; box-shadow: 0 18px 30px rgba(10,20,40,.18); z-index: 190;
  }
  body.m-menu-open .topnav-link { width: 100%; min-height: 48px; padding: 12px 16px !important; font-size: 16px !important; justify-content: flex-start; }
  body.m-menu-open .topnav-link { border-radius: 14px; }
  .topnav-avatar { width: 40px !important; height: 40px !important; font-size: 15px; }
  body.m-menu-open { overflow: hidden; }
  .m-backdrop { display: none; }
  body.m-menu-open .m-backdrop { display: block; position: fixed; inset: 60px 0 0 0; background: rgba(10,20,40,.35); z-index: 180; }
  .topnav-user-menu { right: 0; max-width: calc(100vw - 24px); }
}

@media (max-width: 760px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  body { font-size: 15px; }

  /* ---------- page frame ---------- */
  .page-hero { padding: 22px 0 70px !important; }
  .page-hero-inner, .app-shell .app-content, .app-content { padding-left: 14px !important; padding-right: 14px !important; }
  .page-hero h1 { font-size: 25px !important; letter-spacing: -0.4px !important; line-height: 1.2; }
  .hero-sub { font-size: 14px !important; line-height: 1.5; }
  .breadcrumb-trail { font-size: 13px !important; margin-bottom: 10px !important; }
  .page-hero-inner { flex-direction: column; align-items: stretch !important; gap: 14px !important; }
  .hero-actions { flex-wrap: wrap; width: 100%; }
  .hero-actions > *, .hero-actions .btn, .hero-select { flex: 1 1 100%; width: 100%; }
  .hero-select select { width: 100%; }
  .app-content { padding-top: 16px; padding-bottom: 28px; }

  /* ---------- cards, grids, stats ---------- */
  .card { border-radius: 16px; }
  .card-header { padding: 14px 16px !important; flex-wrap: wrap; gap: 8px 12px; }
  .card-header h3 { font-size: 16px !important; }
  .card-body { padding: 14px 16px !important; }
  .ret-wrap, .row2, .row3, .summary, .v-grid, .candidate-grid, .stats-grid, .stat-grid, .form-row, .form-grid,
  .form-row.cols-2, .form-row.cols-3, .cid-row, .two-col, .three-col, .grid-2, .grid-3, .election-grid, .cards-grid,
  [class*="-grid"]:not(.fa) { grid-template-columns: 1fr !important; }
  .ret-wrap > *, .row2 > *, .summary > *, .v-grid > * { min-width: 0; }
  .sum-row { gap: 14px 22px !important; }
  .who-card { gap: 10px 22px !important; }
  .deadline-box { flex-direction: column; align-items: flex-start !important; }
  .submit-row { flex-direction: column; align-items: stretch !important; }
  .submit-row .btn { width: 100%; }
  .timeline { margin-left: -4px; margin-right: -4px; }
  .tl-step { font-size: 11px !important; }

  /* ---------- buttons, inputs: thumb-sized, no iOS zoom ---------- */
  .btn, button.btn, a.btn { min-height: 46px; padding-top: 11px; padding-bottom: 11px; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
  .btn-sm { min-height: 42px !important; font-size: 14px !important; padding-left: 14px; padding-right: 14px; }
  input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=search],
  input[type=date], input[type=url], select, textarea { font-size: 16px !important; min-height: 46px; max-width: 100%; box-sizing: border-box; }
  textarea { min-height: 96px; }
  input[type=file] { max-width: 100%; font-size: 14px; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  .check-row, .check-row label, label.check { align-items: flex-start; gap: 12px; }
  .radio-pill span { padding: 12px 22px; }
  .page-btn { min-width: 42px; height: 42px; }
  .row-actions { flex-wrap: wrap; gap: 8px; }

  /* ---------- filters, toolbars, tabs ---------- */
  .filter-bar, .toolbar, .bulk-bar, .filter-stack, .card-actions, .act-row, .modal-footer, .form-actions {
    flex-direction: column; align-items: stretch !important; gap: 10px !important;
  }
  .filter-bar, .app-shell .card > .filter-bar { padding: 14px 16px !important; }
  .filter-bar input, .filter-bar select, .filter-stack input, .filter-stack select, .search-pill, .toolbar input, .toolbar select {
    width: 100% !important; min-width: 0 !important; max-width: none !important; flex: 1 1 auto;
  }
  .bulk-bar .btn, .act-row .btn, .modal-footer .btn, .form-actions .btn, .toolbar .btn { width: 100%; }
  .pill-tabs, .section-tabs, .tabs { display: flex; overflow-x: auto; flex-wrap: nowrap; gap: 8px; padding-bottom: 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .pill-tabs::-webkit-scrollbar, .section-tabs::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  .pill-tab, .section-tab, .tab { flex: 0 0 auto; white-space: nowrap; min-height: 42px; }

  /* ---------- pagination ---------- */
  .pagination { flex-direction: column; align-items: center !important; gap: 10px; padding: 14px 16px !important; text-align: center; }
  .pagination-btns { flex-wrap: wrap; justify-content: center; }

  /* ---------- tables become cards ---------- */
  .table-wrap { overflow-x: visible !important; }
  table.m-stack { display: block; width: 100%; border: 0; min-width: 0 !important; }
  table.m-stack thead { display: none; }
  table.m-stack tbody { display: block; }
  table.m-stack tr { display: block; margin: 0 0 12px; padding: 4px 14px; background: #fff; border: 1px solid var(--border-light, #e6ebf5); border-radius: 14px; box-shadow: 0 2px 8px rgba(20,51,95,.05); }
  table.m-stack tr.clickable-row:active { background: #f4f7fc; }
  table.m-stack td, table.m-stack th {
    display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; text-align: right;
    width: auto !important; min-width: 0 !important; max-width: none !important; padding: 10px 0 !important;
    border: 0 !important; border-bottom: 1px solid var(--border-light, #eef1f7) !important; overflow-wrap: anywhere;
  }
  table.m-stack td:last-child { border-bottom: 0 !important; }
  table.m-stack td[data-label]::before {
    content: attr(data-label); flex: 0 0 38%; max-width: 42%; text-align: left; font-size: 11px; font-weight: 700;
    letter-spacing: .5px; text-transform: uppercase; color: var(--text-muted, #6b7a99); padding-top: 3px;
  }
  table.m-stack td[data-label=""]::before { content: none; }
  table.m-stack td > * { max-width: 100%; }
  table.m-stack td > .m-val { flex: 1 1 auto; text-align: right; }
  table.m-stack td.currency, table.m-stack td[style*="text-align:right"] { text-align: right !important; }
  table.m-stack td[colspan] { display: block; text-align: center; }
  table.m-stack td[colspan]::before { content: none; }
  table.m-stack tr:has(> td[colspan]) { padding: 8px; }
  table.m-stack .row-actions, table.m-stack td .btn { justify-content: flex-end; }
  table.m-stack td:has(> .row-actions) { flex-direction: column; align-items: stretch; }
  table.m-stack td:has(> .row-actions)::before { content: none; }
  table.m-stack td:has(> .row-actions) .row-actions { justify-content: stretch; }
  table.m-stack td:has(> .row-actions) .btn { flex: 1 1 100%; }

  /* ---------- modals, side panels ---------- */
  .modal-overlay { padding: 0 !important; align-items: flex-end !important; }
  .modal { max-width: 100% !important; width: 100% !important; max-height: 94vh !important; max-height: 94dvh !important; border-radius: 20px 20px 0 0 !important; }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px !important; padding-right: 16px !important; }
  .modal-body { padding-top: 16px; padding-bottom: 16px; }
  .detail-overlay { padding: 0 !important; align-items: flex-end !important; }
  .detail-panel { max-width: 100% !important; border-radius: 20px 20px 0 0 !important; margin-bottom: 0 !important; max-height: 94vh; max-height: 94dvh; overflow-y: auto !important; }
  .detail-overlay.show { align-items: flex-end; }
  .mobile-close { display: inline-flex; }

  #returnsBanner { flex-direction: column; align-items: stretch !important; }
  #returnsBanner .btn { width: 100%; }

  /* ---------- misc ---------- */
  .cand-card { padding: 16px; }
  .cand-view-btn { min-height: 46px; }
  .toast, #toast { left: 12px !important; right: 12px !important; bottom: 12px !important; max-width: none !important; width: auto !important; text-align: center; }
  .g-toolbar button { min-height: 42px; }
  .g-body { padding: 2px 16px 18px !important; font-size: 15px !important; }
  details.g-sec > summary { padding: 14px 16px !important; font-size: 15px !important; }
  .state { padding: 22px 6px !important; }
  .ref-box { font-size: 18px !important; padding: 10px 16px !important; }
  pre, code { overflow-x: auto; max-width: 100%; }
}

@media (max-width: 420px) {
  .btn { width: auto; }                 /* the theme made every button full width here; keep that only where we ask for it */
  .card-body .btn, .modal-footer .btn, .submit-row .btn, .bulk-bar .btn, .act-row .btn, .toolbar .btn { width: 100%; }
  .page-hero h1 { font-size: 22px !important; }
  table.m-stack td[data-label]::before { flex-basis: 34%; }
}

@media print { .m-nav-btn, .m-backdrop { display: none !important; } }