/**
 * SSG Domain Checker — responsive layer
 * Breakpoints:
 *   Desktop  min-width: 1025px
 *   Tablet   769px – 1024px
 *   Mobile   max-width: 768px
 *   Small    max-width: 480px
 */

/* -------------------------------------------------------------------------- */
/* Base safety                                                                */
/* -------------------------------------------------------------------------- */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-size: 15px;
}

.admin-content,
.container {
  max-width: 1400px;
}

/* -------------------------------------------------------------------------- */
/* Drawer overlay + close                                                     */
/* -------------------------------------------------------------------------- */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 35;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.sidebar-overlay.is-visible,
.sidebar-overlay.is-visible[hidden] {
  display: block !important;
}

.drawer-brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.drawer-close-btn {
  display: none;
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
  min-width: 40px;
  min-height: 40px;
  padding: 4px;
}

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

.user-drawer {
  display: none;
}

/* -------------------------------------------------------------------------- */
/* Desktop (≥1025px)                                                          */
/* -------------------------------------------------------------------------- */

@media (min-width: 1025px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .monitoring-meta {
    grid-template-columns: repeat(4, 1fr);
  }

  .admin-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .admin-stats-grid.compact {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

  .health-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .admin-sidebar {
    position: sticky;
    transform: none !important;
  }

  .admin-menu-btn,
  .drawer-close-btn,
  .mobile-menu-btn,
  .user-drawer,
  .sidebar-overlay {
    display: none !important;
  }

  .modal-card {
    width: min(100%, 520px);
  }

  .modal-card.modal-wide {
    width: min(100%, 640px);
  }
}

/* -------------------------------------------------------------------------- */
/* Tablet (769px – 1024px)                                                    */
/* -------------------------------------------------------------------------- */

@media (max-width: 1024px) and (min-width: 769px) {
  .stats-grid,
  .monitoring-meta,
  .admin-stats-grid,
  .health-cards,
  .health-summary-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-content {
    padding: 18px;
  }

  .container {
    margin-top: 18px;
    padding: 0 16px 40px;
  }

  /* Sidebar → drawer on tablet */
  .admin-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 86vw);
    height: 100%;
    max-height: 100dvh;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow);
    z-index: 40;
  }

  .admin-sidebar.open {
    transform: translateX(0);
  }

  .admin-menu-btn,
  .drawer-close-btn {
    display: inline-flex;
  }

  .admin-form-grid {
    grid-template-columns: 1fr;
  }

  /* Tables: horizontal scroll on tablet */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 680px;
  }

  .modal-card {
    width: min(100%, 520px);
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* -------------------------------------------------------------------------- */
/* Shared drawer behavior ≤1024px                                             */
/* -------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  body.drawer-open {
    overflow: hidden;
  }

  .admin-layout {
    display: block;
  }

  .admin-main {
    width: 100%;
  }
}

/* -------------------------------------------------------------------------- */
/* Mobile (≤768px)                                                            */
/* -------------------------------------------------------------------------- */

@media (max-width: 768px) {
  body {
    font-size: 15px;
  }

  .primary-btn,
  .secondary-btn,
  .danger-btn,
  .action-btn,
  .icon-btn,
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  select,
  textarea {
    min-height: 44px;
  }

  .icon-btn {
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-height: 0;
    width: 18px;
    height: 18px;
  }

  h1,
  .admin-page-title {
    font-size: clamp(18px, 4.5vw, 22px);
  }

  h2 {
    font-size: clamp(16px, 4vw, 20px);
  }

  .panel {
    padding: 14px;
    margin-bottom: 14px;
  }

  .admin-content {
    padding: 12px 14px 28px;
  }

  .admin-topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .container {
    margin-top: 12px;
    padding: 0 12px 28px;
  }

  /* ---- Admin drawer ---- */
  .admin-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: min(300px, 88vw);
    height: 100%;
    max-height: 100dvh;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    box-shadow: var(--shadow);
    z-index: 40;
    padding: 16px 12px;
  }

  .admin-sidebar.open {
    transform: translateX(0);
  }

  .admin-menu-btn,
  .drawer-close-btn {
    display: inline-flex;
  }

  .admin-nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
  }

  .admin-sidebar-foot .secondary-btn,
  .admin-sidebar-foot .block-btn {
    min-height: 44px;
  }

  /* ---- User dashboard topbar + drawer ---- */
  .dashboard-page .topbar {
    padding: 10px 12px;
    gap: 10px;
    min-height: 56px;
  }

  .dashboard-page .mobile-menu-btn {
    display: inline-flex;
    order: -1;
  }

  .dashboard-page .topbar .brand {
    flex: 1;
    min-width: 0;
  }

  .dashboard-page .app-name {
    font-size: clamp(13px, 3.5vw, 15px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .dashboard-page .top-actions .status-pill,
  .dashboard-page .top-actions .secondary-btn,
  .dashboard-page .top-actions .inline-form {
    display: none;
  }

  .user-drawer {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    width: min(300px, 88vw);
    height: 100%;
    max-height: 100dvh;
    background: var(--card);
    border-right: 1px solid var(--border);
    z-index: 40;
    padding: 16px 12px;
    transform: translateX(-100%);
    transition: transform 200ms ease;
    overflow-y: auto;
    box-shadow: var(--shadow);
  }

  .user-drawer.open {
    transform: translateX(0);
  }

  .user-drawer-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    margin-top: 8px;
  }

  .user-drawer-nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
  }

  .user-drawer-nav a:hover,
  .user-drawer-nav a:focus-visible {
    background: rgba(75, 0, 168, 0.08);
    outline: none;
  }

  .user-drawer-foot {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    margin-top: 12px;
  }

  /* ---- Stats ---- */
  .stats-grid,
  .monitoring-meta,
  .admin-stats-grid,
  .health-cards,
  .health-summary-list,
  .info-grid,
  .account-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-card {
    padding: 12px 14px;
  }

  .stat-card strong {
    font-size: 22px;
    margin-top: 6px;
  }

  /* ---- Toolbar / actions ---- */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
  }

  .toolbar-right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .toolbar-right #settingsBtn {
    grid-column: 1 / -1;
  }

  .search-field,
  .search-field input,
  #statusFilter {
    width: 100%;
    min-width: 0;
  }

  .form-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .form-actions .primary-btn,
  .form-actions .secondary-btn {
    width: 100%;
    margin-top: 0;
  }

  #domainInput {
    min-height: 140px;
  }

  .admin-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-filters input,
  .admin-filters select {
    max-width: none;
    width: 100%;
  }

  .admin-filters .primary-btn {
    width: 100%;
  }

  .admin-form-grid {
    grid-template-columns: 1fr;
  }

  .account-actions .primary-btn,
  .account-actions .secondary-btn,
  .account-form-actions .primary-btn,
  .account-form-actions .secondary-btn {
    width: 100%;
  }

  .health-toolbar {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .health-toolbar .primary-btn {
    width: 100%;
  }

  .health-detail-grid {
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
  }

  /* ---- Bulk bar (sticky) ---- */
  .bulk-bar:not([hidden]) {
    position: sticky;
    bottom: 10px;
    z-index: 25;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    background: var(--card);
    border: 1px solid rgba(75, 0, 168, 0.35);
    box-shadow: var(--shadow);
  }

  .bulk-actions {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }

  .bulk-actions .secondary-btn,
  .bulk-actions .danger-btn {
    width: 100%;
  }

  /* ---- Table → card mode ---- */
  .table-wrap {
    overflow-x: visible;
  }

  .table-wrap table {
    min-width: 0;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
  }

  .table-wrap tbody tr:last-child {
    margin-bottom: 0;
  }

  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border: 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    text-align: right;
  }

  .table-wrap tbody td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .table-wrap tbody td:first-child {
    padding-top: 0;
  }

  .table-wrap tbody td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: left;
    flex: 0 1 42%;
  }

  .table-wrap tbody td.col-check {
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
  }

  .table-wrap tbody td.col-check::before {
    content: none;
  }

  .table-wrap tbody td.col-check .row-check {
    margin-right: 4px;
  }

  /* Domain title cell (monitoring) */
  .table-wrap tbody td.cell-domain {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    text-align: left;
  }

  .table-wrap tbody td.cell-domain::before {
    display: none;
  }

  .table-wrap tbody td.cell-domain .link-btn strong {
    font-size: 16px;
    word-break: break-word;
  }

  .table-wrap tbody td.actions-cell {
    flex-wrap: wrap;
    justify-content: stretch;
    gap: 8px;
  }

  .table-wrap tbody td.actions-cell::before {
    flex: 0 0 100%;
    margin-bottom: 2px;
  }

  .table-wrap tbody td.actions-cell .action-btn,
  .table-wrap tbody td.actions-cell .inline-form {
    flex: 1 1 calc(50% - 4px);
  }

  .table-wrap tbody td.actions-cell .inline-form {
    display: flex;
  }

  .table-wrap tbody td.actions-cell .action-btn {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .table-wrap tbody td[colspan],
  .table-wrap tbody td.empty {
    display: block;
    text-align: center;
    border: 0;
  }

  .table-wrap tbody td[colspan]::before,
  .table-wrap tbody td.empty::before {
    content: none !important;
  }

  /* ---- Modals ---- */
  .modal-backdrop {
    padding: 12px;
    align-items: flex-end;
    place-items: stretch end;
  }

  .modal-card,
  .modal-card.modal-wide {
    width: calc(100vw - 24px);
    max-width: none;
    max-height: 90vh;
    overflow-y: auto;
    padding: 16px;
    margin: auto 0 0;
    border-radius: 14px 14px 10px 10px;
  }

  .modal-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .modal-actions .secondary-btn,
  .modal-actions .danger-btn,
  .modal-actions .primary-btn {
    width: 100%;
  }

  /* ---- Toast ---- */
  .toast-container {
    top: 12px;
    right: 12px;
    left: 12px;
    bottom: auto;
    width: auto;
    max-width: none;
    align-items: center;
  }

  .toast {
    width: 100%;
    max-width: 480px;
  }

  /* ---- Login / auth ---- */
  .login-page {
    padding: 12px;
    align-items: flex-start;
    padding-top: max(24px, env(safe-area-inset-top));
  }

  .login-card {
    width: calc(100vw - 24px);
    max-width: none;
    padding: 28px 18px 22px;
  }

  .login-card h1 {
    font-size: clamp(20px, 5vw, 24px);
  }

  .login-card input,
  .login-card .primary-btn,
  .password-field input {
    min-height: 44px;
  }

  /* ---- Misc ---- */
  .flash-stack {
    left: 12px;
    right: 12px;
    width: auto;
  }

  #accountPanel,
  #addDomainPanel,
  #domainMonitoring {
    scroll-margin-top: 68px;
  }
}

/* -------------------------------------------------------------------------- */
/* Small phones (≤480px)                                                      */
/* -------------------------------------------------------------------------- */

@media (max-width: 480px) {
  .stats-grid,
  .monitoring-meta,
  .admin-stats-grid,
  .health-cards,
  .health-summary-list,
  .info-grid,
  .account-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-right {
    grid-template-columns: 1fr;
  }

  .toolbar-right #settingsBtn {
    grid-column: auto;
  }

  .app-name {
    font-size: 13px;
  }

  .top-actions {
    gap: 6px;
  }

  .admin-page-title {
    font-size: 16px;
  }

  .table-wrap tbody td.actions-cell .action-btn,
  .table-wrap tbody td.actions-cell .inline-form {
    flex: 1 1 100%;
  }
}

/* -------------------------------------------------------------------------- */
/* Landscape phones — avoid overly tall drawers                               */
/* -------------------------------------------------------------------------- */

@media (max-width: 768px) and (orientation: landscape) {
  .admin-sidebar,
  .user-drawer {
    width: min(320px, 70vw);
  }

  .modal-card,
  .modal-card.modal-wide {
    max-height: 85vh;
  }

  .login-page {
    place-items: center;
    padding-top: 12px;
  }
}
