:root {
  /* Typography */
  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  
  /* Layout Sizing */
  --sidebar-width: 260px;
  --header-height: 70px;
  
  /* Unified Professional Aesthetic */
  --bg-color: #f8fafc; /* Slate 50 background */
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  
  --text-primary: #0f172a; /* Slate 900 */
  --text-secondary: #64748b; /* Slate 500 */
  --sidebar-text: #475569; /* Slate 600 */
  --sidebar-text-hover: #0f172a;
  
  --border-color: #e2e8f0; /* Slate 200 */
  --sidebar-border: #e2e8f0;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --shadow-soft: 0 4px 20px rgba(0,0,0,0.03);
  
  --radius-sm: 0.375rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-full: 9999px;
  
  /* Standard Agency Accent Colors */
  --accent-color: #2563eb; /* Blue 600 */
  --accent-light: #eff6ff; /* Blue 50 */
  --success-color: #10b981; /* Emerald 500 */
  --danger-color: #ef4444; /* Red 500 */
  --warning-color: #f59e0b; /* Amber 500 */
}

/* Reset page-specific color overrides to enforce uniform professional palette */
body.theme-green, body.theme-warm, body.theme-blue, body.theme-purple, body.theme-beige, body.theme-mono {
  --accent-color: #2563eb; 
  --accent-light: #eff6ff;
}

/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px !important; /* Locks rem conversion to exactly 16px across all devices */
  -webkit-text-size-adjust: 100%; /* Prevents iOS/Android from automatically inflating font sizes */
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 100%;
  max-width: 100vw;
  position: relative;
  overflow-wrap: break-word; /* Prevents long numbers/strings from breaking grid structures */
}

/* Layout */
.app-container { display: flex; min-height: 100vh; }
.main-content {
  flex: 1; margin-left: var(--sidebar-width);
  min-width: 0; /* CRITICAL FIX: prevents flex children from blowing out layout past 100vw */
  transition: margin-left 0.3s ease; display: flex; flex-direction: column;
}

/* Header */
.top-header {
  height: 72px;
  background-color: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 2rem; position: sticky; top: 0; z-index: 40;
}
.header-left .page-title { font-size: 1.25rem; font-weight: 600; color: var(--text-primary); }
.header-right { display: flex; align-items: center; gap: 1rem; }
.user-profile { display: flex; align-items: center; gap: 0.75rem; }
.avatar {
  width: 40px; height: 40px; border-radius: var(--radius-full);
  background-color: var(--accent-light); color: var(--accent-color);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}

/* Content Area */
.dashboard-content { padding: 2rem; max-width: 1600px; margin: 0 auto; width: 100%; min-width: 0; }

/* Cards */
.card {
  background-color: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  transition: box-shadow 0.2s ease;
  min-width: 0; /* CRITICAL FIX: prevents chart canvases from blowing out card width */
  max-width: 100%;
}
.card:hover { box-shadow: var(--shadow-md); }

/* Grids */
.grid-cols-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.grid-cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.grid-cols-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.layout-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }

/* Responsive */
@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .layout-2-1 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app-container { flex-direction: column; }
  .main-content { margin-left: 0; }
  .sidebar { transform: translateX(-100%); width: 280px; }
  .sidebar.open { transform: translateX(0); }
  .grid-cols-4, .grid-cols-2, .grid-cols-3, .layout-2-1 { grid-template-columns: 1fr; }
  .dashboard-content { padding: 1rem; }
  .top-header { padding: 0.5rem 1rem; height: auto; min-height: 60px; flex-wrap: wrap; gap: 0.5rem; position: sticky; top: 0; z-index: 40; }
  .header-left .page-title { font-size: 1rem; line-height: 1.2; word-break: break-word; flex: 1; min-width: 100px; }
  .user-profile { gap: 0.5rem; }
  .avatar { width: 32px; height: 32px; font-size: 0.875rem; }
}

/* --- PREMIUM NOTIFICATIONS --- */
.notification-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 400px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  border-left: 4px solid var(--accent-color);
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  animation: toast-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.toast.toast-success { border-left-color: var(--success-color); }
.toast.toast-error { border-left-color: var(--danger-color); }
.toast.toast-warning { border-left-color: var(--warning-color); }

.toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.toast.toast-success i { color: var(--success-color); }
.toast.toast-error i { color: var(--danger-color); }
.toast.toast-warning i { color: var(--warning-color); }

.toast-message {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

@keyframes toast-in {
  to { transform: translateX(0); }
}

@keyframes toast-out {
  to { transform: translateX(130%); opacity: 0; }
}

/* --- ACTION BUTTONS --- */
.btn-action {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  background: white;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 1.1rem;
}

.btn-action:hover {
  background: var(--accent-light);
  color: var(--accent-color);
  border-color: var(--accent-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.btn-action.btn-delete:hover {
  background: #fee2e2;
  color: var(--danger-color);
  border-color: var(--danger-color);
}
/* --- PREMIUM CUSTOM SELECTS --- */
.custom-select-container {
  position: relative;
  width: 100%;
  font-family: var(--font-family);
  user-select: none;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-select-trigger:hover {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.custom-select-trigger i {
  font-size: 1rem;
  color: var(--text-secondary);
  transition: transform 0.3s ease;
}

.custom-select-container.open .custom-select-trigger i {
  transform: rotate(180deg);
}

.custom-select-options {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 15px 30px -10px rgba(0,0,0,0.15);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  max-height: 250px;
  overflow-y: auto;
  padding: 0.5rem;
}

.custom-select-container.open .custom-select-options {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.custom-option {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.custom-option:hover {
  background: var(--accent-light);
  color: var(--accent-color);
}

.custom-option.selected {
  background: var(--accent-color);
  color: #ffffff;
}

/* Scrollbar for options */
.custom-select-options::-webkit-scrollbar {
  width: 6px;
}
.custom-select-options::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 10px;
}

/* --- PROFESSIONAL FORM CONTROLS --- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  letter-spacing: 0.025em;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  font-family: var(--font-family);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  outline: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-control:hover {
  border-color: #cbd5e1;
}

.form-control:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: #ffffff;
}

.form-control::placeholder {
  color: #94a3b8;
  font-weight: 400;
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
  line-height: 1.5;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19.5 8.25l-7.5 7.5-7.5-7.5' /%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1.25rem;
  padding-right: 2.5rem;
}
