:root {
  /* ===== MATERIAL DESIGN 3 - Color Palette ===== */
  --md-primary: #1976d2;
  --md-primary-container: #e3f2fd;
  --md-on-primary: #ffffff;
  --md-on-primary-container: #0d47a1;

  --md-secondary: #00897b;
  --md-secondary-container: #e0f2f1;
  --md-on-secondary: #ffffff;

  --md-surface: #ffffff;
  --md-surface-variant: #f5f5f5;
  --md-surface-container: #fafafa;
  --md-surface-container-high: #eeeeee;
  --md-on-surface: #1c1b1f;
  --md-on-surface-variant: #49454f;

  --md-outline: #e0e0e0;
  --md-outline-variant: #f5f5f5;
  --md-background: #fefefe;
  --md-on-background: #1c1b1f;

  --md-error: #ba1a1a;
  --md-on-error: #ffffff;
  --md-success: #2e7d32;
  --md-warning: #f57c00;

  /* Material Spacing */
  --md-spacing-1: 4px;
  --md-spacing-2: 8px;
  --md-spacing-3: 12px;
  --md-spacing-4: 16px;
  --md-spacing-6: 24px;
  --md-spacing-8: 32px;

  /* Material Shape */
  --md-shape-sm: 8px;
  --md-shape-md: 12px;
  --md-shape-lg: 16px;
  --md-shape-full: 9999px;

  /* ===== UNIFIED BUTTON DESIGN SYSTEM ===== */
  /* Default Theme: Blue */
  --btn-primary-light: #e3f2fd;
  --btn-secondary-light: #f5f5f5;
  --btn-danger-light: #ffebee;
  --btn-success-light: #e8f5e9;
  --btn-warning-light: #fff3e0;

  --btn-primary-base: #1976d2;
  --btn-secondary-base: #616161;
  --btn-danger-base: #d32f2f;
  --btn-success-base: #388e3c;
  --btn-warning-base: #f57c00;

  --btn-padding-default: 10px 20px;
  --btn-gap: 8px;
  --btn-radius-default: 12px;
  --btn-radius-small: 8px;
  --btn-font-weight: 500;
  --btn-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --btn-hover-lift: translateY(-1px);

  /* Legacy color aliases for styleguide */
  --primary-color: var(--btn-primary-base);
  --primary-hover: #1565c0;
  --secondary-color: var(--btn-secondary-base);
  --danger-color: var(--btn-danger-base);
  --success-color: var(--btn-success-base);
  --bg-color: var(--md-background);
}

/* ===== THEME: PURPLE ===== */
[data-theme="purple"] {
  --btn-primary-light: #f3e5f5;
  --btn-primary-base: #7b1fa2;
  --primary-color: #7b1fa2;
  --primary-hover: #6a1b9a;
  --md-primary: #7b1fa2;
  --md-primary-container: #f3e5f5;
}

/* ===== THEME: GREEN ===== */
[data-theme="green"] {
  --btn-primary-light: #e8f5e9;
  --btn-primary-base: #2e7d32;
  --primary-color: #2e7d32;
  --primary-hover: #1b5e20;
  --md-primary: #2e7d32;
  --md-primary-container: #e8f5e9;
}

/* ===== THEME: ORANGE ===== */
[data-theme="orange"] {
  --btn-primary-light: #fff3e0;
  --btn-primary-base: #f57c00;
  --primary-color: #f57c00;
  --primary-hover: #e65100;
  --md-primary: #f57c00;
  --md-primary-container: #fff3e0;
}

/* ===== THEME: RETRO (Vintage Warm) ===== */
[data-theme="retro"] {
  /* Retro palette colors */
  --btn-primary-light: #fff5e6;
  --btn-primary-base: #ee8c00;
  --btn-secondary-light: #e8f2f0;
  --btn-secondary-base: #0a6847;
  --btn-success-light: #f5f8e8;
  --btn-success-base: #cbd479;
  --btn-danger-light: #f8e8e9;
  --btn-danger-base: #9b2226;
  --btn-warning-light: #fff0e6;
  --btn-warning-base: #c14702;

  /* Aliasy */
  --primary-color: #ee8c00;
  --primary-hover: #c14702;
  --secondary-color: #0a6847;
  --success-color: #cbd479;
  --danger-color: #9b2226;

  /* Material Design tokens */
  --md-primary: #ee8c00;
  --md-primary-container: #fff5e6;
  --md-secondary: #0a6847;
  --md-secondary-container: #e8f2f0;
  --md-background: #e9e490;
  --md-surface: #f5f5dc;
  --md-surface-variant: #e9e490;
}

