/* ==========================================================================
   Responsive behaviour (spec §34, §48)
   --------------------------------------------------------------------------
   Tested widths: 320, 375, 390, 430, 768, 1024, 1280, 1440, 1920.

   Breakpoints are max-width because the desktop layout is the base and each
   step narrows it — the reverse would mean re-stating the desktop grid.
   ========================================================================== */

/* ---- Large desktop: widen the reading column -------------------------- */
@media (min-width: 1600px) {
  .content {
    padding-inline: var(--space-10);
  }
}

/* ---- Small desktop / large tablet: collapse the sidebar to icons ------- */
@media (max-width: 1180px) {
  .app,
  .app[data-sidebar='expanded'] {
    grid-template-columns: var(--sidebar-collapsed) 1fr;
  }

  .app .brand-name,
  .app .nav-item span,
  .app .nav-section-label {
    display: none;
  }

  .app .nav-item {
    justify-content: center;
  }

  .sidebar-brand {
    justify-content: center;
    padding-inline: var(--space-2);
  }

  .brand-logo-img {
    max-width: 40px;
    max-height: 40px;
  }
}

/* ---- Tablet and below: sidebar becomes a drawer ------------------------ */
@media (max-width: 900px) {
  .app,
  .app[data-sidebar='collapsed'],
  .app[data-sidebar='expanded'] {
    grid-template-columns: 1fr;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: var(--z-drawer);
    inline-size: min(300px, 85vw);
    /* Off-canvas by default. -101% avoids a hairline of the panel showing
       through at some zoom levels. */
    transform: translateX(-101%);
    box-shadow: var(--shadow-lg);
    transition: transform var(--duration-base) var(--ease-out);
  }

  /* In RTL the drawer lives on the right, so it hides to the right. */
  [dir='rtl'] .sidebar {
    transform: translateX(101%);
  }

  .app[data-drawer='open'] .sidebar,
  [dir='rtl'] .app[data-drawer='open'] .sidebar {
    transform: translateX(0);
  }

  /* Inside the drawer the labels come back — there is room for them. */
  .app .brand-name,
  .app .nav-item span,
  .app .nav-section-label {
    display: initial;
  }

  .app .nav-item {
    justify-content: flex-start;
    /* Comfortable touch targets (spec §48). */
    min-block-size: 46px;
  }

  .sidebar-brand {
    justify-content: flex-start;
    padding-inline: var(--space-5);
  }

  .content {
    padding: var(--space-6) var(--space-5);
  }

  .header {
    padding-inline: var(--space-4);
  }
}

/* ---- Mobile ------------------------------------------------------------ */
@media (max-width: 640px) {
  :root {
    /* Slightly tighter rhythm so cards do not feel cramped by padding. */
    --space-6: 1.15rem;
    --space-8: 1.5rem;
  }

  .content {
    padding: var(--space-5) var(--space-4);
  }

  .page-title {
    font-size: var(--text-2xl);
  }

  .card,
  .card-hero {
    padding: var(--space-5);
    border-radius: var(--radius-lg);
  }

  .grid-auto {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: var(--text-2xl);
  }

  /* Buttons in a row stack and fill the width, so nothing is a tiny target. */
  .actions-stack {
    flex-direction: column;
    align-items: stretch;
  }

  .actions-stack .btn {
    inline-size: 100%;
  }

  .auth-card {
    padding: var(--space-6);
    border-radius: var(--radius-xl);
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-5);
  }

  .modal-footer {
    flex-direction: column-reverse;
  }

  .modal-footer .btn {
    inline-size: 100%;
  }

  .toast-region {
    inset-inline: var(--space-3);
    inset-block-end: var(--space-3);
    max-inline-size: none;
  }

  /* ---- Tables become cards (spec §48) --------------------------------- */
  .table-responsive .table thead {
    display: none;
  }

  .table-responsive .table,
  .table-responsive .table tbody,
  .table-responsive .table tr,
  .table-responsive .table td {
    display: block;
    inline-size: 100%;
  }

  .table-responsive .table tr {
    padding: var(--space-4);
    border-block-start: 1px solid var(--border);
  }

  .table-responsive .table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-2) 0;
    border: none;
    text-align: end;
  }

  /* The header text is carried in a data attribute and shown as a label. */
  .table-responsive .table td::before {
    content: attr(data-label);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: start;
  }

  .table-wrap {
    border: none;
    border-radius: 0;
  }

  .notification-panel {
    position: fixed;
    inset-block-start: var(--header-height);
    inset-inline: var(--space-3);
    inline-size: auto;
  }
  /* ---- Dashboard Mobile Responsive ----------------------------------- */
  .dash-hero-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .dash-hero-body {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .dash-info-box {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .dash-info-divider {
    display: none;
  }

  .dash-actions-grid {
    grid-template-columns: 1fr;
  }

  .dash-service-card {
    grid-template-columns: 1fr 1fr;
  }

  /* ---- Settings Mobile Responsive ------------------------------------- */
  .settings-profile-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-4);
  }

  .settings-profile-chips {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .settings-row-3 {
    grid-template-columns: 1fr !important;
  }

  .settings-row-2 {
    grid-template-columns: 1fr !important;
  }

  .settings-options-grid {
    grid-template-columns: 1fr;
  }

  .settings-security-bottom-row {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  /* ---- Subscription & Activation Mobile Responsive -------------------- */
  .sub-hero-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .sub-credentials-grid {
    grid-template-columns: 1fr;
  }

  .sub-plans-grid {
    grid-template-columns: 1fr;
  }

  .act-card-split {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
  }

  .act-card-btn-col form {
    width: 100%;
  }

  .act-card-btn-col .act-btn-sm {
    width: 100%;
    justify-content: center;
  }
}

/* ---- Very small phones (360px) ---------------------------------------- */
@media (max-width: 360px) {
  .dash-service-card {
    grid-template-columns: 1fr;
  }

  .content {
    padding: var(--space-4) var(--space-3);
  }

  .card,
  .card-hero {
    padding: var(--space-4);
  }

  .page-title {
    font-size: var(--text-xl);
  }

  /* The verification code is 20 digits; it must stay on one line even here. */
  .code-display {
    font-size: var(--text-base);
    letter-spacing: 0.05em;
  }
}

/* ---- Print ------------------------------------------------------------- */
@media print {
  .sidebar,
  .header,
  .toast-region,
  .btn {
    display: none !important;
  }

  .app {
    grid-template-columns: 1fr;
  }

  body {
    background: #fff;
    color: #000;
  }
}
