/* ============================================
   QAMIRI AUDITORIA - Premium Theme
   Modern UI with Glassmorphism & Animations
   Light/Dark Mode Support with Orange Palette
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* ============================================
   THEME VARIABLES
   ============================================ */

/* Light Theme (Default) */
:root {
  /* Background Colors */
  --bg-primary: #faf8f6;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f5f0eb;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 0.95);

  /* Text Colors */
  --text-primary: #1a1410;
  --text-secondary: #4a403a;
  --text-muted: #8a7c74;

  /* Orange Accent Palette based on #B55527 */
  --accent-primary: #B55527;
  --accent-secondary: #D9763A;
  --accent-light: #E8956B;
  --accent-dark: #8C4420;
  --accent-gradient: linear-gradient(135deg, #B55527, #D9763A);
  --accent-gradient-hover: linear-gradient(135deg, #D9763A, #E8956B);
  --accent-glow: rgba(181, 85, 39, 0.35);
  --accent-soft: rgba(181, 85, 39, 0.1);

  /* Status Colors */
  --success: #2d8a5f;
  --success-soft: rgba(45, 138, 95, 0.12);
  --success-glow: rgba(45, 138, 95, 0.35);
  --danger: #c23a38;
  --danger-soft: rgba(194, 58, 56, 0.12);
  --danger-glow: rgba(194, 58, 56, 0.35);
  --warning: #c9820f;
  --warning-soft: rgba(201, 130, 15, 0.12);
  --neutral: rgba(138, 124, 116, 0.12);

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.75);
  --glass-border: rgba(181, 85, 39, 0.12);
  --glass-shadow: 0 8px 32px rgba(26, 20, 16, 0.1);
  --glass-blur: blur(20px);

  /* Borders & Shadows */
  --border-color: rgba(181, 85, 39, 0.15);
  --border-hover: rgba(181, 85, 39, 0.25);
  --shadow-sm: 0 4px 6px -1px rgba(26, 20, 16, 0.08);
  --shadow-md: 0 10px 25px -3px rgba(26, 20, 16, 0.1);
  --shadow-lg: 0 25px 50px -12px rgba(26, 20, 16, 0.15);
  --shadow-glow: 0 0 40px var(--accent-glow);

  /* Particles */
  --particle-1: var(--accent-primary);
  --particle-2: var(--accent-secondary);
  --particle-3: var(--success);

  /* Animations */
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Theme specific */
  --theme-icon-sun: 1;
  --theme-icon-moon: 0;
}

/* Dark Theme */
[data-theme="dark"] {
  /* Background Colors */
  --bg-primary: #0f0d0b;
  --bg-secondary: #1a1614;
  --bg-tertiary: #252019;
  --bg-card: rgba(37, 32, 25, 0.85);
  --bg-card-hover: rgba(37, 32, 25, 0.95);

  /* Text Colors */
  --text-primary: #faf8f6;
  --text-secondary: #c9bfb7;
  --text-muted: #8a7c74;

  /* Orange Accent Palette (adjusted for dark mode) */
  --accent-primary: #D9763A;
  --accent-secondary: #E8956B;
  --accent-light: #F0B08A;
  --accent-dark: #B55527;
  --accent-gradient: linear-gradient(135deg, #D9763A, #E8956B);
  --accent-gradient-hover: linear-gradient(135deg, #E8956B, #F0B08A);
  --accent-glow: rgba(217, 118, 58, 0.4);
  --accent-soft: rgba(217, 118, 58, 0.15);

  /* Status Colors (adjusted for dark mode) */
  --success: #3cb371;
  --success-soft: rgba(60, 179, 113, 0.15);
  --success-glow: rgba(60, 179, 113, 0.4);
  --danger: #e85450;
  --danger-soft: rgba(232, 84, 80, 0.15);
  --danger-glow: rgba(232, 84, 80, 0.4);
  --warning: #e5a020;
  --warning-soft: rgba(229, 160, 32, 0.15);
  --neutral: rgba(138, 124, 116, 0.2);

  /* Glassmorphism */
  --glass-bg: rgba(26, 22, 20, 0.85);
  --glass-border: rgba(217, 118, 58, 0.15);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

  /* Borders & Shadows */
  --border-color: rgba(217, 118, 58, 0.12);
  --border-hover: rgba(217, 118, 58, 0.25);
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 25px -3px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.45);

  /* Theme specific */
  --theme-icon-sun: 0;
  --theme-icon-moon: 1;
}

/* ============================================
   RESET & BASE
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

/* ============================================
   ANIMATED BACKGROUND
   ============================================ */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  transition: opacity var(--transition-smooth);
}

.bg-layer::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 40%, var(--accent-soft), transparent 50%),
    radial-gradient(ellipse 60% 60% at 80% 20%, rgba(217, 118, 58, 0.08), transparent 50%),
    radial-gradient(ellipse 70% 50% at 60% 80%, var(--success-soft), transparent 50%);
  animation: bgPulse 15s ease-in-out infinite alternate;
}

