/* ==========================================================================
   Mobile and responsive overrides
   ========================================================================== */

@media (max-width: 992px) {
  .stats-grid-4x2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .chart-card-wide {
    grid-column: 1;
  }
}

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

  .container,
  .admin-header .container,
  .section.container {
    width: 100%;
    max-width: 100%;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .section {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }

  .section-dark {
    margin: 1rem 0;
    padding: 1.25rem;
    border-radius: var(--radius-sm);
  }

  .main-content {
    min-height: calc(100vh - 160px);
    min-height: calc(100svh - 160px);
  }

  /* Navigation */
  .navbar {
    position: sticky;
    top: 0;
  }

  .nav-container {
    height: 56px;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
    position: relative;
  }

  .nav-logo {
    min-width: 0;
    max-width: calc(100vw - 5rem);
  }

  .logo-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .nav-toggle {
    display: flex;
    flex-shrink: 0;
  }

  .nav-links {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    max-height: calc(100vh - 56px);
    max-height: calc(100svh - 56px);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem;
    z-index: 1000;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  }

  .nav-links.active {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .nav-item,
  .nav-item-home,
  .nav-item-servers,
  .nav-item-community,
  .nav-item-monitoring,
  .nav-item-profile,
  .nav-item-admin,
  .nav-item-auth,
  .nav-item-theme-lang {
    grid-column: auto;
    grid-row: auto;
    min-width: 0;
  }

  .nav-item-placeholder {
    display: none;
  }

  .nav-item {
    display: flex;
    align-items: stretch;
    justify-content: stretch;
  }

  .nav-link,
  .btn-nav-outline,
  .btn-nav-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: 0.65rem 0.75rem;
    text-align: center;
    white-space: normal;
  }

  .nav-item-auth,
  .nav-item-theme-lang {
    grid-column: 1 / -1;
  }

  .nav-item-auth form {
    width: 100%;
  }

  .nav-item-theme-lang {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.25rem;
  }

  .nav-item-theme-lang .language-selector,
  .nav-item-theme-lang .theme-selector {
    width: 100%;
    min-width: 0;
    max-width: none;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    padding: 0.5rem 0.55rem;
  }

  .nav-item-theme-lang .effect-speed-container {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .nav-item-theme-lang .effect-speed-slider {
    width: min(180px, 60vw);
    min-width: 120px;
  }

  /* General layout */
  .hero {
    padding: 2.75rem 0 2rem;
  }

  .hero-title {
    font-size: 2rem;
    line-height: 1.1;
    overflow-wrap: anywhere;
  }

  .hero-subtitle,
  .page-desc {
    font-size: 0.95rem;
    overflow-wrap: anywhere;
  }

  .hero-actions,
  .detail-actions,
  .form-actions,
  .analytics-controls {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
    width: 100%;
  }

  .hero-actions .btn,
  .detail-actions .btn,
  .form-actions .btn,
  .analytics-controls .btn,
  .analytics-controls select {
    width: 100%;
    min-width: 0;
  }

  .hero-stats,
  .modal-meta {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .news-grid,
  .server-grid,
  .profile-grid,
  .resources-grid,
  .detail-grid,
  .footer-grid,
  .form-row,
  .settings-grid,
  .bilingual-form-unified,
  .charts-grid {
    grid-template-columns: 1fr !important;
  }

  .stats-grid,
  .stats-grid-7,
  .stats-grid-4x2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .stat-card {
    min-width: 0;
    padding: 0.9rem;
    gap: 0.65rem;
  }

  .stat-info,
  .stat-content {
    min-width: 0;
  }

  .stat-info .stat-label,
  .stat-content .stat-label,
  .stat-info .stat-number,
  .stat-content .stat-number {
    max-width: 100%;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .stat-info .stat-number,
  .stat-content .stat-number {
    font-size: 1.45rem;
    line-height: 1.1;
  }

  .server-card,
  .news-card,
  .profile-card,
  .resource-card,
  .form-card,
  .admin-table-wrapper,
  .chart-card {
    width: 100%;
    min-width: 0;
    border-radius: var(--radius-sm);
  }

  .server-card-header,
  .server-card-footer,
  .resource-header,
  .admin-section-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .server-card-footer .btn,
  .admin-section-header .btn {
    width: 100%;
    min-width: 0;
  }

  .server-title,
  .server-desc,
  .news-title,
  .news-excerpt,
  .resource-title,
  .page-title,
  .section-title,
  .admin-section-header h2 {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .page-title,
  .section-title {
    font-size: 1.65rem;
    line-height: 1.15;
  }

  /* Forms */
  .auth-card,
  .form-card,
  .settings-card {
    padding: 1rem;
  }

  .form-fieldset {
    padding: 1rem;
    min-width: 0;
  }

  .form-group,
  .language-column,
  .image-section,
  .style-options,
  .settings-col-left,
  .settings-col-right {
    min-width: 0;
  }

  .form-input,
  .form-textarea,
  .chat-input,
  select,
  textarea,
  input {
    max-width: 100%;
  }

  .style-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .style-option {
    padding: 0.75rem;
  }

  .hero-preview {
    padding: 1.5rem 1rem;
  }

  .hero-preview .hero-title {
    font-size: 1.65rem;
    letter-spacing: 0.02em;
    overflow-wrap: anywhere;
  }

  .hero-preview .hero-subtitle {
    font-size: 0.9rem;
  }

  .settings-card div[style*="align-items: flex-end"] {
    flex-direction: column;
    align-items: stretch !important;
  }

  .settings-card div[style*="align-items: flex-end"] > * {
    width: 100%;
  }

  .settings-card #newGameIconBtn,
  .settings-card #newGameIconBtn + .btn,
  .settings-card button {
    max-width: 100%;
  }

  /* Admin */
  .admin-header {
    padding: 1.4rem 0 0.75rem;
  }

  .admin-nav {
    gap: 0.4rem;
    padding-bottom: 0.4rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .admin-tab {
    flex: 0 0 auto;
    min-width: auto;
    padding: 0.55rem 0.75rem;
    font-size: 0.78rem;
    scroll-snap-align: start;
  }

  .table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
  }

  .data-table {
    width: max-content;
    min-width: 640px;
    table-layout: auto;
  }

  .data-table th,
  .data-table td {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
  }

  .data-table.table-users {
    min-width: 920px;
  }

  .data-table.table-news,
  .data-table.table-servers,
  .visitor-log-table {
    min-width: 780px;
  }

  .actions-cell {
    min-width: 0;
    flex-wrap: nowrap;
  }

  .actions-cell .btn,
  .btn-xs[data-i18n],
  .btn-sm[data-i18n] {
    min-width: 0;
  }

  .chart-card {
    min-height: 300px;
  }

  .chart-body {
    min-height: 240px;
  }

  .visitor-pages-cell {
    white-space: normal !important;
    min-width: 220px;
  }

  /* Modals */
  .modal {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }

  .modal-content {
    width: 100% !important;
    max-width: none !important;
    height: 100vh;
    height: 100svh;
    max-height: 100vh;
    max-height: 100svh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    display: flex;
    flex-direction: column;
  }

  .modal-header {
    flex-shrink: 0;
    padding: 0.9rem 1rem;
    gap: 0.75rem;
  }

  .modal-header h2 {
    min-width: 0;
    font-size: 1rem;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .modal-body,
  .modal-body-scroll,
  .preview-pane,
  .crop-container {
    flex: 1 1 auto;
    max-height: none !important;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem;
  }

  #newsForm {
    min-height: 0;
    flex: 1 1 auto;
  }

  .preview-tabs,
  .crop-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .preview-tab,
  .crop-controls .btn {
    width: 100%;
  }

  .preview-home-bg,
  .preview-full-bg {
    padding: 1rem;
    overflow-x: hidden;
  }

  .preview-full-article,
  .preview-home-bg .news-grid {
    max-width: 100% !important;
  }

  /* Community chat */
  .chat-layout {
    grid-template-columns: 1fr !important;
  }

  .chat-nickname-bar,
  .chat-form {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-form .btn,
  .chat-nickname-bar .btn {
    width: 100%;
  }

  .chat-messages {
    max-height: 55svh;
  }

  .online-users-container {
    max-height: 220px !important;
  }

  .footer {
    margin-top: 2rem;
    padding: 2rem 0 1rem;
  }

  .footer-section h4 {
    white-space: normal;
  }

  .footer-bottom p {
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  .container,
  .admin-header .container,
  .section.container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .stats-grid,
  .stats-grid-7,
  .stats-grid-4x2 {
    grid-template-columns: 1fr;
  }

  .nav-links.active {
    grid-template-columns: 1fr;
  }

  .nav-item-auth,
  .nav-item-theme-lang {
    grid-column: auto;
  }

  .nav-item-theme-lang {
    grid-template-columns: 1fr;
  }

  .hero-title {
    font-size: 1.75rem;
  }

  .page-title,
  .section-title {
    font-size: 1.45rem;
  }

  .btn {
    width: 100%;
    min-width: 0;
    padding-left: 1rem;
    padding-right: 1rem;
    white-space: normal;
  }

  .actions-cell .btn,
  .modal-close,
  .nav-toggle {
    width: auto;
    flex-shrink: 0;
  }

  .style-options {
    grid-template-columns: 1fr;
  }

  .form-fieldset,
  .auth-card,
  .form-card,
  .settings-card,
  .resource-card,
  .profile-card {
    padding: 0.85rem;
  }

  .data-table {
    min-width: 600px;
  }

  .data-table.table-users {
    min-width: 860px;
  }

  .data-table.table-news,
  .data-table.table-servers,
  .visitor-log-table {
    min-width: 720px;
  }

  .modal-header,
  .modal-body,
  .modal-body-scroll,
  .preview-pane,
  .crop-container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}
