/* ========================================
   CORE BASE STYLES
   ======================================== */

:root {
  --radius: 8px;
  --radius-lg: 12px;
  --transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  /* Modern Light Theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --primary: #6366f1;
  --primary-hover: #5b5ef7;
  --primary-light: rgba(99, 102, 241, 0.05);
  --accent: #10b981;
  --accent-light: rgba(16, 185, 129, 0.05);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.05);
  --warning: #f59e0b;
  --warning-light: rgba(245, 158, 11, 0.05);
  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  /* Modern Dark Theme */
  --bg-primary: #0a0b0f;
  --bg-secondary: #12141a;
  --bg-tertiary: #1a1d26;
  --surface: #1e2128;
  --surface-hover: #252832;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --primary: #6366f1;
  --primary-hover: #5b5ef7;
  --primary-light: rgba(99, 102, 241, 0.1);
  --accent: #10b981;
  --accent-light: rgba(16, 185, 129, 0.1);
  --danger: #f87171;
  --danger-light: rgba(248, 113, 113, 0.1);
  --warning: #fbbf24;
  --warning-light: rgba(251, 191, 36, 0.1);
  --border: #2d3748;
  --border-light: #374151;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* ========================================
   RESET & BASE STYLES
   ======================================== */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-weight: 400;
  line-height: 1.6;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   LAYOUT SYSTEM
   ======================================== */

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 100vh;
  transition: var(--transition);
}

.main.full-width {
  background: var(--bg-primary);
  margin-left: 0;
}

.main {
  display: grid;
  grid-template-rows: 72px 1fr;
  min-width: 0;
  background: var(--bg-secondary);
  margin-left: 280px;
}

.content {
  padding: 32px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ========================================
   SIDEBAR COMPONENT
   ======================================== */

.sidebar {
  position: fixed;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  backdrop-filter: blur(20px);
  transition: var(--transition);
  left: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  z-index: 99;
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
  opacity: 0.7;
  z-index: -1;
}

.sidebar-toggle {
  position: absolute;
  right: 20px;
  top: 24px;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface-hover);
  border-radius: var(--radius);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: var(--transition);
}

.sidebar-toggle:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* ========================================
   BRAND COMPONENT
   ======================================== */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 32px;
  transition: var(--transition);
}

.brand:hover {
  transform: translateY(-1px);
}

.brand-logo {
  display: inline-block;
  width: 36px;
  height: 36px;
}

.brand-mark:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-xl);
}

.brand-text {
  font-size: 18px;
  font-weight: 600;
}

/* ========================================
   NAVIGATION COMPONENT
   ======================================== */

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.nav-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--primary);
  transform: scaleY(0);
  transition: var(--transition);
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  transform: translateX(4px);
}

.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.nav-link.active::before {
  transform: scaleY(1);
}

/* ========================================
   TOPBAR COMPONENT
   ======================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

/* ========================================
   FLASH MESSAGES
   ======================================== */

.flash-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.flash-group:empty {
  display: none;
}

.flash {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-weight: 500;
  position: relative;
  overflow: hidden;
  animation: slideIn 0.3s ease-out;
  padding-right: 44px;
}

.flash::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: currentColor;
}

.flash .flash-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  transition: var(--transition);
}

.flash .flash-close:hover {
  opacity: 1;
  background: var(--surface-hover);
}

.flash.success {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.flash.error {
  background: var(--danger-light);
  color: var(--danger);
  border-color: var(--danger);
}

.flash.warning {
  background: var(--warning-light);
  color: var(--warning);
  border-color: var(--warning);
}

@keyframes slideIn {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ========================================
   FORM COMPONENTS
   ======================================== */

.form {
  display: grid;
  gap: 20px;
}

.field {
  display: grid;
  gap: 8px;
}

label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.025em;
}

input,
textarea,
select {
  width: 100%;
  padding: 14px 16px;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-size: 14px;
  font-weight: 400;
  transition: var(--transition);
  font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: var(--surface);
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--border-light);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

.hint {
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.4;
}

/* ========================================
   CARD COMPONENT
   ======================================== */

.card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-light), transparent);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-light);
}

.card-title {
  margin: 0 0 20px;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card .top-actions {
  margin-top: -50px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.card-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin: -8px 0 20px 0;
  font-weight: 400;
}

/* ========================================
   GRID SYSTEM
   ======================================== */

.grid.two {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}

.grid.three {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 24px;
}

/* ========================================
   BUTTON COMPONENT
   ======================================== */

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  justify-content: right;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  background: var(--surface-hover);
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transition: left 0.5s;
}

.button:hover::before {
  left: 100%;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.button.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}

.button.primary:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-secondary);
}

.button.ghost:hover {
  background: var(--surface-hover);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.button.small {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
}

.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ========================================
   ICON BUTTON COMPONENT
   ======================================== */

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: transparent;
  border: none;
}

.icon-button:hover {
  background: var(--surface-hover);
}

.icon-button:active {
  background: var(--surface-active);
}

.icon-button:focus {
  outline: none;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.gap-4 {
  gap: 32px;
}

a {
  color: var(--text-primary);
}

.list {
  list-style-type: none;
  padding-left: 0;
}

/* ========================================
   THEME TOGGLE
   ======================================== */

.theme-toggle {
  position: relative;
}

.theme-icon {
  transition: var(--transition);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.theme-icon-sun {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}

.theme-icon-moon {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(180deg) scale(0.8);
}

[data-theme="light"] .theme-icon-sun {
  opacity: 0;
  transform: translate(-50%, -50%) rotate(-180deg) scale(0.8);
}

[data-theme="light"] .theme-icon-moon {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(0deg) scale(1);
}

/* ========================================
   LOADING STATES
   ======================================== */

.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========================================
   PAGE LOADER
   ======================================== */

.page-loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s ease-out, visibility 0.3s ease-out;
}

.page-loader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: loaderSpin 1s linear infinite;
  margin-bottom: 20px;
}

.loader-text {
  color: var(--text-secondary);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.025em;
}

@keyframes loaderSpin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Hide main content while loading */
body.loading .app-shell {
  opacity: 0;
  visibility: hidden;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 1296px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-210px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    box-shadow: var(--shadow-xl);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: flex;
  }

  .main {
    margin-left: 0;
  }

  .sidebar .nav:not(.sidebar.open .nav) {
    display: none;
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

  .content {
    padding: 20px;
    padding-left: 90px;
  }

  .topbar {
    padding: 12px 20px;
  }
}

.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.sidebar.open~.sidebar-backdrop {
  opacity: 1;
  visibility: visible;
}

/* ========================================
   SESSION SECURITY MODALS
   ======================================== */

.session-warning-modal,
.session-expired-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.session-warning-modal .modal-backdrop,
.session-expired-modal .modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.session-warning-modal .modal-content,
.session-expired-modal .modal-content {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  text-align: center;
}

.session-warning-modal h3,
.session-expired-modal h3 {
  margin: 0 0 16px 0;
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 600;
}

.session-warning-modal p,
.session-expired-modal p {
  margin: 0 0 24px 0;
  color: var(--text-secondary);
  line-height: 1.5;
}

.session-warning-modal .modal-actions,
.session-expired-modal .modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.session-warning-modal .modal-actions .button,
.session-expired-modal .modal-actions .button {
  min-width: 120px;
}