/* ========================================================================
   shadcn-inspired Design System for Quick Connect Dashboard
   CSS Custom Properties + Component Classes
   ======================================================================== */

/* --- Theme Variables --------------------------------------------------- */

:root {
  /* Light theme (default) */
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;

  /* Chart colors */
  --chart-1: 12 76% 61%;
  --chart-2: 173 58% 39%;
  --chart-3: 197 37% 24%;
  --chart-4: 43 74% 66%;
  --chart-5: 27 87% 67%;

  /* Sidebar */
  --sidebar: 0 0% 98%;
  --sidebar-foreground: 240 5.3% 26.1%;
  --sidebar-border: 240 5.9% 90%;
  --sidebar-accent: 240 4.8% 95.9%;
  --sidebar-accent-foreground: 240 5.9% 10%;
}

.dark {
  --background: 240 10% 3.9%;
  --foreground: 0 0% 98%;
  --card: 240 10% 3.9%;
  --card-foreground: 0 0% 98%;
  --popover: 240 10% 3.9%;
  --popover-foreground: 0 0% 98%;
  --primary: 0 0% 98%;
  --primary-foreground: 240 5.9% 10%;
  --secondary: 240 3.7% 15.9%;
  --secondary-foreground: 0 0% 98%;
  --muted: 240 3.7% 15.9%;
  --muted-foreground: 240 5% 64.9%;
  --accent: 240 3.7% 15.9%;
  --accent-foreground: 0 0% 98%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 0 0% 98%;
  --border: 240 3.7% 15.9%;
  --input: 240 3.7% 15.9%;
  --ring: 240 4.9% 83.9%;

  --chart-1: 220 70% 50%;
  --chart-2: 160 60% 45%;
  --chart-3: 30 80% 55%;
  --chart-4: 280 65% 60%;
  --chart-5: 340 75% 55%;

  --sidebar: 240 5.9% 10%;
  --sidebar-foreground: 240 4.8% 95.9%;
  --sidebar-border: 240 3.7% 15.9%;
  --sidebar-accent: 240 3.7% 15.9%;
  --sidebar-accent-foreground: 240 4.8% 95.9%;
}

/* --- Accent Theme Variants (composable with light/dark) ---------------- */

[data-theme="blue"] {
  --primary: 221 83% 53%;
  --primary-foreground: 210 40% 98%;
  --ring: 221 83% 53%;
  --chart-1: 221 83% 53%;
  --chart-2: 212 95% 68%;
  --chart-3: 216 92% 60%;
  --chart-4: 210 98% 78%;
  --chart-5: 199 89% 48%;
}

[data-theme="green"] {
  --primary: 142 76% 36%;
  --primary-foreground: 355 7% 97%;
  --ring: 142 76% 36%;
  --chart-1: 142 76% 36%;
  --chart-2: 153 60% 53%;
  --chart-3: 160 84% 39%;
  --chart-4: 158 64% 52%;
  --chart-5: 173 58% 39%;
}

[data-theme="rose"] {
  --primary: 346 77% 49%;
  --primary-foreground: 355 7% 97%;
  --ring: 346 77% 49%;
  --chart-1: 346 77% 49%;
  --chart-2: 340 75% 55%;
  --chart-3: 350 80% 60%;
  --chart-4: 330 65% 50%;
  --chart-5: 0 84% 60%;
}

[data-theme="orange"] {
  --primary: 24 95% 53%;
  --primary-foreground: 60 9% 98%;
  --ring: 24 95% 53%;
  --chart-1: 24 95% 53%;
  --chart-2: 20 90% 48%;
  --chart-3: 30 80% 55%;
  --chart-4: 43 74% 66%;
  --chart-5: 27 87% 67%;
}

/* --- Reset & Base ------------------------------------------------------ */

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

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

a {
  color: hsl(var(--primary));
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

hr {
  border: none;
  border-top: 1px solid hsl(var(--border));
  margin: 1.5rem 0;
}

/* --- Layout ------------------------------------------------------------ */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

.container-fluid {
  width: 100%;
  padding: 0 1rem;
}

.grid {
  display: grid;
  gap: 1.5rem;
}

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

@media (max-width: 768px) {
  .grid-cols-2, .grid-cols-3 {
    grid-template-columns: 1fr;
  }
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }

.w-full { width: 100%; }

/* --- Spacing ----------------------------------------------------------- */

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }

