/* ========================================= */
/* RESPONSIVE LAYOUT SYSTEM                  */
/* ========================================= */

/* Page Layouts */
.page-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  flex-shrink: 0;
  background: white;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: var(--shadow-sm);
}

.page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.page-content {
  flex: 1;
  padding: var(--space-lg);
  background: #f8fafc;
}

.page-footer {
  flex-shrink: 0;
  background: white;
  border-top: 1px solid #e5e7eb;
  padding: var(--space-lg);
  text-align: center;
  color: #6b7280;
  font-size: var(--text-sm);
}

/* Dashboard Layout */
.dashboard-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
  min-height: 100vh;
}

.dashboard-sidebar {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  height: fit-content;
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.dashboard-header {
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
}

.dashboard-content {
  display: grid;
  gap: var(--space-lg);
}

/* Card Grid Layouts */
.card-grid {
  display: grid;
  gap: var(--space-lg);
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.card-grid-sm {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.card-grid-lg {
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
}

/* Two Column Layout */
.two-column-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
}

.two-column-main {
  order: 1;
}

.two-column-sidebar {
  order: 2;
}

/* Three Column Layout */
.three-column-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
}

.three-column-left {
  order: 1;
}

.three-column-main {
  order: 2;
}

.three-column-right {
  order: 3;
}

/* Modal Layouts */
.modal-layout {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-md);
}

.modal-content {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  width: 100%;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-lg);
  border-bottom: 1px solid #e5e7eb;
}

.modal-body {
  padding: var(--space-lg);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-lg);
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

/* Table Layouts */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid #e5e7eb;
  background: white;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

.table th,
.table td {
  padding: var(--space-md);
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.table th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  font-size: var(--text-sm);
}

.table tbody tr:hover {
  background: #f9fafb;
}

/* List Layouts */
.list-container {
  background: white;
  border-radius: var(--radius-lg);
  border: 1px solid #e5e7eb;
  overflow: hidden;
}

.list-item {
  display: flex;
  align-items: center;
  padding: var(--space-lg);
  border-bottom: 1px solid #e5e7eb;
  transition: background-color 0.2s ease;
}

.list-item:last-child {
  border-bottom: none;
}

.list-item:hover {
  background: #f9fafb;
}

.list-item-content {
  flex: 1;
}

.list-item-actions {
  display: flex;
  gap: var(--space-sm);
  margin-left: var(--space-md);
}

/* Form Layouts */
.form-layout {
  max-width: 600px;
  margin: 0 auto;
  background: white;
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
}

.form-layout-wide {
  max-width: 800px;
}

.form-layout-full {
  max-width: none;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.form-row-2 {
  grid-template-columns: repeat(2, 1fr);
}

.form-row-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* ========================================= */
/* RESPONSIVE BREAKPOINTS                    */
/* ========================================= */

/* Mobile Layouts */
@media (max-width: 480px) {
  .page-content {
    padding: var(--space-md);
  }
  
  .dashboard-layout {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  
  .dashboard-sidebar {
    order: 2;
  }
  
  .dashboard-main {
    order: 1;
  }
  
  .card-grid {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  
  .card-grid-sm,
  .card-grid-lg {
    grid-template-columns: 1fr;
  }
  
  .two-column-layout {
    grid-template-columns: 1fr;
  }
  
  .three-column-layout {
    grid-template-columns: 1fr;
  }
  
  .modal-content {
    max-width: 95vw;
    margin: var(--space-sm);
  }
  
  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--space-md);
  }
  
  .form-layout {
    padding: var(--space-lg);
    margin: var(--space-sm);
  }
  
  .form-row-2,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
  
  .list-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }
  
  .list-item-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }
  
  /* Mobile table as cards */
  .table-container {
    border: none;
    background: transparent;
  }
  
  .table,
  .table thead,
  .table tbody,
  .table th,
  .table td,
  .table tr {
    display: block;
  }
  
  .table thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }
  
  .table tr {
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    padding: var(--space-md);
    background: white;
  }
  
  .table td {
    border: none;
    position: relative;
    padding: var(--space-sm) 0;
    border-bottom: 1px solid #f3f4f6;
  }
  
  .table td:before {
    content: attr(data-label) ": ";
    font-weight: 600;
    color: #374151;
    font-size: var(--text-sm);
    margin-bottom: var(--space-xs);
    display: block;
  }
  
  .table td:last-child {
    border-bottom: none;
    margin-bottom: 0;
  }
}

/* Tablet Layouts */
@media (min-width: 481px) and (max-width: 768px) {
  .page-content {
    padding: var(--space-lg);
  }
  
  .dashboard-layout {
    grid-template-columns: 1fr;
    gap: var(--space-lg);
  }
  
  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
  }
  
  .card-grid-sm {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
  
  .card-grid-lg {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  }
  
  .two-column-layout {
    grid-template-columns: 1fr 300px;
  }
  
  .three-column-layout {
    grid-template-columns: 250px 1fr 250px;
  }
  
  .form-row-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}

/* Desktop Layouts */
@media (min-width: 769px) {
  .page-content {
    padding: var(--space-xl);
  }
  
  .dashboard-layout {
    grid-template-columns: 300px 1fr;
    gap: var(--space-xl);
  }
  
  .dashboard-sidebar {
    order: 1;
  }
  
  .dashboard-main {
    order: 2;
  }
  
  .card-grid {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-xl);
  }
  
  .card-grid-sm {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
  
  .card-grid-lg {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }
  
  .two-column-layout {
    grid-template-columns: 1fr 350px;
  }
  
  .three-column-layout {
    grid-template-columns: 300px 1fr 300px;
  }
  
  .form-row-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .form-row-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ========================================= */
/* UTILITY CLASSES                           */
/* ========================================= */

/* Spacing utilities */
.space-y > * + * {
  margin-top: var(--space-md);
}

.space-y-sm > * + * {
  margin-top: var(--space-sm);
}

.space-y-lg > * + * {
  margin-top: var(--space-lg);
}

.space-y-xl > * + * {
  margin-top: var(--space-xl);
}

.space-x > * + * {
  margin-left: var(--space-md);
}

.space-x-sm > * + * {
  margin-left: var(--space-sm);
}

.space-x-lg > * + * {
  margin-left: var(--space-lg);
}

.space-x-xl > * + * {
  margin-left: var(--space-xl);
}

/* Overflow utilities */
.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}

.overflow-scroll {
  overflow: scroll;
}

.overflow-x-auto {
  overflow-x: auto;
}

.overflow-y-auto {
  overflow-y: auto;
}

/* Height utilities */
.h-screen {
  height: 100vh;
}

.h-full {
  height: 100%;
}

.min-h-screen {
  min-height: 100vh;
}

/* Width utilities */
.w-full {
  width: 100%;
}

.w-auto {
  width: auto;
}

.max-w-full {
  max-width: 100%;
}

/* ========================================= */
/* ACCESSIBILITY IMPROVEMENTS                */
/* ========================================= */

/* Focus styles */
.modal-content:focus-within {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .page-header,
  .dashboard-header,
  .modal-content,
  .list-container,
  .form-layout {
    border: 2px solid #000;
  }
  
  .table th {
    background: #000;
    color: #fff;
  }
  
  .list-item:hover {
    background: #000;
    color: #fff;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .modal-layout,
  .list-item,
  .table tbody tr {
    transition: none;
  }
}
