/* ============================================
   THEME.CSS — Variables, Base, Layout
   Modern SaaS Ticket System Design
   ============================================ */

/* ============================================
   CSS Custom Properties
   ============================================ */

:root {
  /* Brand / Primary */
  --primary:           #5B5BD6;
  --primary-dark:      #4646BC;
  --primary-light:     #7B7BE8;
  --primary-bg:        rgba(91, 91, 214, 0.08);
  --primary-bg-hover:  rgba(91, 91, 214, 0.12);

  /* Surface */
  --bg:                #F8FAFC;
  --surface:           #FFFFFF;
  --surface-raised:    #F1F5F9;
  --border:            #E2E8F0;
  --border-light:      #F1F5F9;

  /* Text */
  --text:              #0F172A;
  --text-secondary:    #64748B;
  --text-tertiary:     #94A3B8;

  /* Status */
  --status-open:            #2563EB;
  --status-open-bg:         #EFF6FF;
  --status-in-progress:     #D97706;
  --status-in-progress-bg:  #FFFBEB;
  --status-on-hold:         #7C3AED;
  --status-on-hold-bg:      #F5F3FF;
  --status-resolved:        #059669;
  --status-resolved-bg:     #ECFDF5;
  --status-closed:          #6B7280;
  --status-closed-bg:       #F9FAFB;

  /* Priority */
  --priority-low:           #059669;
  --priority-low-bg:        #ECFDF5;
  --priority-medium:        #D97706;
  --priority-medium-bg:     #FFFBEB;
  --priority-high:          #DC2626;
  --priority-high-bg:       #FEF2F2;
  --priority-critical:      #991B1B;
  --priority-critical-bg:   #FEF2F2;

  /* Danger */
  --danger:     #DC2626;
  --danger-bg:  #FEF2F2;

  /* Sidebar */
  --sidebar-bg:              #111827;
  --sidebar-text:            #F9FAFB;
  --sidebar-text-secondary:  #9CA3AF;
  --sidebar-hover:           rgba(255, 255, 255, 0.07);
  --sidebar-active:          rgba(255, 255, 255, 0.13);
  --sidebar-active-text:     #FFFFFF;
  --sidebar-border:          rgba(255, 255, 255, 0.08);
  --sidebar-width:           240px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.07), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.10), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  --font-mono:   'JetBrains Mono', 'Menlo', 'Monaco', 'Courier New', monospace;

  /* Transitions */
  --transition-fast:  120ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base:  200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow:  350ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Radius */
  --radius-xs:   4px;
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* Aliases for backward compat */
  --color-primary:          var(--primary);
  --color-primary-dark:     var(--primary-dark);
  --color-primary-light:    var(--primary-light);
  --color-bg:               var(--bg);
  --color-bg-secondary:     var(--surface-raised);
  --color-bg-tertiary:      #E8EDF3;
  --color-text:             var(--text);
  --color-text-secondary:   var(--text-secondary);
  --color-text-tertiary:    var(--text-tertiary);
  --color-border:           var(--border);
  --color-border-light:     var(--border-light);
  --gradient-primary:       linear-gradient(135deg, var(--primary), var(--primary-dark));
}

/* ============================================
   Dark Mode
   ============================================ */

[data-theme="dark"] {
  --bg:                #0D1117;
  --surface:           #161B22;
  --surface-raised:    #1E242D;
  --border:            #30363D;
  --border-light:      #21262D;

  --text:              #E6EDF3;
  --text-secondary:    #8B949E;
  --text-tertiary:     #484F58;

  --sidebar-bg:        #0B0D12;
  --sidebar-text:      #E6EDF3;
  --sidebar-text-secondary: #6E7681;
  --sidebar-hover:     rgba(255, 255, 255, 0.06);
  --sidebar-active:    rgba(255, 255, 255, 0.11);
  --sidebar-border:    rgba(255, 255, 255, 0.07);

  --status-open-bg:          rgba(37, 99, 235, 0.15);
  --status-in-progress-bg:   rgba(217, 119, 6, 0.15);
  --status-on-hold-bg:       rgba(124, 58, 237, 0.15);
  --status-resolved-bg:      rgba(5, 150, 105, 0.15);
  --status-closed-bg:        rgba(107, 114, 128, 0.12);
  --priority-low-bg:         rgba(5, 150, 105, 0.15);
  --priority-medium-bg:      rgba(217, 119, 6, 0.15);
  --priority-high-bg:        rgba(220, 38, 38, 0.15);
  --priority-critical-bg:    rgba(153, 27, 27, 0.15);
  --danger-bg:               rgba(220, 38, 38, 0.15);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.40);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.50), 0 1px 2px rgba(0, 0, 0, 0.40);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.50);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.60);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.70);

  /* Aliases */
  --color-primary:          var(--primary-light);
  --color-bg:               var(--bg);
  --color-bg-secondary:     var(--surface-raised);
  --color-bg-tertiary:      #252B35;
  --color-text:             var(--text);
  --color-text-secondary:   var(--text-secondary);
  --color-text-tertiary:    var(--text-tertiary);
  --color-border:           var(--border);
  --color-border-light:     var(--border-light);
  --gradient-primary:       linear-gradient(135deg, var(--primary-light), var(--primary));
}