.mx-auto { margin-left: auto; margin-right: auto; }

.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }

.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.py-12 { padding-top: 3rem; padding-bottom: 3rem; }

/* --- Typography -------------------------------------------------------- */

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

.text-xs { font-size: 0.75rem; line-height: 1rem; }
.text-sm { font-size: 0.875rem; line-height: 1.25rem; }
.text-base { font-size: 1rem; line-height: 1.5rem; }
.text-lg { font-size: 1.125rem; line-height: 1.75rem; }
.text-xl { font-size: 1.25rem; line-height: 1.75rem; }
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-3xl { font-size: 1.875rem; line-height: 2.25rem; }
.text-4xl { font-size: 2.25rem; line-height: 2.5rem; }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.text-muted { color: hsl(var(--muted-foreground)); }
.text-primary { color: hsl(var(--primary)); }
.text-destructive { color: hsl(var(--destructive)); }

.tracking-tight { letter-spacing: -0.025em; }

/* --- Navigation Bar ---------------------------------------------------- */

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid hsl(var(--border));
  background-color: hsl(var(--background));
  transition: background-color 0.3s ease, border-color 0.3s ease;
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-brand {
  display: flex;
  flex-direction: column;
}

.nav-brand-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: hsl(var(--foreground));
  letter-spacing: -0.025em;
}

.nav-brand-subtitle {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
}

.nav-items {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@media (max-width: 640px) {
  .nav {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .nav-items {
    flex-wrap: wrap;
  }
}

/* --- Buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  text-decoration: none;
  line-height: 1.25rem;
  gap: 0.5rem;
}

.btn:hover {
  text-decoration: none;
}

.btn:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.btn:disabled, .btn.is-loading {
  opacity: 0.5;
  pointer-events: none;
}

.btn-primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-primary:hover {
  background-color: hsl(var(--primary) / 0.9);
}

.btn-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}
.btn-secondary:hover {
  background-color: hsl(var(--secondary) / 0.8);
}

.btn-destructive {
  background-color: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
}
.btn-destructive:hover {
  background-color: hsl(var(--destructive) / 0.9);
}

.btn-outline {
  border-color: hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
}
.btn-outline:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.btn-ghost {
  background-color: transparent;
  color: hsl(var(--foreground));
}
.btn-ghost:hover {
  background-color: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 0.625rem 2rem;
  font-size: 1rem;
}

.btn-icon {
  padding: 0.5rem;
  width: 2.25rem;
  height: 2.25rem;
}

/* --- Cards ------------------------------------------------------------- */

.card {
  background-color: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.card-header {
  padding: 1.5rem 1.5rem 0;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.card-description {
  font-size: 0.875rem;
  color: hsl(var(--muted-foreground));
}

.card-content {
  padding: 1.5rem;
}

.card-footer {
  padding: 0 1.5rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --- Stat Cards (replacing Bulma level) -------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background-color: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: hsl(var(--foreground));
}

/* --- Forms ------------------------------------------------------------- */

.input {
  display: flex;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--ring) / 0.2);
}

.input::placeholder {
  color: hsl(var(--muted-foreground));
}

.label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  margin-bottom: 0.375rem;
}

.form-group {
  margin-bottom: 1rem;
}

/* Radio / Checkbox */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
  cursor: pointer;
}

.radio-label input[type="radio"] {
  accent-color: hsl(var(--primary));
}

/* --- Tables ------------------------------------------------------------ */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}

table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

table.table thead {
  background-color: hsl(var(--muted));
}

table.table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: hsl(var(--muted-foreground));
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid hsl(var(--border));
}

table.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid hsl(var(--border));
  color: hsl(var(--foreground));
}

table.table tbody tr:last-child td {
  border-bottom: none;
}

table.table tbody tr {
  transition: background-color 0.15s ease;
}

table.table tbody tr:hover {
  background-color: hsl(var(--muted) / 0.5);
}

/* --- Menu / Sidebar ---------------------------------------------------- */

.sidebar {
  background-color: hsl(var(--sidebar));
  border-right: 1px solid hsl(var(--sidebar-border));
  padding: 1.5rem;
  min-height: calc(100vh - 3.5rem);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.menu-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  margin-bottom: 0.5rem;
  padding: 0 0.5rem;
}

