/* =========================================================
   REVY AI CRM — Design System & Stylesheet
   Modern, Light, Spacious & Premium Aesthetic
   Inspired by Linear, Stripe Dashboard, and OpenAI
   ========================================================= */

:root {
  /* Brand Palette */
  --primary: #4AA8E8;
  --secondary: #3D72D8;
  --accent-cyan: #5CCFD2;
  --accent-purple: #6651B8;

  /* Neutral Surface & Backgrounds */
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-hover: #F1F5F9;
  --border: #E5E7EB;
  --border-focus: #4AA8E8;

  /* Text Colors */
  --text-main: #111827;
  --text-muted: #6B7280;
  --text-disabled: #9CA3AF;

  /* Status Colors */
  --success: #22C55E;
  --success-bg: rgba(34, 197, 94, 0.08);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.08);
  --error: #EF4444;
  --error-bg: rgba(239, 68, 68, 0.08);
  --info: #3B82F6;
  --info-bg: rgba(59, 130, 246, 0.08);

  /* Signature Gradient */
  --gradient-logo: linear-gradient(90deg, #6651B8 0%, #4AA8E8 50%, #5CCFD2 100%);
  --gradient-subtle: linear-gradient(135deg, rgba(102, 81, 184, 0.05) 0%, rgba(74, 168, 232, 0.05) 100%);

  /* Typography */
  --font-heading: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Component Layout */
  --sidebar-w: 250px;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 20px;
  --shadow-card: 0 4px 20px -2px rgba(15, 23, 42, 0.05), 0 2px 6px -1px rgba(15, 23, 42, 0.03);
  --shadow-hover: 0 8px 24px -4px rgba(15, 23, 42, 0.08), 0 4px 12px -2px rgba(15, 23, 42, 0.04);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--secondary);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-main);
  margin: 0 0 6px;
  letter-spacing: -0.015em;
}

.mono {
  font-family: monospace;
  font-size: 0.9em;
}

::selection {
  background: rgba(74, 168, 232, 0.2);
  color: var(--text-main);
}

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

/* =========================================================
   APP LAYOUT & SHELL
   ========================================================= */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 26px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.brand-logo-img {
  height: 38px;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
}

.brand-logo-img.large {
  height: 64px;
  margin: 0 auto 16px;
  display: block;
}

.brand-icon-wrapper {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gradient-logo);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(102, 81, 184, 0.25);
  flex-shrink: 0;
}

.brand-icon-wrapper.large {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin: 0 auto 14px;
}

.brand-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 17px;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-ai-badge {
  background: var(--gradient-logo);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-disabled);
  font-weight: 600;
  padding: 16px 12px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  transition: all 0.15s ease;
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text-main);
}

.nav-link.active {
  background: rgba(74, 168, 232, 0.08);
  color: var(--secondary);
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke-width: 2;
  color: var(--text-muted);
}

.nav-link.active .nav-icon {
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gradient-logo);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  truncate: true;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.logout-link {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 8px;
  text-align: center;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, color 0.15s ease;
}

.logout-link:hover {
  background: var(--error-bg);
  color: var(--error);
}

.main {
  padding: 32px 40px 60px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 20px;
  flex-wrap: wrap;
}

.page-eyebrow {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-purple);
  margin-bottom: 4px;
}

.page-head h1 {
  font-size: 28px;
  letter-spacing: -0.02em;
}

.page-desc {
  color: var(--text-muted);
  font-size: 14px;
}

/* =========================================================
   FLASH MESSAGES
   ========================================================= */

.flash-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}

.flash-success {
  background: var(--success-bg);
  border-color: rgba(34, 197, 94, 0.2);
  color: #15803D;
}

.flash-error {
  background: var(--error-bg);
  border-color: rgba(239, 68, 68, 0.2);
  color: #B91C1C;
}

.flash-warning {
  background: var(--warning-bg);
  border-color: rgba(245, 158, 11, 0.2);
  color: #B45309;
}

.flash-info {
  background: var(--info-bg);
  border-color: rgba(59, 130, 246, 0.2);
  color: #1D4ED8;
}

/* =========================================================
   CARDS & STATS
   ========================================================= */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s ease;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--dot, var(--primary));
}

.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-value {
  font-family: var(--font-heading);
  font-size: 32px;
  font-weight: 700;
  color: var(--text-main);
}

.section-title {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title .count-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(74, 168, 232, 0.1);
  padding: 2px 10px;
  border-radius: 12px;
}

/* =========================================================
   5-DAY CALL RAIL (SIGNATURE CRM ELEMENT)
   ========================================================= */

.call-rail {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 32px;
}

