:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f4f8;
  --border-color: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-dim: rgba(37, 99, 235, 0.08);
  --primary-light: #dbeafe;
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #3b82f6;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 16px;
  --radius-pill: 9999px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-hover); }

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 2px 0 8px rgba(0,0,0,0.03);
}

.sidebar-brand {
  padding: 24px 20px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-top: 4px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  color: var(--primary);
  background: var(--primary-dim);
}

.sidebar-nav a.active {
  color: var(--primary);
  background: var(--primary-light);
  border-left-color: var(--primary);
  font-weight: 600;
}

.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-user .avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.sidebar-user .user-info { flex: 1; }
.sidebar-user .user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.sidebar-user .user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.main-content {
  margin-left: 260px;
  flex: 1;
  padding: 32px 40px;
  min-height: 100vh;
  background: var(--bg-primary);
}

/* Top bar */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-m);
  padding: 24px;
  box-shadow: var(--shadow-card);
}

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-m);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

.stat-card .stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); }
.stat-card .stat-value.primary { color: var(--primary); }

/* Tables */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-m);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}

td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

tr:hover td { background: #f8fafc; }
tr:last-child td { border-bottom: none; }

/* Status badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-draft { background: #f1f5f9; color: #64748b; }
.badge-sent { background: #dbeafe; color: #2563eb; }
.badge-revised { background: #fef3c7; color: #d97706; }
.badge-pending { background: #fef3c7; color: #d97706; }
.badge-ready { background: #d1fae5; color: #059669; }
.badge-accepted { background: #d1fae5; color: #059669; }
.badge-declined { background: #fee2e2; color: #dc2626; }
.badge-active { background: #d1fae5; color: #059669; }
.badge-locked { background: #fee2e2; color: #dc2626; }
.badge-modified { background: #fef3c7; color: #d97706; }
.badge-admin-modified { background: #ede9fe; color: #7c3aed; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-s);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-icon { padding: 6px 10px; }

/* Forms */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-s);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

select.form-control { cursor: pointer; }
textarea.form-control { min-height: 100px; resize: vertical; }

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 20% 50%, rgba(255,255,255,0.15) 0%, transparent 50%),
              radial-gradient(ellipse at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 50%),
              radial-gradient(ellipse at 60% 80%, rgba(255,255,255,0.08) 0%, transparent 50%);
  animation: bgDrift 20s ease-in-out infinite alternate;
  z-index: 0;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 48px 40px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius-l);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  position: relative;
  z-index: 1;
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.login-card .login-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
}

.login-card .btn { width: 100%; justify-content: center; margin-top: 8px; }
.login-card .form-control { background: #f8fafc; }

@keyframes bgDrift {
  0% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(2%, -1%) rotate(1deg); }
  66% { transform: translate(-1%, 2%) rotate(-0.5deg); }
  100% { transform: translate(1%, -2%) rotate(0.5deg); }
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-s);
  margin-bottom: 20px;
  font-size: 14px;
}

.alert-error { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }

/* Quote detail */
.quote-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.quote-meta { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 8px; }
.quote-meta .meta-item { font-size: 13px; color: var(--text-secondary); }
.quote-meta .meta-item strong { color: var(--text-primary); }

.section-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-primary);
}

.line-items-table .override { color: var(--warning); font-style: italic; }
.line-items-table .locked td { opacity: 0.6; }

.quote-total {
  display: flex;
  justify-content: flex-end;
  padding: 20px 24px;
  background: #f8fafc;
  border-top: 1px solid var(--border-color);
  font-size: 18px;
  font-weight: 700;
  gap: 16px;
}

.quote-total .total-label { color: var(--text-muted); }
.quote-total .total-value { color: var(--primary); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-l);
  padding: 32px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}

.modal h3 { margin-bottom: 24px; font-size: 18px; }

/* Revision timeline */
.timeline { margin-top: 16px; }

.timeline-item {
  padding: 16px;
  border-left: 2px solid var(--border-color);
  margin-left: 8px;
  margin-bottom: 12px;
  position: relative;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 20px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg-card);
}

.timeline-item .timeline-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }

/* Audit log */
.audit-entry { padding: 8px 0; border-bottom: 1px solid var(--border-color); font-size: 13px; }
.audit-entry:last-child { border-bottom: none; }
.audit-entry .audit-action { font-weight: 600; color: var(--primary); }
.audit-entry .audit-time { color: var(--text-muted); font-size: 11px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state h3 { font-size: 18px; margin-bottom: 8px; color: var(--text-secondary); }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition);
}

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

/* Contracts section */
.badge-contract-draft { background: #f1f5f9; color: #64748b; }
.badge-contract-active { background: #d1fae5; color: #059669; }
.badge-contract-pending { background: #fef3c7; color: #d97706; }
.badge-contract-expired { background: #fee2e2; color: #dc2626; }
.badge-contract-terminated { background: #fee2e2; color: #dc2626; }

.contract-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
}

.signature-box {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-m);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  background: #f8fafc;
}

.signature-box:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-dim);
}

.signature-box.signed {
  border-color: var(--success);
  border-style: solid;
  background: #ecfdf5;
}

/* Org switcher on dashboard */
.org-switcher select {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* OAuth buttons on login */
.btn-google { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-google:hover { background: #f9fafb; color: #374151; }
.btn-microsoft { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.btn-microsoft:hover { background: #f9fafb; color: #374151; }

/* Org logo in sidebar / forms - ensure visibility on light bg */
.org-logo-dark { filter: none; }