body {
  font-family: "Google Sans Flex", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: var(--md-background);
  color: var(--md-on-background);
  line-height: 1.6;
  margin: 0;
}

h1,
h2,
h3,
h4,
h5 {
  margin-top: 0;
}
a {
  text-decoration: none;
  color: inherit;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--btn-gap);
  padding: var(--btn-padding-default);
  border-radius: var(--btn-radius-default);
  font-weight: var(--btn-font-weight);
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: var(--btn-transition);
  line-height: 1;
  font-family: inherit; /* Fix correct font usage */
  font-size: 0.9rem; /* Match nav links */
}

.btn-primary {
  background: var(--btn-primary-light);
  color: var(--btn-primary-base);
}
.btn-primary:hover {
  background: var(--btn-primary-base);
  color: white;
  transform: var(--btn-hover-lift);
}

.btn-secondary {
  background: var(--btn-secondary-light);
  color: var(--btn-secondary-base);
}
.btn-secondary:hover {
  background: var(--btn-secondary-base);
  color: white;
  transform: var(--btn-hover-lift);
}

.btn-danger {
  background: var(--btn-danger-light);
  color: var(--btn-danger-base);
}
.btn-danger:hover {
  background: var(--btn-danger-base);
  color: white;
  transform: var(--btn-hover-lift);
}

.btn-success {
  background: var(--btn-success-light);
  color: var(--btn-success-base);
}
.btn-success:hover {
  background: var(--btn-success-base);
  color: white;
  transform: var(--btn-hover-lift);
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 1.25rem;
  position: relative;
}
.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--md-on-surface);
  font-size: 0.9rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-sm);
  background-color: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--md-primary);
  box-shadow: 0 0 0 3px var(--md-primary-container);
}

/* Autocomplete Dropdown (Legacy Port) */
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  max-height: 240px;
  overflow-y: auto;
  display: none; /* JS toggles this */
  margin-top: 4px;
}
.autocomplete-list.active {
  display: block;
}

.autocomplete-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.2s;
  color: #334155;
  border-bottom: 1px solid #f1f5f9;
}
.autocomplete-item:last-child {
  border-bottom: none;
}
.autocomplete-item:hover,
.autocomplete-item.selected {
  background-color: #f8fafc;
  color: #0284c7;
}
.autocomplete-item strong {
  color: #0284c7;
  font-weight: 600;
}
.autocomplete-add-new {
  background-color: #f0f9ff;
  border-top: 2px solid #e0f2fe;
  color: #0284c7;
  font-weight: 500;
}
.autocomplete-add-new:hover {
  background-color: #e0f2fe;
  color: #0369a1;
}

/* ===== ALERTS ===== */
.alert {
  padding: 1rem;
  border-radius: var(--md-shape-md);
  margin-bottom: 1rem;
  border-left: 4px solid transparent;
}
.alert-info {
  background-color: #e3f2fd;
  border-left-color: var(--md-primary);
  color: #0d47a1;
}
.alert-success {
  background-color: #e8f5e9;
  border-left-color: var(--md-success);
  color: #1b5e20;
}
.alert-danger {
  background-color: #ffebee;
  border-left-color: var(--md-error);
  color: #b71c1c;
}

/* ===== NAVBAR ===== */
/* ===== NAVBAR (LEGACY PORT) ===== */
.navbar {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(224, 224, 224, 0.5);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* ===== ADMIN SIDEBAR (LEGACY PORT) ===== */
:root {
  --sidebar-width: 260px;
  --admin-bg: #f8f9fa;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e2e8f0;
}

.admin-body-mock {
  background-color: var(--admin-bg);
  display: flex;
  min-height: 400px; /* Demo height */
  border: 1px solid #ccc;
  position: relative;
  overflow: hidden;
}

.admin-sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  box-sizing: border-box;
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a202c;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  text-decoration: none;
}