.bg-layer::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  opacity: 0.03;
  pointer-events: none;
}

@keyframes bgPulse {
  0% {
    transform: scale(1) rotate(0deg);
  }

  100% {
    transform: scale(1.05) rotate(2deg);
  }
}

/* Floating Particles */
.particles {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.particle {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--accent-primary);
  border-radius: 50%;
  opacity: 0.3;
  animation: float 20s infinite ease-in-out;
}

.particle:nth-child(1) {
  left: 10%;
  top: 20%;
  animation-delay: 0s;
  animation-duration: 25s;
}

.particle:nth-child(2) {
  left: 20%;
  top: 80%;
  animation-delay: 2s;
  animation-duration: 20s;
}

.particle:nth-child(3) {
  left: 80%;
  top: 40%;
  animation-delay: 4s;
  animation-duration: 22s;
  background: var(--accent-secondary);
}

.particle:nth-child(4) {
  left: 40%;
  top: 60%;
  animation-delay: 6s;
  animation-duration: 18s;
}

.particle:nth-child(5) {
  left: 65%;
  top: 90%;
  animation-delay: 8s;
  animation-duration: 23s;
  background: var(--success);
}

.particle:nth-child(6) {
  left: 90%;
  top: 10%;
  animation-delay: 1s;
  animation-duration: 21s;
}

.particle:nth-child(7) {
  left: 5%;
  top: 50%;
  animation-delay: 3s;
  animation-duration: 19s;
  background: var(--accent-secondary);
}

.particle:nth-child(8) {
  left: 55%;
  top: 15%;
  animation-delay: 5s;
  animation-duration: 24s;
}

@keyframes float {

  0%,
  100% {
    transform: translate(0, 0) scale(1);
    opacity: 0.3;
  }

  25% {
    transform: translate(30px, -50px) scale(1.5);
    opacity: 0.6;
  }

  50% {
    transform: translate(-20px, -100px) scale(1);
    opacity: 0.3;
  }

  75% {
    transform: translate(50px, -50px) scale(1.2);
    opacity: 0.5;
  }
}

/* ============================================
   TOP BAR / NAVIGATION
   ============================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Brand Section */
.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.05rem;
  transition: var(--transition-smooth);
}

.brand:hover {
  transform: scale(1.02);
}

/* Nexcel Logo */
.brand-logo {
  height: 38px;
  width: auto;
  transition: var(--transition-smooth);
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  color: white;
  font-size: 0.95rem;
  font-weight: 800;
  box-shadow: var(--shadow-glow);
  position: relative;
  overflow: hidden;
}

.brand-badge::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.3), transparent 60%);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Topbar Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Theme Toggle Button */
.theme-toggle {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.theme-toggle:hover {
  border-color: var(--accent-primary);
  background: var(--accent-soft);
  transform: scale(1.05);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.theme-toggle:hover svg {
  color: var(--accent-primary);
}

.theme-toggle .sun-icon {
  position: absolute;
  opacity: var(--theme-icon-sun);
  transform: rotate(calc((1 - var(--theme-icon-sun)) * 90deg));
}

.theme-toggle .moon-icon {
  position: absolute;
  opacity: var(--theme-icon-moon);
  transform: rotate(calc((1 - var(--theme-icon-moon)) * -90deg));
}

/* User Pill */
.user-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

.user-pill::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success-glow);
  animation: pulse 2s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.2);
  }
}