.menu-label:not(:first-child) {
  margin-top: 1.5rem;
}

.menu-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.5rem;
}

.menu-list li a {
  display: block;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: hsl(var(--sidebar-foreground));
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.menu-list li a:hover {
  background-color: hsl(var(--sidebar-accent));
  color: hsl(var(--sidebar-accent-foreground));
  text-decoration: none;
}

.menu-list li a.active {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

/* --- Alert / Banner ---------------------------------------------------- */

.alert {
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  padding: 1rem 1.25rem;
  font-size: 0.875rem;
}

.alert-warning {
  background-color: hsl(48 96% 89%);
  border-color: hsl(48 96% 70%);
  color: hsl(25 95% 30%);
}

.dark .alert-warning {
  background-color: hsl(48 30% 15%);
  border-color: hsl(48 50% 30%);
  color: hsl(48 80% 70%);
}

.alert-info {
  background-color: hsl(214 95% 93%);
  border-color: hsl(214 82% 70%);
  color: hsl(214 50% 30%);
}

.dark .alert-info {
  background-color: hsl(214 30% 15%);
  border-color: hsl(214 50% 30%);
  color: hsl(214 80% 70%);
}

/* --- Badge ------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  border: 1px solid transparent;
}

.badge-primary {
  background-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

.badge-secondary {
  background-color: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.badge-outline {
  border-color: hsl(var(--border));
  color: hsl(var(--foreground));
  background: transparent;
}

/* --- Hero Section ------------------------------------------------------ */

.hero {
  padding: 2rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid hsl(var(--border));
  background-color: hsl(var(--background));
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.hero-title {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: hsl(var(--foreground));
}

.hero-subtitle {
  font-size: 1rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.5rem;
}

/* --- Help Text --------------------------------------------------------- */

.help-text {
  font-size: 0.75rem;
  color: hsl(var(--muted-foreground));
  margin-top: 0.25rem;
}

/* --- Theme Toggle ------------------------------------------------------ */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--input));
  background-color: hsl(var(--background));
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.theme-toggle:hover {
  background-color: hsl(var(--accent));
}

.theme-toggle svg {
  width: 1rem;
  height: 1rem;
}

/* Sun icon hidden in dark mode, moon icon hidden in light mode */
.dark .icon-sun { display: none; }
.icon-moon { display: none; }
.dark .icon-moon { display: block; }
.icon-sun { display: block; }

/* --- Theme Picker Dropdown --------------------------------------------- */

.theme-picker {
  position: relative;
  display: inline-block;
}

.theme-picker-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  background-color: hsl(var(--popover));
  color: hsl(var(--popover-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 0.25rem;
  min-width: 8rem;
  z-index: 100;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

.theme-picker-menu.open {
  display: block;
}

.theme-picker-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.375rem 0.5rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: 0.875rem;
  border: none;
  background: transparent;
  color: hsl(var(--popover-foreground));
  cursor: pointer;
  text-align: left;
}

.theme-picker-item:hover {
  background-color: hsl(var(--accent));
}

.theme-picker-item.active {
  background-color: hsl(var(--accent));
  font-weight: 500;
}

.theme-swatch {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 1px solid hsl(var(--border));
}

/* --- Page Layouts ------------------------------------------------------ */

.page-with-sidebar {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: calc(100vh - 3.5rem);
}

@media (max-width: 768px) {
  .page-with-sidebar {
    grid-template-columns: 1fr;
  }
}

.page-content {
  padding: 1.5rem;
}

/* Full-height centered layout (for login) */
.center-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 3.5rem);
  padding: 2rem;
}

/* --- Chart Container --------------------------------------------------- */

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin: 1.5rem 0;
}

@media (max-width: 768px) {
  .chart-grid {
    grid-template-columns: 1fr;
  }
}

.chart-card canvas {
  max-width: 100%;
  height: auto !important;
}

/* --- Utilities --------------------------------------------------------- */

.hidden { display: none; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.rounded { border-radius: var(--radius); }
.border { border: 1px solid hsl(var(--border)); }

.shadow-sm { box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); }
.shadow { box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Loading Spinner --------------------------------------------------- */

.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid hsl(var(--muted));
  border-top-color: hsl(var(--primary));
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn.is-loading .spinner {
  margin-right: 0.25rem;
}
