/* Device layouts. Loaded last, so it overrides the base styles.
   Phone < 600px · Tablet 600–1023px · Desktop 1024–1439px · Large ≥ 1440px. The page uses the full device width. */

.shell { max-width: none; }
.chat-room { max-width: none; border-left: 0; border-right: 0; }
.room-messages .bubble { max-width: min(720px, 80%); }
.tab-ic { margin-right: 6px; }
.home-side .lunar-banner, .home-side .chart-strip { margin: 0; width: 100%; }
.home-side { display: flex; flex-direction: column; gap: 12px; }
.home-side .luck-card { margin: 0; }
.home-below { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 20px; }
.home-below > *, .home-side > * { min-width: 0; }
/* Cards grow to fill the row when they all fit; otherwise the row scrolls */
.astro-list .astro-card { flex-grow: 1; max-width: 420px; }
.astro-nav.no-scroll { visibility: hidden; }
.home-below .kundali-card { margin: 0; }
.kundali-card { container-type: inline-size; }

/* Kundali card: chart on the left, reading on the right, whenever the card itself is wide enough */
.k-grid { display: flex; flex-direction: column; }
.k-side { display: contents; }
.k-grid .k-head { order: -1; }
@container (min-width: 680px) {
  .k-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 28px; align-items: center; }
  .k-side { display: block; }
  .k-grid .k-stage { width: 100%; max-width: 620px; margin: 0; }
  .k-grid .k-info { margin: 16px 0 0; max-width: none; }
  .k-grid .k-legend { justify-content: flex-start; margin: 12px 0 0; max-width: none; }
  .k-grid .k-note { text-align: left; }
  .k-grid .k-cta { justify-content: flex-start; }
}

/* ------------------------------------------------------------------ Other pages: shared */
#historyBody > p.center, #paymentsBody > p.center { grid-column: 1 / -1; }
.history-actions-bar, .pay-summary { grid-column: 1 / -1; }

/* ------------------------------------------------------------------ Phone */
@media (max-width: 599px) {
  /* Dialogs and sheets rise from the bottom edge, like native app sheets */
  .overlay:not(.sheet-overlay) { place-items: end center; padding: 0; }
  .overlay:not(.sheet-overlay) .dialog {
    max-width: none; max-height: 92dvh; border-radius: 26px 26px 0 0; border-bottom: 0;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
    animation: slideUp 280ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  .overlay:not(.sheet-overlay) .dialog::before {
    content: ''; display: block; width: 40px; height: 4px; margin: -8px auto 14px; border-radius: 10px;
    background: rgba(127, 137, 165, 0.35);
  }
  .sheet { padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); }
  .room-head { padding: 8px 10px; }
  .room-head .btn { padding: 0 11px; }
  .room-form { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .rashi-picker { gap: 5px; }

  .app-header { padding: 10px 14px; gap: 10px; }
  .app-header .pill-tag { display: none; }
  .brand h1 { font-size: 17px; }

  /* Bottom tab bar, like a native app */
  .tabs-wrap {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-bottom: 0; border-top: 1px solid var(--gold-border);
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.08);
  }
  .tabs { max-width: none; background: none; border: 0; box-shadow: none; padding: 0; border-radius: 0; gap: 4px; }
  .tab {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 4px 2px; border-radius: 14px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.2px;
  }
  .tab-ic {
    margin: 0; display: grid; place-items: center; width: 52px; height: 28px; border-radius: 16px; font-size: 16px;
    transition: background 200ms ease, transform 200ms ease;
  }
  .tab.active { background: none; box-shadow: none; color: var(--gold-light); font-weight: 700; }
  [data-theme="dark"] .tab.active { color: var(--gold-light); }
  .tab.active .tab-ic { background: var(--gold-gradient); color: #fff; transform: translateY(-1px); box-shadow: 0 3px 10px rgba(217, 119, 6, 0.35); }
  [data-theme="dark"] .tab.active .tab-ic { color: var(--background); }
  .tab-panel.scroll.active { padding: 14px 12px calc(88px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }

  .hero { border-radius: 22px; }
  .astro-list { margin: 0 -12px; padding: 4px 12px 14px; scroll-padding-inline: 12px; }
  .astro-list .astro-card { flex-basis: min(78vw, 300px); }
  .kundali-card { padding: 16px 12px 14px; border-radius: 22px; }
  .k-head h2 { font-size: 20px; }
  .k-seg { width: 100%; }
  .k-seg button { flex: 1; }
}

/* ------------------------------------------------------------------ Tablet and up */
@media (min-width: 600px) {
  .tab-panel.scroll.active { padding: 22px 24px 36px; }
  .tabs { max-width: 640px; }
  .home-side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .home-side .luck-card { grid-column: 1 / -1; }
  .codex-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .daily { max-width: 820px; }
  .astro-list .astro-card { flex-basis: 224px; }

  /* Sheets (account, sign details, Kundali) become centred pop-ups instead of full-width bottom panels */
  .sheet-overlay { place-items: center; padding: 24px; }
  .sheet {
    max-width: 680px; max-height: 86dvh; border-radius: 28px; border-bottom: 1px solid rgba(247, 182, 77, 0.3);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); animation: dialogScale 260ms cubic-bezier(0.16, 1, 0.3, 1) both;
  }
  .sheet .handle { display: none; }
  .dialog { max-width: 520px; padding: 28px; }
  .paywall { max-width: 640px; }
  .plan-list { display: grid; grid-template-columns: 1fr 1fr; }

  /* History and payments: a grid of cards */
  #historyBody:not([hidden]), #paymentsBody:not([hidden]) {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; align-items: start;
  }
  #historyBody .history-item-wrap, #paymentsBody .history-card { margin: 0; }
  .history-card { transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease; }
  .history-card:hover { transform: translateY(-2px); box-shadow: var(--card-shadow); }
  .pay-summary { margin-bottom: 4px; }
}