/* ============================================
   PAGE CONTAINER
   ============================================ */
.page {
  width: min(1400px, calc(100% - 4rem));
  margin: 2rem auto;
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   CARDS - Glassmorphism Style
   ============================================ */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--glass-shadow);
  position: relative;
  overflow: hidden;
  transition: var(--transition-smooth);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-hover), transparent);
}

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

/* ============================================
   BUTTONS
   ============================================ */
.primary-btn,
.ghost-btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-smooth);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  position: relative;
  overflow: hidden;
}

.primary-btn {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.primary-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  transition: 0.5s;
}

.primary-btn:hover::before {
  left: 100%;
}

.primary-btn:hover {
  background: var(--accent-gradient-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px var(--accent-glow);
}

.primary-btn:active {
  transform: translateY(0);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.ghost-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.ghost-btn:hover {
  background: var(--bg-tertiary);
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* ============================================
   FORMS
   ============================================ */
.form {
  display: grid;
  gap: 1.25rem;
}

.form label {
  display: grid;
  gap: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

input,
textarea {
  font-family: inherit;
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: var(--transition-smooth);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input:focus,
textarea:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg-tertiary);
}

input:hover:not(:focus),
textarea:hover:not(:focus) {
  border-color: var(--border-hover);
}

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

/* ============================================
   ALERTS
   ============================================ */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(194, 58, 56, 0.2);
  animation: shake 0.4s ease-out;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-5px);
  }

  40% {
    transform: translateX(5px);
  }

  60% {
    transform: translateX(-3px);
  }

  80% {
    transform: translateX(3px);
  }
}

.alert::before {
  content: '⚠';
  font-size: 1.1rem;
}

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-wrap {
  min-height: calc(100vh - 100px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-card {
  width: min(480px, 100%);
  padding: 2.5rem;
  text-align: center;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-card .muted {
  font-size: 0.9rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}

.login-card .form {
  text-align: left;
}

.login-card .primary-btn {
  width: 100%;
  padding: 1rem;
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* ============================================
   HERO SECTION
   ============================================ */
.hero {
  text-align: center;
  padding: 3rem 1rem;
  position: relative;
}

.hero h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-primary) 50%, var(--accent-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 8s ease infinite;
  background-size: 200% 200%;
}

@keyframes gradientShift {

  0%,
  100% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }
}

.hero .muted {
  font-size: 1.1rem;
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.7;
}

/* ============================================
   METRICS GRID
   ============================================ */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin: 2rem 0;
}

.metric-card {
  padding: 1.75rem;
  border-radius: var(--radius-xl);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  position: relative;
  overflow: hidden;
  transition: var(--transition-smooth);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 4px 0 0 4px;
}

.metric-card span {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.metric-card strong {
  display: block;
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
}

.metric-card.success::before {
  background: var(--success);
}

.metric-card.success strong {
  color: var(--success);
}

.metric-card.danger::before {
  background: var(--danger);
}

.metric-card.danger strong {
  color: var(--danger);
}

.metric-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-lg);
}

/* ============================================
   CONTRACTS GRID
   ============================================ */
.contracts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.contract-card {
  text-decoration: none;
  color: inherit;
  padding: 1.5rem;
  position: relative;
  transition: var(--transition-smooth);
}

.contract-card::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-xl);
  padding: 1px;
  background: linear-gradient(135deg, transparent 40%, rgba(255, 160, 50, 0.8) 100%);
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: var(--transition-smooth);
}

.contract-card:hover::after {
  opacity: 1;
}

.contract-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px rgba(255, 160, 50, 0.15);
}

.contract-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}

.contract-head h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.contract-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.contract-foot span:last-child {
  font-weight: 700;
  color: var(--accent-primary);
  font-size: 1rem;
}

/* ============================================
   STATUS PILLS
   ============================================ */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.status-pass {
  background: var(--success-soft);
  color: var(--success);
  box-shadow: 0 0 12px var(--success-glow);
}

.status-pass::before {
  content: '✓';
}

.status-fail {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: 0 0 12px var(--danger-glow);
}

.status-fail::before {
  content: '✗';
}

