/* ==========================================================================
   CRM Design System — base.css
   Comprehensive design tokens, layout, and component library
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design Tokens
   -------------------------------------------------------------------------- */
:root {
  /* Brand colors */
  --color-primary: #4a90d9;
  --color-primary-hover: #357abd;
  --color-secondary: #6c757d;
  --color-info: #17a2b8;

  /* Status colors */
  --color-success: #28a745;
  --color-error: #dc3545;
  --color-warning: #ffc107;

  /* Surface & text */
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-text: #333333;
  --color-text-muted: #6c757d;
  --color-border: #dee2e6;

  /* Sidebar */
  --color-sidebar-bg: #1a202c;
  --color-sidebar-text: #e2e8f0;
  --color-sidebar-hover: #2d3748;
  --color-sidebar-active: #4a90d9;
  --sidebar-width: 240px;

  /* Shared */
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  min-height: 100vh;
}

/* --------------------------------------------------------------------------
   3. Sidebar Navigation (dark theme)
   -------------------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  padding: 1.5rem 0;
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
  font-size: 1.25rem;
  color: #ffffff;
  font-weight: 700;
}

.nav-section {
  padding: 0.75rem 0 0.25rem;
}

.nav-section-label {
  display: block;
  padding: 0 1.5rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(226, 232, 240, 0.45);
}

.nav-links {
  list-style: none;
  padding: 0.5rem 0;
}

.nav-links li a {
  display: flex;
  align-items: center;
  padding: 0.6rem 1.5rem;
  color: var(--color-sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
}

.nav-links li a:hover {
  background: var(--color-sidebar-hover);
  color: #ffffff;
}

.nav-links li a.active {
  color: #ffffff;
  font-weight: 600;
  background: var(--color-sidebar-hover);
  border-left: 3px solid var(--color-sidebar-active);
  padding-left: calc(1.5rem - 3px);
}

.nav-icon {
  width: 18px;
  height: 18px;
  margin-right: 0.5rem;
  vertical-align: middle;
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   4. Main Content
   -------------------------------------------------------------------------- */
.content {
  margin-left: var(--sidebar-width);
  padding: 2rem;
  flex: 1;
  width: calc(100% - var(--sidebar-width));
}

/* --------------------------------------------------------------------------
   5. Flash Messages
   -------------------------------------------------------------------------- */
.flash-message {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flash-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.flash-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.flash-warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.flash-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
}

.flash-close:hover {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   6. Auth Forms
   -------------------------------------------------------------------------- */
.auth-container {
  max-width: 400px;
  margin: 2rem auto;
}

.auth-form {
  background: var(--color-surface);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-link {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.auth-link a {
  color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   7. Form Groups & Layout
   -------------------------------------------------------------------------- */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.15);
}

.password-wrapper {
  display: flex;
  gap: 0.5rem;
}

.password-wrapper input {
  flex: 1;
}

.toggle-password {
  padding: 0.5rem 0.75rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* --------------------------------------------------------------------------
   8. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-secondary);
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-success {
  background: var(--color-success);
  color: white;
}

.btn-success:hover {
  background: #218838;
}

.btn-danger {
  background: var(--color-error);
  color: white;
}

.btn-danger:hover {
  background: #c82333;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
}

.btn-outline:hover {
  background: var(--color-primary);
  color: white;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

/* --------------------------------------------------------------------------
   9. Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  line-height: 1.4;
}

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

.badge-success {
  background: #28a745;
}

.badge-warning {
  background: #ffc107;
  color: #333333;
}

.badge-danger {
  background: #dc3545;
}

.badge-info {
  background: #17a2b8;
}

.badge-muted {
  background: #6c757d;
}

/* --------------------------------------------------------------------------
   10. Data Table
   -------------------------------------------------------------------------- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

.data-table th {
  background: var(--color-bg);
  font-weight: 600;
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.9rem;
}

.data-table tr:hover td {
  background: #f1f3f5;
}

.data-table th[data-sort] {
  cursor: pointer;
}

.sort-asc::after {
  content: " \2191";
}

.sort-desc::after {
  content: " \2193";
}

/* --------------------------------------------------------------------------
   11. Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
}

.card-body {
  padding: 1.25rem;
}

/* --------------------------------------------------------------------------
   12. Stats Grid
   -------------------------------------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--color-primary);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   13. Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1rem;
}

.tab {
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--color-text-muted);
  font-weight: 500;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-size: 0.9rem;
  transition: color var(--transition), border-color var(--transition);
}

.tab:hover {
  color: var(--color-text);
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* --------------------------------------------------------------------------
   14. Filter Bar
   -------------------------------------------------------------------------- */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.filter-bar input:focus,
.filter-bar select:focus {
  border-color: var(--color-primary);
  outline: none;
}

/* --------------------------------------------------------------------------
   15. Pagination
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  gap: 0.25rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.pagination a,
.pagination span {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  text-decoration: none;
  color: var(--color-text);
}

.pagination a:hover {
  background: var(--color-bg);
}

.pagination .active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* --------------------------------------------------------------------------
   16. Page Header
   -------------------------------------------------------------------------- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.page-header .actions {
  display: flex;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   17. Detail Header
   -------------------------------------------------------------------------- */
.detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.detail-header h1 {
  font-size: 1.5rem;
  margin: 0;
}

.detail-header .badges {
  display: flex;
  gap: 0.5rem;
}

.detail-header .actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   18. Empty State
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  opacity: 0.4;
  margin-bottom: 1rem;
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.empty-state p {
  margin-bottom: 1rem;
}

/* --------------------------------------------------------------------------
   19. Utility Classes
   -------------------------------------------------------------------------- */

/* Headings */
h1 {
  margin-bottom: 1rem;
}

/* Code */
code {
  background: var(--color-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* Text helpers */
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger { color: var(--color-error); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* Spacing */
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* Flex */
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Visibility */
.hidden { display: none; }
