/* =========================================================
   电子合同签署平台 - 全局样式
   E-Contract Sign Platform
   ========================================================= */

:root {
  --primary: #1a6fff;
  --primary-hover: #1557cc;
  --primary-light: #e8f1ff;
  --success: #22c55e;
  --success-light: #e6f9ee;
  --warning: #f59e0b;
  --warning-light: #fef9e7;
  --danger: #ef4444;
  --danger-light: #fde8e8;
  --info: #6366f1;
  --bg: #f5f7fa;
  --bg-card: #ffffff;
  --bg-input: #f9fafb;
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --sidebar-w: 240px;
  --header-h: 60px;
}

/* Dark theme */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --border: #334155;
    --border-light: #2d3a4d;
    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
    --primary-light: #1e3a5f;
    --success-light: #1a3d2a;
    --warning-light: #3d3520;
    --danger-light: #3d1f1f;
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ====== Components ====== */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius); border: none;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 0.2s; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-outline {
  background: transparent; color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-input); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--radius); }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 14px; font-weight: 500;
  color: var(--text); margin-bottom: 6px;
}
.form-control {
  width: 100%; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text); font-size: 14px; transition: border-color 0.2s;
  outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,111,255,0.1); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; font-family: inherit; }
select.form-control { cursor: pointer; }

/* Cards */
.card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 24px; margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}
.card-title { font-size: 18px; font-weight: 600; }

/* Tables */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 12px 16px; font-weight: 600;
  color: var(--text-secondary); border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 16px; border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
tbody tr:hover { background: var(--bg-input); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-muted { background: var(--bg-input); color: var(--text-muted); }

/* Stats cards */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 20px;
  box-shadow: var(--shadow);
}
.stat-value { font-size: 32px; font-weight: 700; color: var(--text); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; margin-bottom: 12px;
}

/* Tabs */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--border); margin-bottom: 24px; }
.tab-btn {
  padding: 12px 24px; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-secondary); font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 0.2s; margin-bottom: -2px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Modal */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); z-index: 1000;
  justify-content: center; align-items: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius-xl); width: 90%; max-width: 680px;
  max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 18px; font-weight: 600; }
.modal-body { padding: 24px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 12px;
  padding: 16px 24px; border-top: 1px solid var(--border);
}

/* Login page */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a6fff 0%, #6366f1 100%);
}
.login-card {
  background: var(--bg-card); border-radius: var(--radius-xl); padding: 48px;
  width: 100%; max-width: 420px; box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 36px; }
.login-header h1 { font-size: 24px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.login-header p { color: var(--text-muted); font-size: 14px; }
.login-logo { font-size: 40px; margin-bottom: 16px; }

/* Toast */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 14px 20px; border-radius: var(--radius); font-size: 14px;
  color: #fff; box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease; min-width: 280px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
.toast-warning { background: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Loading spinner */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state-text { font-size: 15px; margin-bottom: 16px; }

/* Admin layout */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: var(--sidebar-w); background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}
.sidebar-header {
  padding: 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-logo { font-size: 28px; }
.sidebar-title { font-size: 16px; font-weight: 700; }
.sidebar-subtitle { font-size: 12px; color: var(--text-muted); }
.sidebar-nav { flex: 1; padding: 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-radius: var(--radius); color: var(--text-secondary);
  font-size: 14px; cursor: pointer; transition: all 0.2s;
  margin-bottom: 2px; border: none; background: none; width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--bg-input); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 20px; width: 24px; text-align: center; }
.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.admin-main {
  margin-left: var(--sidebar-w); flex: 1; padding: 24px 32px;
  min-width: 0;
}
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.page-title { font-size: 22px; font-weight: 700; }

/* Signature pad */
.signature-pad-container {
  border: 2px dashed var(--border); border-radius: var(--radius);
  background: #fff; position: relative; overflow: hidden;
  width: 100%; max-width: 400px; height: 200px;
}
.signature-pad-container canvas {
  width: 100%; height: 100%; cursor: crosshair;
}
@media (prefers-color-scheme: dark) {
  .signature-pad-container { background: #fff; }
  .signature-pad-container canvas { background: #fff; }
}

/* Contract content */
.contract-preview {
  background: var(--bg-input); border-radius: var(--radius);
  padding: 24px; max-height: 500px; overflow-y: auto;
  line-height: 1.8; font-size: 14px; white-space: pre-wrap;
  border: 1px solid var(--border);
}

/* Steps */
.steps { display: flex; margin-bottom: 32px; }
.step {
  flex: 1; text-align: center; position: relative;
  padding-top: 32px;
}
.step::before {
  content: ''; position: absolute; top: 12px; left: 50%;
  transform: translateX(-50%); width: 24px; height: 24px;
  border-radius: 50%; background: var(--border); z-index: 1;
}
.step::after {
  content: ''; position: absolute; top: 23px; left: 0; right: 0;
  height: 2px; background: var(--border);
}
.step:first-child::after { left: 50%; }
.step:last-child::after { right: 50%; }
.step.completed::before { background: var(--success); }
.step.completed::after { background: var(--success); }
.step.active::before { background: var(--primary); }
.step-label { font-size: 13px; font-weight: 500; }
.step.completed .step-label { color: var(--success); }
.step.active .step-label { color: var(--primary); }

/* Sign page layout */
.sign-page { min-height: 100vh; background: var(--bg); }
.sign-header {
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 16px 32px; display: flex; align-items: center; justify-content: space-between;
}
.sign-body {
  max-width: 900px; margin: 0 auto; padding: 32px 24px;
}
.sign-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }

/* Timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: ''; position: absolute; left: 8px; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 24px; }
.timeline-item::before {
  content: ''; position: absolute; left: -20px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--border); border: 2px solid var(--bg);
}
.timeline-item.completed::before { background: var(--success); }
.timeline-item.active::before { background: var(--primary); }
.timeline-time { font-size: 12px; color: var(--text-muted); }
.timeline-content { font-size: 14px; margin-top: 4px; }

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