/* ============================================
   Base Reset
   ============================================ */

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

html {
  font-family: var(--font-family);
  font-size: 14px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color var(--transition-base), color var(--transition-base);
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================
   App Layout
   ============================================ */

.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 100;
  border-right: 1px solid var(--sidebar-border);
  transition: transform var(--transition-base), width var(--transition-base);
}

.sidebar.collapsed {
  width: 60px;
}

.sidebar.no-transition,
.sidebar.no-transition ~ .main-wrapper {
  transition: none !important;
}

.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .sidebar-link span:last-child,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-user-info {
  display: none;
}

.sidebar.collapsed .sidebar-user {
  justify-content: center;
}

.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: 10px;
}

.sidebar.collapsed .sidebar-link-icon {
  margin: 0;
}

.sidebar.collapsed .sidebar-footer {
  padding: 10px 6px;
}

.sidebar.collapsed .sidebar-footer-actions {
  flex-direction: column;
}

.sidebar.collapsed .sidebar-collapse i {
  transform: rotate(180deg);
}

/* Sidebar Nav */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-section-title {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--sidebar-text-secondary);
  padding: 0 10px;
  margin-bottom: 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition-fast);
  margin-bottom: 1px;
  cursor: pointer;
}

.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.sidebar-link-icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  font-size: 14px;
  opacity: 0.85;
}

.sidebar-link.active .sidebar-link-icon {
  opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  margin-bottom: 8px;
  overflow: hidden;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--sidebar-text-secondary);
}

.sidebar-footer-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sidebar-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--sidebar-text-secondary);
  cursor: pointer;
  font-size: 14px;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.sidebar-action-btn:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

.sidebar-collapse {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--sidebar-text-secondary);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.sidebar-collapse:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

@media (min-width: 1025px) {
  .sidebar-collapse {
    display: flex;
  }
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--sidebar-text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.sidebar-close:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
}

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ============================================
   Main Wrapper
   ============================================ */

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-base);
}

.sidebar.collapsed ~ .main-wrapper {
  margin-left: 60px;
}

/* ============================================
   Topbar
   ============================================ */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: 52px;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.topbar-actions {
  flex-shrink: 0;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-version {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
}

.topbar-action-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.topbar-action-btn:hover {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--text-tertiary);
}

/* Search */
.topbar-search-wrapper {
  flex: 0 1 380px;
  min-width: 0;
}

.topbar-search-container {
  position: relative;
}

.topbar-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 13px;
  pointer-events: none;
}

.topbar-search-container .topbar-search-input {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 32px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  font-family: var(--font-family);
  transition: all var(--transition-fast);
}

.topbar-search-input::placeholder {
  color: var(--text-tertiary);
}

.topbar-search-input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.topbar-search-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  max-height: 360px;
  overflow-y: auto;
}

/* Notifications */
.topbar-notification-container {
  position: relative;
}

.topbar-notification-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--danger);
  color: white;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-notification-badge.hidden {
  display: none;
}

.topbar-notification-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
}

.topbar-notification-menu.hidden {
  display: none;
}

.topbar-notification-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.topbar-notification-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.topbar-notification-list {
  max-height: 300px;
  overflow-y: auto;
}

.topbar-notification-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.topbar-notification-link {
  font-size: 12px;
  color: var(--primary);
  font-weight: 500;
}

/* Burger */
.burger-btn {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.burger-line {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: all var(--transition-fast);
}

/* ============================================
   Messages / Toasts
   ============================================ */

.messages-container {
  padding: 12px 24px 0;
}

.message-toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  animation: fadeInDown var(--transition-base) ease-out;
}

.message-toast.success {
  background: var(--status-resolved-bg);
  border-color: var(--status-resolved);
  color: var(--status-resolved);
}

.message-toast.error {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.message-toast.warning {
  background: var(--status-in-progress-bg);
  border-color: var(--status-in-progress);
  color: var(--status-in-progress);
}

.message-toast.info {
  background: var(--status-open-bg);
  border-color: var(--status-open);
  color: var(--status-open);
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
  flex: 1;
  padding: 28px 32px;
}

/* ============================================
   Native Form Elements (Django auto-generated)
   ============================================ */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
textarea,
select {
  font-family: var(--font-family);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover,
input[type="search"]:hover,
input[type="url"]:hover,
input[type="number"]:hover,
textarea:hover,
select:hover {
  border-color: var(--text-tertiary);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

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

@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: block;
  }

  .sidebar-collapse {
    display: none;
  }

  .main-wrapper {
    margin-left: 0 !important;
  }

  .burger-btn {
    display: flex;
  }

  .main-content {
    padding: 20px;
  }
}

@media (max-width: 640px) {
  .main-content {
    padding: 16px;
  }

  .topbar {
    padding: 10px 16px;
  }
}
