/* ===========================================
   📱 RESPONSIVE - 响应式设计
   =========================================== */

/* ===== TABLET AND UP (768px+) ===== */
@media (min-width: 768px) {
  .container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-6);
  }

  .grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* Sidebar Layout */
  .sidebar {
    position: fixed;
    top: 73px;
    left: 0;
    height: calc(100vh - 73px);
    z-index: var(--z-sticky);
  }

  .content {
    margin-left: 290px; /* 增加10px来确保内容不被sidebar遮挡 */
    max-width: calc(100vw - 290px);
  }

  .content--sidebar-collapsed {
    margin-left: 0;
    max-width: 100vw;
  }

  /* Form Rows */
  .form-row {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Modal Adjustments */
  .modal__content {
    max-width: 600px;
    margin: var(--space-8);
  }

  .modal__footer {
    flex-direction: row;
    justify-content: flex-end;
  }

  .modal__footer .btn {
    width: auto;
  }
}

/* ===== DESKTOP (1024px+) ===== */
@media (min-width: 1024px) {
  .container {
    padding: 0 var(--space-8);
  }

  /* Dashboard Stats Grid */
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Password Grid */
  .passwords-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Modal Size */
  .modal__content {
    max-width: 700px;
  }
}

/* ===== LARGE DESKTOP (1280px+) ===== */
@media (min-width: 1280px) {
  .container {
    max-width: 1400px;
  }

  /* Dashboard Stats Grid */
  .dashboard-stats {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Password Grid */
  .passwords-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Modal Size */
  .modal__content {
    max-width: 800px;
  }
}

/* ===== MOBILE (< 768px) ===== */
@media (max-width: 767px) {
  /* Global Adjustments */
  body {
    font-size: var(--font-size-sm);
  }

  /* Header */
  .header {
    position: relative;
  }

  .header__content {
    padding: var(--space-3) var(--space-4);
  }

  .header__left {
    flex-shrink: 0;
  }

  .header__center {
    display: none; /* Hide search on mobile */
  }

  .header__right {
    gap: var(--space-2);
  }

  /* Sidebar */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: var(--z-modal);
    transform: translateX(-100%);
    transition: transform var(--transition-base);
    border-radius: 0 var(--border-radius-lg) var(--border-radius-lg) 0;
    box-shadow: var(--shadow-lg);
  }

  .sidebar--open {
    transform: translateX(0);
  }

  .sidebar--collapsed {
    transform: translateX(-100%);
  }

  /* Content */
  .content {
    margin-left: 0;
    padding: var(--space-4);
  }

  /* Sidebar Toggle */
  .sidebar-toggle {
    display: block;
    position: relative;
    z-index: var(--z-sticky);
  }

  /* Mobile Overlay */
  .mobile-overlay {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-modal - 1));
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
  }

  .mobile-overlay--active {
    opacity: 1;
    visibility: visible;
  }

  /* Page Header */
  .page-header {
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
  }

  .page-header__title {
    font-size: var(--font-size-2xl);
    line-height: 1.3;
  }

  .page-header__description {
    font-size: var(--font-size-sm);
  }

  .page-header__content {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-3);
  }

  .page-header__actions {
    width: 100%;
    justify-content: stretch;
    flex-direction: column;
  }

  .page-header__actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Dashboard Stats */
  .dashboard-stats {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }

  .stat-card {
    padding: var(--space-4);
  }

  .stat-card__content {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
  }

  .stat-card__number {
    font-size: var(--font-size-2xl);
  }

  .stat-card__label {
    font-size: var(--font-size-xs);
  }

  /* Password Grid */
  .passwords-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  /* Cards */
  .card {
    margin-bottom: var(--space-3);
  }

  .card__header,
  .card__body,
  .card__footer {
    padding: var(--space-4);
  }

  /* Modals */
  .modal {
    padding: var(--space-2);
  }

  .modal__content {
    margin: 0;
    max-width: none;
    max-height: calc(100vh - var(--space-4));
    border-radius: var(--border-radius-lg);
  }

  .modal__header,
  .modal__body,
  .modal__footer {
    padding: var(--space-4);
  }

  .modal__title {
    font-size: var(--font-size-lg);
  }

  .modal__footer {
    flex-direction: column;
    gap: var(--space-2);
  }

  .modal__footer .btn {
    width: 100%;
  }

  /* Forms */
  .form-group {
    margin-bottom: var(--space-4);
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  /* Buttons */
  .btn {
    width: 100%;
    justify-content: center;
    padding: var(--space-3) var(--space-4);
  }

  .btn + .btn {
    margin-top: var(--space-2);
  }

  /* Tables */
  table {
    font-size: var(--font-size-xs);
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  th,
  td {
    padding: var(--space-2);
    min-width: 120px;
  }

  /* Toasts */
  .toast {
    position: fixed;
    bottom: var(--space-4);
    left: var(--space-4);
    right: var(--space-4);
    top: auto;
    max-width: none;
    transform: translateY(100%);
  }

  .toast--show {
    transform: translateY(0);
  }

  /* Touch Targets */
  button,
  .btn,
  .nav-item,
  input,
  select,
  textarea {
    min-height: 44px; /* iOS minimum touch target */
  }

  /* Scrolling */
  .sidebar__nav,
  .modal__body,
  .content {
    -webkit-overflow-scrolling: touch;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .sidebar,
  .header,
  .modal,
  .btn--floating,
  .toast {
    display: none !important;
  }

  .content {
    margin-left: 0 !important;
    max-width: none !important;
  }

  .card,
  .stat-card {
    box-shadow: none !important;
    border: 1px solid #000 !important;
    break-inside: avoid;
  }

  .page {
    page-break-inside: avoid;
  }

  * {
    color: #000 !important;
    background: #fff !important;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --color-gray-50: #0f172a;
    --color-gray-100: #1e293b;
    --color-gray-200: #334155;
    --color-gray-300: #475569;
    --color-gray-400: #64748b;
    --color-gray-500: #94a3b8;
    --color-gray-600: #cbd5e1;
    --color-gray-700: #e2e8f0;
    --color-gray-800: #f1f5f9;
    --color-gray-900: #f8fafc;

    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
  }
}

/* ===== HIGH CONTRAST ===== */
@media (prefers-contrast: high) {
  :root {
    --border-width: 2px;
    --shadow-sm: none;
    --shadow-md: 0 0 0 2px var(--color-primary);
    --shadow-lg: 0 0 0 4px var(--color-primary);
  }

  .card,
  .stat-card,
  .modal__content,
  .btn {
    border: 2px solid var(--border-color);
    box-shadow: none;
  }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .sidebar {
    transition: none;
  }

  .modal {
    transition: none;
  }
}