.rail-col {
  border-radius: var(--radius);
  padding: 16px 14px;
  min-height: 120px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail-col-head {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.rail-col.is-overdue {
  border-color: rgba(239, 68, 68, 0.3);
  background: linear-gradient(180deg, var(--error-bg), var(--surface) 60%);
}
.rail-col.is-overdue .rail-col-head {
  color: var(--error);
}

.rail-col.is-today {
  border-color: var(--primary);
  background: linear-gradient(180deg, rgba(74, 168, 232, 0.08), var(--surface) 65%);
  box-shadow: 0 0 0 2px rgba(74, 168, 232, 0.15), var(--shadow-card);
}
.rail-col.is-today .rail-col-head {
  color: var(--secondary);
}

.rail-col.is-upcoming {
  opacity: 0.9;
}

.rail-item {
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.rail-item:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.rail-item-name {
  font-weight: 600;
  color: var(--text-main);
}

.rail-item-phone {
  font-size: 11px;
  color: var(--text-muted);
}

.rail-empty {
  font-size: 12px;
  color: var(--text-disabled);
  font-style: italic;
  padding-top: 8px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-block;
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 168, 232, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(74, 168, 232, 0); }
}

/* =========================================================
   TABLES
   ========================================================= */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  margin-bottom: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-main);
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-hover);
}

.cell-phone {
  font-family: var(--font-body);
  color: var(--text-muted);
}

/* =========================================================
   BADGES & PILLS
   ========================================================= */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.pill-new { background: #F1F5F9; color: #475569; }
.pill-new::before { background: #64748B; }

.pill-contacted { background: rgba(74, 168, 232, 0.12); color: #0284C7; }
.pill-contacted::before { background: #0284C7; }

.pill-interested { background: var(--warning-bg); color: #D97706; }
.pill-interested::before { background: #D97706; }

.pill-closed_won { background: var(--success-bg); color: #16A34A; }
.pill-closed_won::before { background: #16A34A; }

.pill-closed_lost { background: var(--error-bg); color: #DC2626; }
.pill-closed_lost::before { background: #DC2626; }

.pill-pending { background: var(--warning-bg); color: #D97706; }
.pill-pending::before { background: #D97706; }

.pill-approved { background: var(--success-bg); color: #16A34A; }
.pill-approved::before { background: #16A34A; }

.pill-rejected { background: var(--error-bg); color: #DC2626; }
.pill-rejected::before { background: #DC2626; }

/* =========================================================
   BUTTONS & FORMS
   ========================================================= */

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

input[type="text"], input[type="password"], input[type="date"], input[type="file"],
select, textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font-body);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 168, 232, 0.2);
}

.field {
  margin-bottom: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn:active {
  transform: translateY(1px);
}

/* Primary Button Spec: Background #4AA8E8, Hover #3D72D8, Text White */
.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
}

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

/* Secondary Button Spec: Background White, Border #4AA8E8, Text #4AA8E8 */
.btn-secondary {
  background: #FFFFFF;
  border: 1px solid var(--primary);
  color: var(--primary);
}

.btn-secondary:hover {
  background: rgba(74, 168, 232, 0.08);
  color: var(--secondary);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text-main);
}

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

.btn-success:hover {
  background: #16A34A;
}

.btn-danger {
  background: #FFFFFF;
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--error);
}

.btn-danger:hover {
  background: var(--error-bg);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: 6px;
}

.form-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}

/* =========================================================
   PAGINATION CONTROL
   ========================================================= */

.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
  box-shadow: var(--shadow-card);
  flex-wrap: wrap;
  gap: 12px;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-muted);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.page-link:hover:not(.disabled):not(.active) {
  background: var(--surface-hover);
  border-color: var(--primary);
  color: var(--primary);
}

.page-link.active {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
  font-weight: 600;
}

.page-link.disabled {
  color: var(--text-disabled);
  background: var(--bg);
  border-color: var(--border);
  cursor: not-allowed;
}

.page-link.ellipsis {
  border: none;
  background: transparent;
  color: var(--text-muted);
}

/* =========================================================
   AUTHENTICATION PAGE
   ========================================================= */

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  background-image: radial-gradient(circle at 50% 0%, rgba(102, 81, 184, 0.08), transparent 50%),
                    radial-gradient(circle at 100% 100%, rgba(92, 207, 210, 0.08), transparent 50%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 38px 34px;
  box-shadow: 0 20px 40px -15px rgba(15, 23, 42, 0.08);
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}

.login-brand h1 {
  font-size: 22px;
  margin-bottom: 2px;
}

.login-brand p {
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.06em;
}

.login-hint {
  margin-top: 22px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* =========================================================
   EMPTY STATES & DETAILS
   ========================================================= */

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state strong {
  color: var(--text-main);
  display: block;
  margin-bottom: 6px;
  font-family: var(--font-heading);
  font-size: 16px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.timeline-item {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  border-left: 4px solid var(--border);
  box-shadow: var(--shadow-card);
}

.timeline-item.pending { border-left-color: var(--warning); }
.timeline-item.approved { border-left-color: var(--success); }
.timeline-item.rejected { border-left-color: var(--error); }

.timeline-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .call-rail { grid-template-columns: repeat(3, 1fr); }
  .profile-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .main { padding: 20px; }
  .call-rail { grid-template-columns: repeat(2, 1fr); }
}