:root {
  --blue:   #2563eb;
  --blue-d: #1d4ed8;
  --green:  #059669;
  --amber:  #d97706;
  --red:    #dc2626;
  --purple: #7c3aed;
  --gray:   #6b7280;
  --bg:     #f1f5f9;
  --card:   #ffffff;
  --border: #e2e8f0;
  --text:   #1e293b;
  --muted:  #64748b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ── LOGIN ──────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .logo-icon { font-size: 40px; display: block; margin-bottom: 8px; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--text); }
.login-logo p  { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── MS LOGIN BUTTON ──────────────────────────────────────────────── */
.btn-ms {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 11px 16px;
  background: white; border: 1.5px solid #8c8c8c; border-radius: 4px;
  font-size: 15px; font-weight: 600; color: #1e293b;
  text-decoration: none; cursor: pointer;
  transition: background .15s;
}
.btn-ms:hover { background: #f5f5f5; }

.login-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 12px; margin: 16px 0 12px;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── USER SEARCH ──────────────────────────────────────────────────── */
.user-search-wrap { position: relative; }
.user-search-input {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; outline: none;
  background: white; transition: border-color .15s;
  box-sizing: border-box;
}
.user-search-input:focus { border-color: var(--blue); }
.user-search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: white; border: 1.5px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-md); z-index: 50; max-height: 240px; overflow-y: auto;
}
.us-option {
  padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.us-option:last-child { border-bottom: none; }
.us-option:hover { background: var(--bg); }
.us-option-name { font-weight: 600; }
.us-option-email { font-size: 11px; color: var(--muted); }
.us-no-results { padding: 10px 12px; color: var(--muted); font-size: 13px; }

#login-form label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
#login-form input {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; transition: border-color .15s;
}
#login-form input:focus { border-color: var(--blue); }
.error-msg { background: #fef2f2; color: var(--red); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-top: 10px; }

/* ── TOPNAV ──────────────────────────────────────────────────── */
.topnav {
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-brand { display: flex; align-items: center; gap: 8px; margin-right: 32px; }
.logo-icon-sm { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 16px; color: var(--text); }

.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-links a {
  padding: 6px 14px; border-radius: 8px;
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }
.nav-links a.active { background: #eff6ff; color: var(--blue); }

.badge {
  background: var(--red); color: white;
  border-radius: 99px; font-size: 10px; font-weight: 700;
  padding: 1px 6px; margin-left: 6px; vertical-align: middle;
}

.nav-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
#nav-user-name { font-size: 13px; font-weight: 500; color: var(--muted); }
.btn-link { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.btn-link:hover { color: var(--red); }

/* ── MAIN ────────────────────────────────────────────────────── */
#main-content { padding: 28px 28px; max-width: 1100px; margin: 0 auto; }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: none;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-decoration: none;
}
.btn:hover { opacity: .88; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary   { background: var(--blue);   color: white; }
.btn-success   { background: var(--green);  color: white; }
.btn-danger    { background: var(--red);    color: white; }
.btn-warning   { background: var(--amber);  color: white; }
.btn-purple    { background: var(--purple); color: white; }
.btn-ghost     { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-full      { width: 100%; justify-content: center; margin-top: 16px; padding: 11px; }
.btn-sm        { padding: 5px 11px; font-size: 12px; }

/* ── PAGE HEADER ─────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header .subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ── CONTRACT LIST ───────────────────────────────────────────── */
.contract-list { display: flex; flex-direction: column; gap: 10px; }

.contract-card {
  background: white; border-radius: var(--radius);
  border: 1px solid var(--border); padding: 16px 20px;
  cursor: pointer; transition: box-shadow .15s, border-color .15s;
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start;
}
.contract-card:hover { box-shadow: var(--shadow-md); border-color: #cbd5e1; }

.cc-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.cc-meta  { color: var(--muted); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.cc-meta span::before { content: ''; }

.cc-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

/* ── STATUS BADGES ───────────────────────────────────────────── */
.status {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 99px; padding: 3px 10px; font-size: 11px; font-weight: 600;
  white-space: nowrap;
}
.s-draft               { background: #f1f5f9; color: var(--gray); }
.s-sent_to_approver    { background: #fffbeb; color: var(--amber); }
.s-rejected_by_approver,
.s-rejected_by_signatory { background: #fef2f2; color: var(--red); }
.s-sent_to_signatory   { background: #eff6ff; color: var(--blue); }
.s-signed              { background: #f0fdf4; color: var(--green); }
.s-archived            { background: #f5f3ff; color: var(--purple); }

/* ── EMPTY STATE ─────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--muted);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* ── CONTRACT DETAIL ─────────────────────────────────────────── */
.contract-detail { display: grid; grid-template-columns: 1fr 360px; gap: 20px; align-items: start; }

.detail-main, .detail-sidebar { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: white; border-radius: var(--radius);
  border: 1px solid var(--border); padding: 20px;
}
.card-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 14px; }

.info-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; }
.info-label { color: var(--muted); font-size: 12px; font-weight: 500; padding-top: 1px; white-space: nowrap; }
.info-value { font-size: 13px; }

.text-block { background: var(--bg); border-radius: 8px; padding: 12px 14px; font-size: 13px; line-height: 1.6; white-space: pre-wrap; }

/* ── TIMELINE ────────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: grid; grid-template-columns: 28px 1fr;
  gap: 0 12px; position: relative;
}
.timeline-item:not(:last-child) .tl-line { height: 100%; }
.tl-dot-wrap { display: flex; flex-direction: column; align-items: center; }
.tl-dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; background: var(--bg); border: 2px solid var(--border); }
.tl-line { width: 2px; background: var(--border); flex: 1; min-height: 12px; }
.tl-body { padding-bottom: 16px; padding-top: 2px; }
.tl-action { font-weight: 600; font-size: 13px; }
.tl-by { font-size: 11px; color: var(--muted); }
.tl-notes { font-size: 12px; color: var(--text); background: var(--bg); border-radius: 6px; padding: 6px 10px; margin-top: 4px; }

/* ── ACTION PANEL ────────────────────────────────────────────── */
.action-panel { border: 2px solid var(--blue); border-radius: var(--radius); padding: 20px; background: #f8faff; }
.action-panel.ap-warning { border-color: var(--amber); background: #fffcf0; }
.action-panel.ap-success { border-color: var(--green); background: #f0fdf4; }
.action-panel.ap-purple  { border-color: var(--purple); background: #faf5ff; }
.action-panel h3 { font-size: 14px; font-weight: 700; margin-bottom: 14px; }
.action-panel .actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ── FORMS ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; outline: none;
  background: white; transition: border-color .15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--blue); }
.form-group textarea { min-height: 90px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

.file-upload-area {
  border: 2px dashed var(--border); border-radius: 8px; padding: 24px 20px;
  text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  user-select: none;
}
.file-upload-area:hover { border-color: var(--blue); background: #f8faff; }
.file-upload-area.drag-over {
  border-color: var(--blue); background: #eff6ff;
  transform: scale(1.015);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.file-upload-area.has-file { border-color: var(--green); background: #f0fdf4; }
.file-upload-area input { display: none; }
.file-upload-icon { font-size: 24px; margin-bottom: 6px; }
.file-name { margin-top: 6px; font-size: 12px; color: var(--blue); font-weight: 500; }

/* ── AI ─────────────────────────────────────────────────────── */
.btn-ai {
  width: 100%; padding: 10px 14px;
  background: linear-gradient(135deg, #6d28d9, #4f46e5);
  color: white; border: none; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn-ai:hover { opacity: .9; transform: translateY(-1px); }
.btn-ai:disabled { opacity: .6; cursor: default; transform: none; }

.ai-summary {
  font-size: 13px; line-height: 1.65; color: var(--text);
  border-top: 1px solid var(--border); padding-top: 12px;
}
.ai-h2 {
  font-size: 13px; font-weight: 700; color: var(--text);
  margin: 12px 0 4px; padding-bottom: 3px;
  border-bottom: 1px solid var(--border);
}
.ai-h3 {
  font-size: 12px; font-weight: 700; color: var(--purple);
  margin: 10px 0 3px; text-transform: uppercase; letter-spacing: .4px;
}
.ai-li {
  padding: 2px 0 2px 14px; position: relative; font-size: 12.5px;
}
.ai-li::before { content: '•'; position: absolute; left: 4px; color: var(--purple); }
.ai-error { font-size: 12px; color: var(--red); background: #fef2f2; border-radius: 6px; padding: 8px 10px; }
.ai-loading { font-size: 12px; color: var(--muted); padding: 6px 0; }

@keyframes dots { 0%,20%{content:'.'} 40%{content:'..'} 60%,100%{content:'...'} }
.ai-dots::after { content: '.'; animation: dots 1.2s infinite; }

.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--blue); }

.form-actions { display: flex; gap: 10px; margin-top: 24px; }

/* ── FILE BADGE ──────────────────────────────────────────────── */
.file-badge {
  display: inline-flex; align-items: center; gap: 8px;
  background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 8px;
  padding: 8px 12px; font-size: 12px; font-weight: 500; color: #0369a1;
  text-decoration: none; transition: background .15s;
}
.file-badge:hover { background: #e0f2fe; }

/* ── USERS TABLE ─────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid var(--border); }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tr:hover td { background: var(--bg); }
.data-table .actions { display: flex; gap: 6px; }

/* ── ROLE BADGES ─────────────────────────────────────────────── */
.role { display: inline-block; border-radius: 99px; padding: 2px 9px; font-size: 11px; font-weight: 600; }
.role-user  { background: #f1f5f9; color: var(--gray); }
.role-adm   { background: #f5f3ff; color: var(--purple); }
.role-admin { background: #fef2f2; color: var(--red); }

/* ── STATS ROW ───────────────────────────────────────────────── */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius); border: 1px solid var(--border); padding: 16px 20px; }
.stat-num  { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── REJECTION NOTE ──────────────────────────────────────────── */
.rejection-box {
  background: #fef2f2; border: 1px solid #fca5a5; border-radius: 8px;
  padding: 12px 14px; font-size: 13px;
}
.rejection-box strong { color: var(--red); }

.stalled-box {
  background: #fffbeb; border: 1px solid #fcd34d; border-left: 4px solid var(--amber);
  border-radius: 8px; padding: 12px 14px; font-size: 13px; line-height: 1.55;
  margin-bottom: 14px;
}

/* ── MODAL ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: white; border-radius: 14px; padding: 28px;
  width: 500px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
  position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; font-size: 16px; cursor: pointer;
  color: var(--muted); width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }

/* ── TOAST ───────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: #1e293b; color: white;
  border-radius: 10px; padding: 12px 20px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md); z-index: 300;
  animation: slideUp .2s ease;
}
.toast.toast-error { background: var(--red); }
.toast.toast-success { background: var(--green); }
@keyframes slideUp { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }

/* ── BACK BUTTON ─────────────────────────────────────────────── */
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 13px; text-decoration: none;
  margin-bottom: 16px; cursor: pointer; background: none; border: none;
  padding: 0;
}
.back-btn:hover { color: var(--text); }

/* ── LOADER ──────────────────────────────────────────────────── */
.loader { text-align: center; padding: 40px; color: var(--muted); font-size: 13px; }

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .contract-detail { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .form-row  { grid-template-columns: 1fr; }
  #main-content { padding: 16px; }
  .topnav { padding: 0 12px; }
  .nav-links a { padding: 6px 8px; font-size: 12px; }
}