.sidebar-logo {
  height: 60px;
  width: auto;
  display: block;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-category {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: #a0aec0;
  font-weight: 600;
  margin-bottom: 0.5rem;
  margin-top: 1.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
  background: var(--btn-success-light);
  color: var(--btn-success-base);
}

.nav-item:hover {
  background: var(--btn-success-base);
  color: white;
  transform: translateY(-1px);
}

.nav-item.active {
  background: var(--btn-success-base);
  color: white;
}

.nav-item[href*="logout"] {
  background: var(--btn-danger-light);
  color: var(--btn-danger-base);
}

.nav-item[href*="logout"]:hover {
  background: var(--btn-danger-base);
  color: white;
}

/* Admin Main Content Mock */
.admin-main {
  flex: 1;
  padding: 2rem;
  background: var(--admin-bg);
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 500;
  color: #1a202c;
  margin: 0;
}

.admin-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.profile-info {
  text-align: right;
}

.profile-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: #2d3748;
}

.profile-role {
  font-size: 0.8rem;
  color: #718096;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  background: #cbd5e0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a5568;
  font-weight: 600;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.nav-brand {
  font-size: 1.375rem;
  font-weight: 500;
  color: var(--md-on-surface);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.2s;
}

.nav-brand:hover {
  opacity: 0.8;
}

.nav-logo {
  height: 40px;
  width: auto;
  display: block;
}

.nav-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

.nav-link {
  color: var(--md-on-surface-variant);
  text-decoration: none;
  padding: var(--btn-padding-default);
  border-radius: var(--btn-radius-default);
  transition: all 0.5s;
  font-weight: 500;
  font-size: 0.95rem; /* Slightly larger match standard text better */
  display: inline-flex;
  align-items: center;
  gap: var(--btn-gap);
}

.nav-link:hover {
  background: var(--md-surface-variant);
  color: var(--md-on-surface);
}

@media (max-width: 768px) {
  .nav-links {
    display: none; /* Mobile menu logic needed if full port, but keeping simple for styleguide */
  }
  /* Minimal mobile support for styleguide */
  .nav-links.active {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
}

/* ===== FOOTER (RECONSTRUCTED) ===== */
.footer {
  background: white;
  border-top: 1px solid var(--md-outline);
  margin-top: auto; /* Push to bottom */
  padding: 2rem 0;
  color: var(--md-on-surface-variant);
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  text-align: center;
}

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.footer-link {
  color: var(--md-on-surface-variant);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.footer-link:hover {
  color: var(--md-primary);
}

.footer-copyright {
  font-size: 0.8rem;
  color: #999;
}

/* ===== UTILS ===== */
.card {
  background: white;
  padding: 2rem;
  border-radius: var(--md-shape-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--md-outline);
  margin-bottom: 1.5rem;
}

/* Legacy Toggle Switch (from Admin) */
.toggle-switch {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
  background-color: #ccc;
  border-radius: 24px;
  transition: 0.4s;
  margin-right: 0px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: 0.4s;
}
.toggle-switch input:checked + .slider {
  background-color: var(--md-primary);
}
.toggle-switch input:checked + .slider:before {
  transform: translateX(24px);
}

/* Legacy Radio & Checkbox Labels */
.radio-group,
.checkbox-group {
  display: flex;
  gap: 10px;
}
.radio-label,
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-sm);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
  color: var(--md-on-surface);
}
.radio-label:hover,
.checkbox-label:hover {
  background-color: var(--md-surface-variant);
  border-color: var(--md-primary);
}
.radio-label input[type="radio"],
.checkbox-label input[type="checkbox"] {
  accent-color: var(--md-primary);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ===== CUSTOM DROPDOWN (LEGACY SELECT PORT) ===== */
.custom-dropdown {
  position: relative;
  min-width: 200px;
  cursor: pointer;
}

.dropdown-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.75rem 1rem;
  background: white;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-shape-sm);
  transition: all 0.2s;
  box-sizing: border-box; /* Fix sizing */
}

.dropdown-trigger:hover {
  border-color: var(--md-primary);
}

.dropdown-selected {
  font-family: inherit;
  font-size: 1rem;
  color: var(--md-on-surface);
  user-select: none;
  flex: 1;
}

.dropdown-arrow {
  font-size: 1.25rem;
  color: var(--md-on-surface-variant);
  transition: transform 0.2s;
  margin-left: 0.5rem;
}

.custom-dropdown.active .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: var(--md-shape-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  max-height: 250px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
}

.custom-dropdown.active .dropdown-menu {
  display: block;
}

.dropdown-option {
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  font-size: 1rem;
  color: var(--md-on-surface);
}

.dropdown-option:hover {
  background: #f8fafc;
  color: var(--md-primary);
}

