/* ============================================================
   CDD Screening System — CSS
   Colors: Deep Forest #1B3D2E, Emerald #2D8659, Warm White
   ============================================================ */

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

:root {
  --primary: #1B3D2E;
  --accent: #2D8659;
  --accent-hover: #236e48;
  --accent-light: #f0fdf4;
  --secondary: #6B9E7A;
  --bg: #f0f2f5;
  --bg-card: #ffffff;
  --bg-warm: #f9fafb;
  --text: #374151;
  --text-muted: #6B7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --border-light: #d1d5db;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --success: #059669;
  --success-bg: #d1fae5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans TC', sans-serif;
}

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

/* ============================================================
   Layouts
   ============================================================ */

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

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar .brand {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar .brand-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar .brand-text {
  line-height: 1.3;
}
.sidebar .brand-text .name { font-size: 14px; font-weight: 600; }
.sidebar .brand-text .env { font-size: 10px; color: rgba(255,255,255,0.4); }

.sidebar nav { flex: 1; padding: 8px 0; overflow-y: auto; }

.sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  user-select: none;
}

.sidebar .nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
.sidebar .nav-item.active {
  color: #fff;
  background: rgba(45,134,89,0.2);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar .nav-spacer { flex: 1; }
.sidebar .nav-item.logout { color: rgba(239,68,68,0.6); }
.sidebar .nav-item.logout:hover { color: #ef4444; }

.main-area {
  flex: 1;
  margin-left: 220px;
  padding: 24px 32px;
  min-height: 100vh;
}

/* ============================================================
   Login Page (no sidebar)
   ============================================================ */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, #132b1f 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.login-card .brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-card .brand-icon {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  margin-bottom: 12px;
}
.login-card .brand h1 { font-size: 20px; color: var(--primary); font-weight: 700; }
.login-card .brand p { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.login-card .error-box {
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: none;
}
.login-card .error-box.visible { display: block; }

/* ============================================================
   Form Elements
   ============================================================ */

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}
.form-group label .opt { font-weight: 400; color: var(--text-light); font-size: 12px; }

.form-input, .form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: var(--font);
}
.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45,134,89,0.15);
}
.form-input::placeholder { color: var(--text-light); }

.row-2 { display: flex; gap: 12px; }
.row-2 .form-group { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-warm); color: var(--text); border: 1px solid var(--border-light); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ============================================================
   Tables
   ============================================================ */

.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-warm);
  white-space: nowrap;
}
table.data-table td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
}
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--accent-light); }

.font-mono { font-family: 'SF Mono', 'Courier New', monospace; font-size: 12px; }

/* ============================================================
   Tags & Badges
   ============================================================ */

.role-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.role-admin { background: #fee2e2; color: #991b1b; }
.role-manager { background: #fef3c7; color: #92400e; }
.role-operator { background: #dbeafe; color: #1e40af; }
.role-auditor { background: #e0e7ff; color: #3730a3; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-green { background: #10b981; }
.dot-gray { background: #d1d5db; }
.dot-red { background: #ef4444; }

.result-tag {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
}
.tag-pass { background: var(--success-bg); color: var(--success); }
.tag-review { background: var(--warning-bg); color: var(--warning); }
.tag-reject { background: var(--danger-bg); color: var(--danger); }

/* ============================================================
   Top Bar
   ============================================================ */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.topbar h3 { font-size: 20px; font-weight: 700; color: var(--primary); }
.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.topbar .avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}

/* ============================================================
   Cards & Stats
   ============================================================ */

.stats-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 140px;
  background: #fff;
  border-radius: var(--radius);
  padding: 16px 18px;
  border: 1px solid var(--border);
}
.stat-card .num { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-card .label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-card .icon { float: right; font-size: 24px; opacity: 0.2; }

/* ============================================================
   Toolbar
   ============================================================ */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}
.toolbar .left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ============================================================
   CDD Check Form
   ============================================================ */

.schema-toggle {
  display: flex;
  background: #f3f4f6;
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}
.schema-toggle .tab {
  flex: 1;
  text-align: center;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.schema-toggle .tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.cdd-form-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px;
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.result-card {
  background: var(--bg-warm);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  margin-top: 20px;
}
.result-card .row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.result-card .row .val { font-weight: 600; color: var(--text); }

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.visible { display: flex; }

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  width: 440px;
  max-width: 90%;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { font-size: 16px; font-weight: 600; color: var(--primary); margin-bottom: 16px; }
.modal .btn-row { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ============================================================
   Loading Spinner
   ============================================================ */

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   TOTP Section
   ============================================================ */

.totp-box {
  background: var(--accent-light);
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}
.totp-box h4 { font-size: 14px; color: #065f46; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.totp-box .sub { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

.note { font-size: 12px; color: var(--text-light); font-style: italic; margin-top: 4px; }

/* ============================================================
   Risk Badge
   ============================================================ */
.risk-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 12px; font-weight: 600;
}
.risk-low { background: #d1fae5; color: #065f46; }
.risk-medium { background: #fef3c7; color: #92400e; }
.risk-high { background: #fee2e2; color: #991b1b; }

/* ============================================================
   Select Search — Overlay
   ============================================================ */
.select-search-input {
  position: absolute !important;
  top: 24px !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 10 !important;
  width: 100% !important;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.select-search-options {
  position: absolute !important;
  top: 56px !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 20 !important;
  background: #fff !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  max-height: 280px !important;
  overflow-y: auto !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
  width: 100% !important;
}
.select-search-item:hover { background: var(--accent-light) !important; }

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-area { margin-left: 0; padding: 16px; }
  .row-2 { flex-direction: column; }
  .stats-row { flex-direction: column; }
  .stats-row .stat-card { min-width: auto; }
  .modal { width: 100%; max-width: none; margin: 10px; }
}