/* ------------------------------------------------------------------ Desktop */
@media (min-width: 1024px) {
  /* One top bar: brand on the left, tabs in the middle, actions on the right */
  .app-header { padding: 14px 32px; min-height: 72px; }
  .tabs-wrap {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%); z-index: 5;
    height: 72px; display: flex; align-items: center; padding: 0; background: none; border: 0;
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tabs { max-width: none; width: auto; }
  .tab { padding: 9px 18px; font-size: 13px; }

  .tab-panel.scroll.active { padding: 28px 32px 44px; }
  .home-top { grid-template-columns: clamp(320px, 28vw, 440px) minmax(0, 1fr); gap: 24px; }
  .home-top .hero h2 { font-size: 34px; }
  .home-list .list-head h2 { font-size: 24px; }
  .astro-list .astro-card { flex-basis: 236px; }

  .home-below { grid-template-columns: minmax(0, 1.75fr) minmax(300px, 1fr); gap: 24px; align-items: start; margin-top: 28px; }
  .home-side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; }

  /* Rashifal: sign picker pinned on the left, the reading fills the right */
  .daily {
    max-width: none; display: grid; text-align: left; align-items: start; column-gap: 32px;
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); grid-template-rows: auto auto auto 1fr;
  }
  .daily > .tag, .daily > h2, .daily > p, .daily > .rashi-picker { grid-column: 1; }
  .daily > .tag { justify-self: start; }
  .daily > .rashi-picker {
    grid-template-columns: repeat(3, 1fr); gap: 8px; position: sticky; top: 0; align-self: start; margin-top: 8px;
  }
  .daily > .rashifal { grid-column: 2; grid-row: 1 / -1; max-width: none; }
  .rf-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

  /* Chat room: full-width room, conversation in a comfortable reading column */
  .room-messages { padding-inline: max(12px, calc((100% - 1040px) / 2)); }
  .room-banner { margin-inline: max(12px, calc((100% - 1040px) / 2)); }
  .room-form { padding-inline: max(12px, calc((100% - 1040px) / 2)); }
  .room-head { padding-inline: 24px; }
  .room-messages .bubble { max-width: min(680px, 72%); }

  #historyBody:not([hidden]), #paymentsBody:not([hidden]) { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }
  .plan-list { grid-template-columns: 1fr 1fr; }
  .codex-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px 16px; }
  .sheet { max-width: 960px; }
}

/* ------------------------------------------------------------------ Large screens */
@media (min-width: 1440px) {
  .app-header { padding-inline: 48px; }
  .tab-panel.scroll.active { padding: 32px 48px 52px; }
  .home-top { grid-template-columns: clamp(380px, 26vw, 480px) minmax(0, 1fr); gap: 28px; }
  .astro-list .astro-card { flex-basis: 250px; }
  .home-below { grid-template-columns: minmax(0, 2fr) minmax(340px, 1fr); gap: 28px; }
  .daily { grid-template-columns: minmax(340px, 420px) minmax(0, 1fr); column-gap: 40px; }
}
