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

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #111827;
  --sidebar-text: #d1d5db;
  --sidebar-active: #4f46e5;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --surface: #ffffff;
  --bg: #f3f4f6;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.12);
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ── Auth screens ────────────────────────────────────────────────────────── */
.auth-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); gap: 16px; }
.auth-spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
.auth-screen p { color: var(--text-muted); }

.sign-in-brand { text-align: center; margin-bottom: 8px; }
.sign-in-brand h1 { font-size: 22px; font-weight: 700; margin: 12px 0 4px; }
.sign-in-brand p { color: var(--text-muted); font-size: 13px; }

/* ── App shell ───────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.user-details { overflow: hidden; }
.user-name { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sign-out-btn { background: none; border: none; color: var(--text-muted); font-size: 12px; cursor: pointer; padding: 0; margin-top: 2px; }
.sign-out-btn:hover { color: #fff; }

/* ── Main content ────────────────────────────────────────────────────────── */
#main-content { flex: 1; overflow-y: auto; }

.page { padding: 28px 32px; max-width: 1200px; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h1 { font-size: 20px; font-weight: 700; }
.page-header h2 { font-size: 18px; font-weight: 600; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-body { padding: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h3 { font-size: 14px; font-weight: 600; }

/* Stats row */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 18px 20px; }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }
.empty-row td { text-align: center; padding: 48px; color: var(--text-muted); }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-pending   { background: #f3f4f6; color: #6b7280; }
.badge-extracted { background: #ede9fe; color: #6d28d9; }
.badge-reviewed  { background: #d1fae5; color: #065f46; }
.badge-rejected  { background: #fee2e2; color: #991b1b; }
.badge-needs_review { background: #fef3c7; color: #92400e; }
.badge-draft     { background: #f3f4f6; color: #6b7280; }
.badge-accepted  { background: #d1fae5; color: #065f46; }

.method-badge { font-size: 11px; color: var(--text-muted); font-family: monospace; }

/* Confidence bar */
.conf-bar { width: 80px; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 6px; }
.conf-fill { height: 100%; background: var(--primary); border-radius: 99px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fca5a5; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-success { background: #d1fae5; color: var(--success); border-color: #6ee7b7; }
.btn-success:hover { background: #a7f3d0; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-section { margin-bottom: 24px; }
.form-section-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Search / filter bar ─────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar .form-control { width: auto; }
.search-input { min-width: 220px; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Email viewer ────────────────────────────────────────────────────────── */
.email-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-bottom: 20px; font-size: 13px; }
.email-meta-label { font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.email-body { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.email-iframe { width: 100%; height: 400px; border: none; }
.email-text-pre { padding: 16px; background: #fafafa; font-size: 12px; line-height: 1.6; white-space: pre-wrap; font-family: 'Courier New', monospace; max-height: 400px; overflow-y: auto; }

/* ── Doc viewer ──────────────────────────────────────────────────────────── */
.doc-info { display: flex; align-items: center; gap: 16px; padding: 16px; background: var(--bg); border-radius: var(--radius); margin-bottom: 20px; }
.doc-icon { font-size: 36px; }
.doc-meta { flex: 1; }
.doc-name { font-weight: 600; font-size: 15px; }
.doc-type { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.pdf-embed { width: 100%; height: 600px; border: 1px solid var(--border); border-radius: var(--radius); }
.no-attachment { text-align: center; padding: 48px; color: var(--text-muted); }

/* ── Version timeline ────────────────────────────────────────────────────── */
.version-list { display: flex; flex-direction: column; gap: 12px; }
.version-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.version-card.active-version { border-color: var(--primary); }
.version-header { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: #fafafa; cursor: pointer; }
.version-num { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.version-info { flex: 1; }
.version-title { font-weight: 600; font-size: 13px; }
.version-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.version-actions { display: flex; gap: 8px; }
.version-body { padding: 16px; border-top: 1px solid var(--border); display: none; }
.version-body.open { display: block; }

/* ── Contract form fields ────────────────────────────────────────────────── */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.field-grid .span-2 { grid-column: span 2; }

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb-sep { color: var(--border); }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.loading-placeholder { display: flex; align-items: center; justify-content: center; height: 200px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

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