.dropdown-option.selected {
  background: #e6fffa;
  color: #00897b; /* Secondary color match */
  font-weight: 500;
}

/* ===== NAVBAR USER PROFILE ===== */
.user-info-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--md-outline-variant);
  position: relative;
}

.user-name-nav {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--md-on-surface);
}

.avatar-nav {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: var(--md-surface-variant);
  color: var(--md-on-surface);
  border: none;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
  font-size: 1rem;
}

.avatar-nav:hover {
  background-color: var(--md-outline);
}

/* Fix Dropdown Position */
.avatar-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: white;
  border: 1px solid var(--md-outline);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  min-width: 200px; /* Keep min-width for look */
  width: max-content; /* Allow to grow */
  display: none;
  flex-direction: column;
  padding: 8px 0;
  z-index: 1001;
}

.avatar-dropdown.active {
  display: flex;
}

.avatar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--md-on-surface);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
  white-space: nowrap; /* Prevent wrapping */
}

.avatar-dropdown-item:hover {
  background: var(--md-surface-variant);
}

.avatar-dropdown-item.logout {
  color: var(--md-error);
}

.avatar-dropdown-item.logout:hover {
  background: var(--btn-danger-light);
}

/* ===== BADGES & TAGS (LEGACY PORT) ===== */

/* Tag Pill Badge (Added Tags) */
.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  background: var(--btn-success-light);
  color: var(--btn-success-base);
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.2s ease;
  box-shadow: none;
  user-select: none;
  border: 1px solid rgba(56, 142, 60, 0.2);
  cursor: default;
}

.tag-pill:hover {
  background: var(--btn-success-base);
  color: white;
  border-color: var(--btn-success-base);
  /* transform: translateY(-1px); Removed as per user request */
}

.tag-pill-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  margin-left: 4px;
  font-size: 14px;
  transition: background 0.2s;
  background: rgba(56, 142, 60, 0.2); /* Dark circle by default */
  color: var(--btn-success-base);
}

.tag-pill:hover .tag-pill-remove {
  color: white;
  background: rgba(255, 255, 255, 0.4); /* Lighter circle on hover */
}

/* Button-in-button hover effect */
.tag-pill:hover .tag-pill-remove:hover {
  background: white;
  color: var(--btn-success-base);
  opacity: 1;
}

.tag-pill-remove:hover {
  /* This base rule is overridden by the more specific one above when badge is hovered */
  background: rgba(0, 0, 0, 0.1);
}

/* Popular Tag Pill (Suggestions) */
.popular-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  background: #f1f5f9; /* Slate 100 */
  color: #475569; /* Slate 600 */
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid #e2e8f0; /* Slate 200 */
  cursor: pointer;
  font-family: inherit;
}

.popular-tag-pill:hover {
  background: #e2e8f0; /* Slate 200 */
  color: #1e293b; /* Slate 800 */
  border-color: #cbd5e1;
}

.popular-tag-pill .material-symbols-outlined {
  font-size: 14px;
  color: #94a3b8; /* Slate 400 */
}

.popular-tag-pill:hover .material-symbols-outlined {
  color: #475569;
}

/* Person Pill Badge (Green Variant - matching tags) */
/* Pill Icon (Generic for all tags) */
.tag-pill .pill-icon {
  font-size: 18px;
  margin-right: 4px;
  display: flex;
  align-items: center;
  color: inherit; /* Behave like text */
}

/* Ensure hover state matches standard tag behavior but covers icon */
.tag-pill:hover .pill-icon {
  color: white;
}

.tag-pill-text {
  user-select: none;
  line-height: 1;
}

.tag-pill-remove .material-symbols-outlined {
  font-size: 14px !important;
  font-weight: bold;
}

/* Checkbox Label Alignment */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  border: 1px solid;
}

.alert-info {
  background-color: #e3f2fd;
  color: #0277bd;
  border-color: #0288d1;
}

.alert-success {
  background-color: #e8f5e9;
  color: #2e7d32;
  border-color: #388e3c;
}

.alert-danger {
  background-color: #ffebee;
  color: #c62828;
  border-color: #d32f2f;
}

.alert-warning {
  background-color: #fff3e0;
  color: #e65100;
  border-color: #f57c00;
}

/* ===== COLOR SWATCHES (Style Guide) ===== */
.grid-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.color-swatch {
  padding: 40px 20px;
  border-radius: 8px;
  text-align: center;
  font-weight: 500;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