.status-unknown {
  background: var(--neutral);
  color: var(--text-muted);
}

.status-unknown::before {
  content: '?';
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
  grid-column: 1 / -1;
  padding: 4rem 2rem;
  text-align: center;
}

.empty-state h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.empty-state .muted {
  font-size: 0.95rem;
}

/* ============================================
   CHAT PAGE LAYOUT
   ============================================ */
.chat-page {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  min-height: calc(100vh - 150px);
}

/* Contract Summary Sidebar */
.contract-summary {
  padding: 1.75rem;
  align-self: start;
  position: sticky;
  top: 100px;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s ease;
}

.contract-summary .back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: var(--transition-smooth);
}

.contract-summary .back-link::before {
  /* content: '←'; */
  font-size: 1.1rem;
  transition: transform var(--transition-smooth);
}

.contract-summary .back-link:hover {
  color: var(--accent-secondary);
}

.contract-summary .back-link:hover::before {
  transform: translateX(-4px);
}

.contract-summary h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 1.25rem 0 1rem;
  color: var(--text-primary);
}

.contract-summary dl {
  margin-top: 1.5rem;
  display: grid;
  gap: 1rem;
}

.contract-summary dt {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.contract-summary dd {
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.5;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.contract-summary dd:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

/* Chat Card */
.chat-card {
  display: flex;
  flex-direction: column;
  padding: 1.75rem;
  min-height: 70vh;
  height: calc(100vh - 170px);
  max-height: calc(100vh - 170px);
  overflow: hidden;
}

.chat-header {
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
}

.chat-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.chat-header h2::before {
  content: '🤖';
  font-size: 1.3rem;
}

.chat-header .muted {
  font-size: 0.9rem;
}

/* Chat Messages */
.chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

.chat-card.has-scroll .chat-messages {
  padding-right: 0.4rem;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* Message Bubbles */
.msg {
  max-width: 80%;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  white-space: pre-wrap;
  animation: messageIn 0.3s ease-out;
  position: relative;
}

.msg.markdown {
  white-space: normal;
}

.msg.markdown p {
  margin: 0 0 0.65rem;
}

.msg.markdown p:last-child {
  margin-bottom: 0;
}

.msg.markdown h1,
.msg.markdown h2,
.msg.markdown h3,
.msg.markdown h4 {
  margin: 0 0 0.55rem;
  line-height: 1.35;
}

.msg.markdown h1 {
  font-size: 1.2rem;
}

.msg.markdown h2 {
  font-size: 1.1rem;
}

.msg.markdown h3,
.msg.markdown h4 {
  font-size: 1rem;
}

.msg.markdown ul,
.msg.markdown ol {
  margin: 0 0 0.65rem 1.2rem;
}

.msg.markdown li {
  margin: 0.2rem 0;
}

.msg.markdown blockquote {
  margin: 0 0 0.65rem;
  padding: 0.15rem 0 0.15rem 0.8rem;
  border-left: 3px solid var(--accent-primary);
  color: var(--text-secondary);
}

.msg.markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.12rem 0.32rem;
  font-size: 0.85em;
}

[data-theme="dark"] .msg.markdown code {
  background: rgba(0, 0, 0, 0.3);
}

.msg.markdown pre {
  margin: 0 0 0.65rem;
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.08);
  overflow-x: auto;
}

[data-theme="dark"] .msg.markdown pre {
  background: rgba(0, 0, 0, 0.28);
}

.msg.markdown pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 0.84rem;
}

