/* ========================================
   CAYC Developer Monitor - Unified Styles
   ======================================== */

:root {
  /* Color palette - Light Mode (default) */
  --primary: #667eea;
  --primary-dark: #5568d3;
  --primary-light: #8c9ef6;
  --secondary: #f093fb;
  --accent: #4ade80;
  --danger: #ef4444;
  --warning: #fbbf24;
  --background: #f5f5f5;
  --surface: #ffffff;
  --surface-alt: #f9f9f9;
  --border: #ddd;
  --text-primary: #333;
  --text-secondary: #666;
  --text-muted: #999;

  /* Typography */
  --font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-size-base: 1em;
  --font-size-small: 0.9em;
  --font-size-large: 1.1em;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 20px;
  --spacing-xl: 30px;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.2);
}

/* Dark Mode */
body.dark-mode {
  --primary: #667eea;
  --primary-dark: #5568d3;
  --primary-light: #8c9ef6;
  --secondary: #f093fb;
  --accent: #4ade80;
  --danger: #ef4444;
  --warning: #fbbf24;
  --background: #1a1a1a;
  --surface: #2d2d2d;
  --surface-alt: #3a3a3a;
  --border: #444;
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-muted: #808080;

  /* Shadows adapt for dark mode */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.7);
}

/* ========================================
   Global Styles
   ======================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.6;
  padding: var(--spacing-lg);
}

/* ========================================
   Container & Layout
   ======================================== */

.container {
  max-width: 1400px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--spacing-xl);
}

/* ========================================
   Typography
   ======================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text-primary);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--spacing-lg);
}

h1 {
  font-size: 2em;
}

h2 {
  font-size: 1.75em;
  margin-top: var(--spacing-xl);
}

h3 {
  font-size: 1.5em;
}

.page-title {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  margin-top: var(--spacing-xl);
  margin-bottom: var(--spacing-xl);
}

/* ========================================
   Filters & Forms
   ======================================== */

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xl);
  padding: var(--spacing-lg);
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

label {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  font-size: var(--font-size-small);
}

input[type="text"],
input[type="date"],
input[type="datetime-local"],
input[type="password"],
input[type="number"],
input[type="email"],
select,
textarea {
  padding: var(--spacing-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-base);
  font-family: var(--font-family);
  transition: all 0.2s;
  background: var(--surface);
  color: var(--text-primary);
}

input[type="text"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 5px rgba(102, 126, 234, 0.3);
}

/* ========================================
   Buttons
   ======================================== */

button,
.btn {
  padding: var(--spacing-md) var(--spacing-lg);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: all 0.2s;
  font-size: var(--font-size-base);
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn-primary,
.btn-primary:link {
  background: var(--primary);
  color: white;
}

.btn-primary:hover,
.btn-primary:active {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-secondary,
.btn-secondary:link {
  background: #e0e0e0;
  color: #000;
}

.btn-secondary:hover,
.btn-secondary:active {
  background: #d0d0d0;
  transform: translateY(-1px);
}

/* Dark mode button styles */
body.dark-mode .btn-secondary,
body.dark-mode .btn-secondary:link {
  background: #555;
  color: #000;
}

body.dark-mode .btn-secondary:hover,
body.dark-mode .btn-secondary:active {
  background: #666;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: var(--accent);
  color: white;
}

.btn-success:hover {
  background: #22c55e;
}

.button-group {
  display: flex;
  gap: var(--spacing-md);
  justify-content: center;
  flex-wrap: wrap;
}

/* ========================================
   Tables
   ======================================== */

table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--spacing-xl) 0;
}

thead {
  background: var(--primary);
  color: white;
}

th {
  padding: var(--spacing-lg);
  text-align: left;
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.2s;
}

th:hover {
  background: var(--primary-dark);
}

th::after {
  content: " ⇅";
  margin-left: var(--spacing-sm);
  opacity: 0.5;
  font-size: 0.8em;
}

/* Active sort indicators turn red with direction-specific arrow */
th.sort-asc::after {
  content: " ↑";
  color: var(--danger);
  opacity: 1;
}
th.sort-desc::after {
  content: " ↓";
  color: var(--danger);
  opacity: 1;
}

td {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--border);
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover {
  background: rgba(102, 126, 234, 0.08);
}

tbody tr:nth-child(even) {
  background: rgba(249, 249, 249, 0.5);
}

/* ========================================
   Cards & Sections
   ======================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  font-size: var(--font-size-large);
  font-weight: var(--font-weight-semibold);
  color: var(--primary);
  margin-bottom: var(--spacing-md);
  padding-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--border);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--spacing-lg);
  margin: var(--spacing-xl) 0;
}

.stat-item {
  background: var(--surface-alt);
  padding: var(--spacing-lg);
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid var(--border);
}

.stat-label {
  color: var(--text-secondary);
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--spacing-sm);
}

.stat-value {
  font-size: 1.8em;
  font-weight: var(--font-weight-bold);
  color: var(--primary);
}

/* ========================================
   Badges & Status
   ======================================== */

.badge {
  display: inline-block;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-small);
  font-weight: var(--font-weight-semibold);
}

.badge-primary {
  background: rgba(102, 126, 234, 0.2);
  color: var(--primary);
}

