/* ==================================
   CSS Variables for Theming
   ================================== */

:root {
  /* Elevation overlays */
  --elevate-1: rgba(0, 0, 0, 0.03);
  --elevate-2: rgba(0, 0, 0, 0.08);

  /* Color tokens - Light Mode */
  --background: hsl(0, 0%, 100%);
  --foreground: hsl(0, 0%, 9%);
  --border: hsl(0, 0%, 89%);
  --card: hsl(0, 0%, 98%);
  --card-foreground: hsl(0, 0%, 9%);
  --card-border: hsl(0, 0%, 93%);
  --primary: hsl(217, 91%, 60%);
  --primary-foreground: hsl(0, 0%, 100%);
  --secondary: hsl(0, 0%, 90%);
  --secondary-foreground: hsl(0, 0%, 9%);
  --muted: hsl(217, 10%, 92%);
  --muted-foreground: hsl(217, 10%, 40%);
  --accent: hsl(217, 12%, 89%);
  --accent-foreground: hsl(217, 12%, 25%);
  --destructive: hsl(0, 84%, 60%);
  --destructive-foreground: hsl(0, 0%, 100%);
  --input: hsl(0, 0%, 75%);
  --ring: hsl(217, 91%, 60%);

  /* Fonts */
  --font-sans: Inter, system-ui, -apple-system, sans-serif;
  
  /* Shadows */
  --shadow-sm: 0px 2px 4px -1px hsl(0 0% 0% / 0.06), 0px 1px 2px -1px hsl(0 0% 0% / 0.04);
  --shadow: 0px 4px 6px -1px hsl(0 0% 0% / 0.08), 0px 2px 4px -2px hsl(0 0% 0% / 0.05);
  --shadow-md: 0px 6px 12px -2px hsl(0 0% 0% / 0.10), 0px 3px 6px -3px hsl(0 0% 0% / 0.06);
}

.dark {
  --elevate-1: rgba(255, 255, 255, 0.04);
  --elevate-2: rgba(255, 255, 255, 0.09);

  --background: hsl(0, 0%, 9%);
  --foreground: hsl(0, 0%, 98%);
  --border: hsl(0, 0%, 18%);
  --card: hsl(0, 0%, 11%);
  --card-foreground: hsl(0, 0%, 98%);
  --card-border: hsl(0, 0%, 16%);
  --primary: hsl(217, 91%, 60%);
  --primary-foreground: hsl(0, 0%, 100%);
  --secondary: hsl(0, 0%, 18%);
  --secondary-foreground: hsl(0, 0%, 98%);
  --muted: hsl(217, 10%, 17%);
  --muted-foreground: hsl(217, 10%, 70%);
  --accent: hsl(217, 12%, 19%);
  --accent-foreground: hsl(217, 12%, 85%);
  --destructive: hsl(0, 84%, 60%);
  --destructive-foreground: hsl(0, 0%, 100%);
  --input: hsl(0, 0%, 30%);
  --ring: hsl(217, 91%, 60%);
}

/* ==================================
   Base Styles
   ================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==================================
   Layout
   ================================== */

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  border-bottom: 1px solid var(--border);
  background-color: var(--background);
}

.header-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.heading {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--foreground);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
}

/* ==================================
   Buttons
   ================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0 1rem;
  min-height: 2.25rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: visible;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn svg {
  width: 1rem;
  height: 1rem;
}

.btn-primary {
  background-color: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

.btn-secondary {
  background-color: var(--secondary);
  color: var(--secondary-foreground);
  border-color: var(--secondary);
}

.btn-destructive {
  background-color: var(--destructive);
  color: var(--destructive-foreground);
  border-color: var(--destructive);
}

.btn-ghost {
  background-color: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background-color: var(--accent);
}

.btn-icon {
  min-height: 2.25rem;
  width: 2.25rem;
  padding: 0;
}

.btn-sm {
  min-height: 2rem;
  padding: 0 0.75rem;
  font-size: 0.875rem;
}

/* Hover effect */
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 1;
}

.btn:not(:disabled):hover::after {
  background-color: var(--elevate-1);
}

.btn:not(:disabled):active::after {
  background-color: var(--elevate-2);
}

.btn-close {
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
}

.btn-close:hover {
  background-color: var(--accent);
  color: var(--accent-foreground);
}

/* ==================================
   Search
   ================================== */

.search-container {
  margin-bottom: 1rem;
}

.search-input-wrapper {
  position: relative;
  max-width: 28rem;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted-foreground);
  width: 1rem;
  height: 1rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  border: 1px solid var(--input);
  border-radius: 0.375rem;
  background-color: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--ring);
}

.search-input::placeholder {
  color: var(--muted-foreground);
}

/* ==================================
   Table
   ================================== */

.table-container {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background-color: var(--card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background-color: var(--muted);
}

.data-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--foreground);
}

.data-table th.actions-column {
  text-align: right;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: all 0.3s ease;
  position: relative;
}

.data-table tbody tr:hover {
  background-color: var(--muted);
}

.data-table tbody tr.highlighted {
  background-color: hsl(217, 91%, 60%, 0.1);
  transform: scale(1.01);
}

.data-table tbody tr:last-child {
  border-bottom: none;
}

.data-table td {
  padding: 1rem;
  font-size: 0.875rem;
}

.data-table td:first-child {
  font-weight: 500;
}

.data-table td.actions-cell {
  text-align: right;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--foreground);
  font-size: 0.875rem;
  border-radius: 0.25rem;
  transition: background-color 0.2s;
}

.action-btn:hover {
  background-color: var(--accent);
}

.action-btn svg {
  width: 1rem;
  height: 1rem;
}

.action-btn.delete-btn {
  color: var(--destructive);
}

.action-btn.delete-btn svg {
  color: var(--destructive);
}

/* ==================================
   Table Footer
   ================================== */

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}

.qf-selector-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.qf-label {
  font-weight: 600;
  font-size: 0.875rem;
}

.qf-select {
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid var(--input);
  border-radius: 0.375rem;
  background-color: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  min-width: 350px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
}

.qf-select:focus {
  border-color: var(--ring);
}

/* ==================================
   Forms & Dialogs
   ================================== */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.dialog-overlay.hidden {
  display: none;
}

.dialog-content {
  background-color: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 0.5rem;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.dialog-small {
  max-width: 400px;
}

.dialog-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--foreground);
}

.dialog-body {
  padding: 1.5rem;
}

.dialog-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.form-group {
  margin-bottom: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--foreground);
}

.form-input,
.form-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--input);
  border-radius: 0.375rem;
  background-color: var(--background);
  color: var(--foreground);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus,
.form-select:focus {
  border-color: var(--ring);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
  padding-right: 2rem;
}

.delete-message {
  color: var(--foreground);
  font-size: 0.875rem;
}

.font-semibold {
  font-weight: 600;
  color: var(--foreground);
}

/* ==================================
   Empty State
   ================================== */

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem 1rem;
}

.empty-state.hidden {
  display: none;
}

.empty-state-content {
  text-align: center;
}

.empty-state-content p {
  margin-bottom: 1rem;
  color: var(--muted-foreground);
  font-size: 1rem;
}

/* ==================================
   Theme Toggle
   ================================== */

.icon-sun,
.icon-moon {
  width: 1rem;
  height: 1rem;
}

.hidden {
  display: none !important;
}

/* ==================================
   Utilities
   ================================== */

.text-destructive {
  color: var(--destructive);
}

/* ==================================
   Responsive
   ================================== */

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .table-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .qf-select {
    min-width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