.msg.markdown a {
  color: var(--accent-primary);
  text-decoration: underline;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg.user {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: white;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  background: linear-gradient(135deg, var(--success-soft), var(--accent-soft));
  color: var(--success);
  border: 1px solid rgba(45, 138, 95, 0.2);
  text-align: center;
  font-size: 0.9rem;
}

.msg.typing {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-style: italic;
}

.msg.typing::after {
  content: '';
  display: inline-block;
  width: 20px;
  animation: typingDots 1.4s infinite;
}

@keyframes typingDots {

  0%,
  20% {
    content: '.';
  }

  40% {
    content: '..';
  }

  60%,
  100% {
    content: '...';
  }
}

/* Chat Form */
.chat-form {
  margin-top: auto;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
  display: grid;
  gap: 1rem;
}

.chat-form textarea {
  min-height: 80px;
  resize: none;
}

.chat-form .primary-btn {
  justify-self: end;
}

/* ============================================
   MUTED TEXT
   ============================================ */
.muted {
  color: var(--text-muted);
}

.compact {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1024px) {
  .chat-page {
    grid-template-columns: 1fr;
  }

  .contract-summary {
    position: static;
  }

  .page {
    width: calc(100% - 2rem);
  }
}

/* ============================================
   MOBILE: Contract Summary Slide-Over Panel
   ============================================ */

/* Toggle Button - only visible on mobile */
.mobile-summary-toggle {
  display: none;
}

/* Close Button inside panel - only visible on mobile */
.mobile-summary-close {
  display: none;
}

/* Overlay backdrop - only visible on mobile */
.mobile-summary-overlay {
  display: none;
}

@media (max-width: 768px) {
  .topbar {
    padding: 0.75rem 1rem;
  }

  .brand-text {
    display: none;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .contracts-grid {
    grid-template-columns: 1fr;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .login-card {
    padding: 1.5rem;
  }

  .chat-card {
    padding: 1rem;
    height: calc(100vh - 140px);
    max-height: calc(100vh - 140px);
    min-height: calc(100vh - 140px);
  }

  .msg {
    max-width: 90%;
  }

  /* ---- Chat Page: Mobile Layout ---- */
  .chat-page {
    grid-template-columns: 1fr;
    position: relative;
  }

  /* Hide sidebar by default on mobile, make it a slide-over */
  .contract-summary {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(380px, 85vw);
    max-height: 100vh;
    overflow-y: auto;
    z-index: 2000;
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
    transform: translateX(-105%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
      opacity 0.3s ease;
    box-shadow: none;
    padding: 1.5rem;
    padding-top: 1rem;
  }

  .contract-summary.mobile-open {
    transform: translateX(0);
    opacity: 1;
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.25);
  }

  /* Overlay backdrop */
  .mobile-summary-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    z-index: 1999;
    pointer-events: none;
    transition: background 0.35s ease;
  }

  .mobile-summary-overlay.active {
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  /* Floating Toggle Button */
  .mobile-summary-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    position: fixed;
    bottom: 1.25rem;
    left: 1.25rem;
    z-index: 1500;
    padding: 0.75rem 1.15rem;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 24px var(--accent-glow),
      0 2px 8px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: floatIn 0.5s ease-out;
  }

  .mobile-summary-toggle:active {
    transform: scale(0.95);
  }

  @keyframes floatIn {
    from {
      opacity: 0;
      transform: translateY(20px) scale(0.9);
    }

    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }

  /* Close Button inside panel */
  .mobile-summary-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition-smooth);
    z-index: 10;
  }

  .mobile-summary-close:hover {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: var(--danger);
  }

  /* Scrollbar for the panel */
  .contract-summary::-webkit-scrollbar {
    width: 4px;
  }

  .contract-summary::-webkit-scrollbar-track {
    background: transparent;
  }

  .contract-summary::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
  }
}

@media (max-width: 480px) {
  .page {
    width: calc(100% - 1rem);
    margin: 1rem auto;
  }

  .card {
    border-radius: var(--radius-lg);
  }

  .metric-card {
    padding: 1.25rem;
  }

  .metric-card strong {
    font-size: 2rem;
  }

  .contract-card {
    padding: 1.25rem;
  }
}

/* ============================================
   LOADING STATES
   ============================================ */
.loading {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   SKELETON LOADING
   ============================================ */
.skeleton {
  background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* ============================================
   TOOLTIPS
   ============================================ */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-md);
  z-index: 1000;
}

[data-tooltip]:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-4px);
}

/* ============================================
   FOCUS VISIBLE
   ============================================ */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* ============================================
   SELECTION
   ============================================ */
::selection {
  background: var(--accent-primary);
  color: white;
}

/* ============================================
   NEXCEL FOOTER BRANDING
   ============================================ */
.nexcel-branding {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  margin-top: auto;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.nexcel-branding svg {
  height: 18px;
  width: auto;
}