/* ============================================================
   TABLET APP LAYOUT (7" to 13", html.tab-ui set by js/tablet.js)
   The phone's dark tab bar at the bottom, a little bigger, with
   the + button in the bottom-right corner. Wider screens get more
   tabs; rotating the tablet updates them straight away.
   Below 769px wide components.css already draws the phone shell;
   section 1 draws the same pieces on the bigger screens.
   ============================================================ */

/* Native-app page changes on real tablets (the bar stays put) */
@media (pointer: coarse) and (min-width: 769px) {
  @view-transition { navigation: auto; }
}

/* ---- 1. Phone shell pieces, above 768px wide ---- */
@media (min-width: 769px) {
  html.tab-ui, html.tab-ui body { background: var(--bg); }
  html.tab-ui body { -webkit-tap-highlight-color: transparent; }
  html.tab-ui .sidebar, html.tab-ui .sidebar-overlay, html.tab-ui .hamburger-btn,
  html.tab-ui .app-header-wedding { display: none !important; }
  html.tab-ui .main-content { margin-left: 0 !important; min-width: 0; }
  html.tab-ui body.has-m-tabbar .app-header .header-title,
  html.tab-ui body.has-m-tabbar #headerWeddingName { display: none !important; }

  html.tab-ui .notif-bell {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
  }
  html.tab-ui .notif-badge { top: 1px; right: 1px; }

  /* Forms and detail panels: a floating card on the right, iPad style */
  html.tab-ui .drawer {
    top: 12px;
    right: 12px;
    bottom: 12px;
    height: auto;
    max-width: calc(100vw - 24px);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 24px 60px -12px rgba(28,20,16,.35);
    transform: translateX(calc(100% + 90px));
  }
  html.tab-ui .drawer.open { transform: none; }
  html.tab-ui .modal { border-radius: 24px; }

  html.tab-ui.m-locked, html.tab-ui.m-locked body { overflow: hidden; }

  /* ---- Header ---- */
  html.tab-ui .m-head {
    display: flex;
    align-items: center;
    gap: 11px;
    flex: 1;
    min-width: 0;
  }
  html.tab-ui .m-head-logo {
    width: 40px;
    height: 40px;
    border-radius: 13px;
    background: #1c1410;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 22px;
    box-shadow: 0 6px 14px -8px rgba(28,20,16,.7);
  }
  html.tab-ui .m-head-text { min-width: 0; }
  html.tab-ui .m-head-sub {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
  }
  html.tab-ui .m-head-title {
    font-family: var(--font-serif);
    font-size: 25px;
    font-weight: 700;
    line-height: 1.05;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ---- Floating tab bar ---- */
  html.tab-ui .m-tabbar {
    display: flex;
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    max-width: 440px;
    margin: 0 auto;
    z-index: 250;
    align-items: center;
    justify-content: space-between;
    padding: 6px;
    background: rgba(40,29,21,.94);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border: 1px solid #3a2c20;
    border-radius: 999px;
    box-shadow: 0 14px 32px -6px rgba(28,20,16,.55);
  }
  html.tab-ui.m-locked .m-tabbar { z-index: 390; }

  html.tab-ui .m-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 48px;
    min-width: 48px;
    padding: 0 13px;
    border: none;
    border-radius: 999px;
    background: none;
    color: #a8957a;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: background .2s, color .2s, transform .15s;
  }
  html.tab-ui .m-tab hi-icon { font-size: 19px; }
  html.tab-ui .m-tab span { display: none; }
  html.tab-ui .m-tab.active { background: var(--primary); color: #1c1410; }
  html.tab-ui .m-tab.active span { display: inline; }
  html.tab-ui .m-tab:hover { text-decoration: none; }
  html.tab-ui .m-tab:active { transform: scale(.94); }

  /* Action button: a lone dark button floating above the bar's right end */
  html.tab-ui .m-fab {
    display: flex;
    position: fixed;
    right: 20px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    z-index: 250;
    width: 58px;
    height: 58px;
    border: 1px solid #5a4430;
    border-radius: 20px;
    padding: 0;
    background: linear-gradient(160deg, #3a2a1e, #1c1410);
    color: #e2c48e;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 14px 28px -8px rgba(28,20,16,.6), inset 0 1px 0 rgba(255,255,255,.08);
    transition: transform .15s;
  }
  html.tab-ui.m-locked .m-fab { z-index: 390; }
  html.tab-ui.m-locked .m-fab:not(.open) { opacity: 0; pointer-events: none; }
  html.tab-ui .m-fab span { display: flex; transition: transform .25s ease; }
  html.tab-ui .m-fab:active { transform: scale(.94); }
  html.tab-ui .m-fab.open span { transform: rotate(45deg); }

  /* Moving between pages: the tab bar and + button stay put while the page
     content fades across, like switching tabs in a native app */
  html.tab-ui .m-tabbar { view-transition-name: m-tabbar; }
  html.tab-ui .m-fab { view-transition-name: m-fab; }

  /* ---- Sheets ---- */
  html.tab-ui .m-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 380;
    background: rgba(28,20,16,.45);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }
  html.tab-ui .m-overlay.open { opacity: 1; pointer-events: auto; }

  html.tab-ui .m-sheet {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 385;
    max-height: 88vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    border-radius: 28px 28px 0 0;
    padding: 10px 18px calc(104px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 40px rgba(0,0,0,.18);
    transform: translateY(105%);
    transition: transform .32s cubic-bezier(.2,.8,.2,1);
  }
  html.tab-ui .m-sheet.open { transform: none; }
  /* Leave room for the floating button, which turns into the close button */
  html.tab-ui .m-action-sheet { padding-bottom: calc(166px + env(safe-area-inset-bottom)); }

  html.tab-ui .m-sheet-handle {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 2px auto 16px;
  }
  html.tab-ui .m-sheet-title {
    font-family: var(--font-serif);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.05;
    color: var(--text-primary);
  }
  html.tab-ui .m-sheet-sub {
    font-size: 13px;
    color: var(--text-muted);
    margin: 6px 0 18px;
  }
  html.tab-ui .m-sheet-label {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 18px 2px 8px;
  }

  html.tab-ui .m-tiles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  html.tab-ui .m-tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 108px;
    padding: 14px 12px;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.2;
    text-align: left;
    cursor: pointer;
    transition: transform .15s;
  }
  html.tab-ui .m-tile:active { transform: scale(.96); }
  html.tab-ui .m-tile-ic {
    width: 40px;
    height: 40px;
    border-radius: 13px;
    background: var(--primary-bg);
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
  }
  html.tab-ui .m-tile.main {
    background: linear-gradient(160deg, #2e2116, #1c1410);
    border-color: #1c1410;
    color: #f3e9d8;
  }
  html.tab-ui .m-tile.main .m-tile-ic {
    background: linear-gradient(145deg, #d9bc84, #a07840);
    color: #fff;
  }

  html.tab-ui .m-more-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 2px 4px;
  }
  html.tab-ui .m-more-user .mbn-avatar { width: 48px; height: 48px; font-size: 1rem; }
  html.tab-ui .m-more-user .name { font-weight: 800; font-size: 16px; }
  html.tab-ui .m-more-user .email { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  html.tab-ui .m-more-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  html.tab-ui .m-more-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 6px 12px;
    border-radius: 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 12.5px;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    transition: transform .15s;
  }
  html.tab-ui .m-more-tile:hover { text-decoration: none; }
  html.tab-ui .m-more-tile:active { transform: scale(.96); }
  html.tab-ui .m-more-ic {
    width: 40px;
    height: 40px;
    border-radius: 13px;
    background: var(--bg-muted);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
  }
  html.tab-ui .m-more-tile.active { border-color: var(--primary); }
  html.tab-ui .m-more-tile.active .m-more-ic { background: var(--primary); color: #1c1410; }

  html.tab-ui .m-signout {
    margin-top: 18px;
    width: 100%;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 16px;
    border: 1px solid var(--error-border);
    background: var(--error-bg);
    color: var(--error);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
  }
  html.tab-ui .m-signout hi-icon { font-size: 18px; }
}

/* ---- 2. The dark bar at the bottom, like the phone (either way round) ---- */
html.tab-ui .m-tabbar {
  left: 0;
  right: 0;
  width: fit-content;
  /* never reaches the + button in the corner */
  max-width: calc(100vw - 200px);
  margin: 0 auto;
  bottom: calc(20px + env(safe-area-inset-bottom));
  justify-content: center;
  gap: 6px;
  padding: 7px;
}
html.tab-ui .m-tab {
  height: 54px;
  min-width: 54px;
  padding: 0 16px;
  font-size: 14px;
}
html.tab-ui .m-tab hi-icon { font-size: 21px; }

/* + button in the bottom-right corner, level with the bar */
html.tab-ui .m-fab {
  right: calc(24px + env(safe-area-inset-right));
  bottom: calc(25px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
}

/* The page scrolls inside .main-content, not the browser window. When the window
   scrolls, Chrome on iPad shrinks its address bar without telling the page, and the
   bar was left floating above an empty gap at the bottom of the screen. */
html.tab-ui, html.tab-ui body { height: 100%; overflow: hidden; }
html.tab-ui .app-layout { height: 100%; min-height: 0; }
html.tab-ui .main-content {
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
/* Header, banner and page keep their full height inside the scroll area */
html.tab-ui .main-content > * { flex-shrink: 0; }
html.tab-ui.m-locked .main-content { overflow-y: hidden; }

/* Room at the end of the page so the last card scrolls clear of the bar. A real box,
   because Safari can leave out a scroll area's bottom padding. */
html.tab-ui body.has-m-tabbar .main-content,
html.tab-ui body.has-m-fab .main-content { padding-bottom: 0; }
html.tab-ui body.has-m-tabbar .main-content::after,
html.tab-ui body.has-m-fab .main-content::after {
  content: '';
  display: block;
  flex: none;
  height: calc(118px + env(safe-area-inset-bottom));
}

/* More: a card floating just above the bar */
html.tab-ui .m-sheet {
  left: 0;
  right: 0;
  margin: 0 auto;
  width: min(560px, calc(100vw - 32px));
  bottom: calc(102px + env(safe-area-inset-bottom));
  max-height: calc(100vh - 140px);
  border-radius: 28px;
  padding: 10px 22px 22px;
  box-shadow: 0 24px 60px -12px rgba(28,20,16,.35);
  transform: translateY(calc(100% + 220px));
}
html.tab-ui .m-sheet.open { transform: none; }
/* What happened?: a card rising above the + button */
html.tab-ui .m-action-sheet {
  left: auto;
  right: calc(24px + env(safe-area-inset-right));
  margin: 0;
  width: min(460px, calc(100vw - 48px));
  padding-bottom: 22px;
  transform-origin: bottom right;
}
html.tab-ui .m-more-grid { grid-template-columns: repeat(4, 1fr); }

/* Forms stop just above the bar, so the bar never goes away */
html.tab-ui body.has-m-tabbar .m-tabbar { z-index: 305; }
html.tab-ui.m-locked body.has-m-tabbar .m-tabbar { z-index: 390; }
html.tab-ui body.has-m-tabbar .drawer { bottom: calc(102px + env(safe-area-inset-bottom)); }
@media (max-width: 768px) {
  html.tab-ui body.has-m-tabbar .drawer {
    max-height: calc(100% - 126px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 26px;
    box-shadow: 0 24px 60px -12px rgba(28,20,16,.35);
  }
  html.tab-ui body.has-m-tabbar .drawer:not(.open) { transform: translateY(calc(100% + 160px)); }
}

/* Extra tabs: Tasks except on 7" upright; Providers and Programme on wide
   tablets turned sideways. Hidden ones stay in More. */
html.tab-ui .m-tab[data-tab="vendors"],
html.tab-ui .m-tab[data-tab="programme"] { display: none; }
@media (orientation: portrait) and (max-width: 699px) {
  html.tab-ui .m-tab[data-tab="tasks"] { display: none; }
}
@media (orientation: landscape), (min-width: 700px) {
  html.tab-ui .m-more-tile[href="/app/tasks"] { display: none; }
}
@media (orientation: landscape) and (min-width: 1180px) {
  html.tab-ui .m-tab[data-tab="vendors"],
  html.tab-ui .m-tab[data-tab="programme"] { display: flex; }
  html.tab-ui .m-more-tile[href="/app/vendors"],
  html.tab-ui .m-more-tile[href="/app/programme"] { display: none; }
}

/* Small tablets upright (7", iPad mini): the phone layout, with more room */
@media (orientation: portrait) and (max-width: 768px) {
  html.tab-ui body.has-m-tabbar .app-header { padding: calc(16px + env(safe-area-inset-top)) 24px 14px; }
  html.tab-ui .m-head-title { font-size: 28px; }
  html.tab-ui .page-body { padding: 18px 24px 8px !important; }
  html.tab-ui .tabs, html.tab-ui .tab-bar { margin: 0 -24px 16px; padding: 2px 24px; }

  /* Forms slide up as a centred sheet rather than edge to edge */
  html.tab-ui .drawer,
  html.tab-ui .modal-overlay.show .modal {
    max-width: 640px !important;
    margin: 0 auto;
  }
  html.tab-ui .drawer { left: 0; right: 0; }
}

/* Bigger screens (iPad and up upright, every tablet sideways): phone-style header,
   desktop-size content */
@media (min-width: 769px) {
  html.tab-ui body.has-m-tabbar .app-header {
    height: auto;
    min-height: 0;
    padding: calc(18px + env(safe-area-inset-top)) 28px 16px;
    gap: 12px;
    justify-content: flex-start;
    background: rgba(249,247,244,.9);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
    border-bottom: 1px solid rgba(229,221,212,.6);
  }
  html.tab-ui .m-head-logo { width: 44px; height: 44px; font-size: 24px; border-radius: 14px; }
  html.tab-ui .m-head-sub { font-size: 13px; }
  html.tab-ui .m-head-title { font-size: 30px; }
  html.tab-ui .page-body { padding: 22px 28px !important; }
}

/* Wide tables would need sideways scrolling: show them as cards, as on the phone
   (big tablets upright, and 7" tablets sideways) */
@media (orientation: portrait) and (min-width: 769px), (orientation: landscape) and (max-width: 1100px) {
  html.tab-ui .card:has(> .table-wrapper),
  html.tab-ui .card:has(> .card-body > .table-wrapper) {
    background: transparent;
    border: none;
    box-shadow: none;
    border-radius: 0;
  }
  html.tab-ui .card:has(> .table-wrapper) > .card-header,
  html.tab-ui .card:has(> .table-wrapper) > .card-body {
    padding-left: 0;
    padding-right: 0;
    border-bottom: none;
  }
  html.tab-ui .card:has(> .table-wrapper) > .table-meta { padding: 0 2px !important; }

  html.tab-ui .table-wrapper { overflow: visible; border: none; }
  html.tab-ui table.m-cards,
  html.tab-ui table.m-cards tbody,
  html.tab-ui table.m-cards tfoot { display: block; width: 100%; }
  html.tab-ui table.m-cards thead { display: none; }
  html.tab-ui table.m-cards tr {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 10px;
    margin: 0 0 10px;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-xs);
  }
  html.tab-ui table.m-cards tr:hover td { background: transparent; }
  html.tab-ui table.m-cards td {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    padding: 6px 0 !important;
    border: none !important;
    font-size: 14px;
    text-align: right !important;
    white-space: normal;
    width: auto !important;
  }
  html.tab-ui table.m-cards td::before {
    content: attr(data-label);
    flex-shrink: 0;
    max-width: 45%;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
  }
  html.tab-ui table.m-cards td[data-label=""]::before,
  html.tab-ui table.m-cards td.m-title::before,
  html.tab-ui table.m-cards td.m-act::before,
  html.tab-ui table.m-cards td.m-full::before { content: none; }
  html.tab-ui table.m-cards td.m-title {
    display: block;
    padding: 4px 0 10px !important;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border) !important;
    font-size: 15.5px;
    font-weight: 700;
    text-align: left !important;
  }
  html.tab-ui table.m-cards td.m-lead {
    grid-column: 1;
    align-self: start;
    padding: 4px 0 0 !important;
  }
  html.tab-ui table.m-cards td.m-lead + td.m-title { grid-column: 2; }
  html.tab-ui table.m-cards td.m-act {
    justify-content: flex-end;
    padding-top: 8px !important;
    margin-top: 4px;
    border-top: 1px solid var(--border) !important;
  }
  html.tab-ui table.m-cards td.m-act:empty { display: none; }
  html.tab-ui table.m-cards td.m-full { display: block; text-align: center !important; }
  html.tab-ui table.m-cards tr:has(> td.m-full:only-child) {
    display: block;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
  }
  html.tab-ui table.m-cards tfoot tr { background: var(--bg-muted); }
  html.tab-ui .table-actions .btn-icon { width: 38px; height: 38px; border-radius: 12px; background: var(--bg-muted); }
}
@media (orientation: portrait) and (min-width: 640px), (orientation: landscape) and (max-width: 1100px) {
  /* Pledge, budget and task lists: two cards side by side */
  html.tab-ui table.m-cards tbody {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
  }
  html.tab-ui table.m-cards tbody tr { margin: 0; }
  html.tab-ui table.m-cards tbody tr:has(> td.m-full:only-child) { grid-column: 1 / -1; }
}