.badge-success {
  background: rgba(74, 222, 128, 0.2);
  color: var(--accent);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.badge-warning {
  background: rgba(251, 191, 36, 0.2);
  color: var(--warning);
}

/* ========================================
   Navigation & Menu
   ======================================== */

.menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--spacing-lg);
  margin: var(--spacing-xl) 0;
}

.menu-item {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--spacing-lg);
  text-align: center;
  transition: all 0.3s;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.menu-item:hover {
  border-color: var(--primary);
  box-shadow: 0 0 15px rgba(102, 126, 234, 0.2);
  transform: translateY(-2px);
}

.menu-item-icon {
  font-size: 3em;
  margin-bottom: var(--spacing-md);
}

.menu-item-title {
  font-size: var(--font-size-large);
  font-weight: var(--font-weight-bold);
  color: var(--primary);
  margin-bottom: var(--spacing-sm);
}

.menu-item-desc {
  font-size: var(--font-size-small);
  color: var(--text-secondary);
  line-height: 1.5;
}

.menu-group {
  margin: var(--spacing-xl) 0;
}

.menu-group-title {
  font-size: var(--font-size-large);
  font-weight: var(--font-weight-bold);
  color: var(--text-secondary);
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--border);
}

/* ========================================
   Modals & Dialogs
   ======================================== */

.modal {
  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: 1000;
}

.modal-content {
  background: var(--surface);
  padding: var(--spacing-xl);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

dialog {
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  padding: var(--spacing-xl);
  background: var(--surface);
  color: var(--text-primary);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

dialog h2 {
  margin-top: 0;
}

/* ========================================
   Alerts & Messages
   ======================================== */

.alert {
  padding: var(--spacing-lg);
  border-radius: var(--radius-md);
  margin-bottom: var(--spacing-lg);
  border-left: 4px solid;
}

.alert-info {
  background: rgba(102, 126, 234, 0.1);
  border-color: var(--primary);
  color: var(--primary);
}

.alert-success {
  background: rgba(74, 222, 128, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.alert-warning {
  background: rgba(251, 191, 36, 0.1);
  border-color: var(--warning);
  color: #b45309;
}

.alert-danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--danger);
  color: var(--danger);
}

/* ========================================
   Progress & Loading
   ======================================== */

progress {
  width: 100%;
  height: 20px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}

progress::-webkit-progress-value {
  background: var(--primary);
  border-radius: var(--radius-sm);
}

progress::-moz-progress-bar {
  background: var(--primary);
  border-radius: var(--radius-sm);
}

/* ========================================
   Utilities
   ======================================== */

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--text-muted);
}

.text-primary {
  color: var(--primary);
}

.text-danger {
  color: var(--danger);
}

.text-success {
  color: var(--accent);
}

.mt-1 {
  margin-top: var(--spacing-sm);
}
.mt-2 {
  margin-top: var(--spacing-md);
}
.mt-3 {
  margin-top: var(--spacing-lg);
}
.mt-4 {
  margin-top: var(--spacing-xl);
}

.mb-1 {
  margin-bottom: var(--spacing-sm);
}
.mb-2 {
  margin-bottom: var(--spacing-md);
}
.mb-3 {
  margin-bottom: var(--spacing-lg);
}
.mb-4 {
  margin-bottom: var(--spacing-xl);
}

.p-1 {
  padding: var(--spacing-sm);
}
.p-2 {
  padding: var(--spacing-md);
}
.p-3 {
  padding: var(--spacing-lg);
}
.p-4 {
  padding: var(--spacing-xl);
}

.gap-1 {
  gap: var(--spacing-sm);
}
.gap-2 {
  gap: var(--spacing-md);
}
.gap-3 {
  gap: var(--spacing-lg);
}

.hidden {
  display: none !important;
}

/* ========================================
   Theme Toggle Switch
   ======================================== */

.theme-toggle-container {
  position: fixed;
  left: 20px;
  top: 20px;
  z-index: 1000;
}

.theme-toggle-switch {
  position: relative;
  width: 70px;
  height: 36px;
  background: var(--surface-alt);
  border: 2px solid var(--border);
  border-radius: 50px;
  cursor: pointer;
  padding: 2px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  font-size: 1.1em;
}

.theme-toggle-switch:hover {
  box-shadow: var(--shadow-md);
  transform: scale(1.05);
}

.theme-toggle-switch:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

.toggle-light,
.toggle-dark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  position: relative;
  z-index: 2;
}

.toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 28px;
  height: 28px;
  background: var(--primary);
  border-radius: 50%;
  transition: left 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.theme-toggle-switch.dark .toggle-slider {
  left: 40px;
}

.toggle-light {
  color: var(--text-primary);
  opacity: 0.7;
}

.theme-toggle-switch.dark .toggle-light {
  opacity: 0.3;
}

.toggle-dark {
  color: var(--text-primary);
  opacity: 0.3;
}

.theme-toggle-switch.dark .toggle-dark {
  opacity: 0.7;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 768px) {
  body {
    padding: var(--spacing-md);
  }

  .container {
    padding: var(--spacing-lg);
  }

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

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

  th,
  td {
    padding: var(--spacing-md) var(--spacing-sm);
    font-size: var(--font-size-small);
  }

  h1 {
    font-size: 1.5em;
  }

  h2 {
    font-size: 1.3em;
  }
}
