/* ===== CSS Variables (Light Mode) ===== */
:root {
  --primary: #1a56db;
  --primary-dark: #1239a0;
  --primary-light: #e8f0fe;
  --danger: #c81e1e;
  --danger-light: #fde8e8;
  --warning: #c27803;
  --warning-light: #fdf6b2;
  --success: #057a55;
  --success-light: #def7ec;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --border-radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);

  /* Semantic tokens */
  --bg-body: var(--gray-50);
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-input: #ffffff;
  --text-base: var(--gray-800);
  --text-muted-color: var(--gray-400);
  --border-color: var(--gray-200);
  --table-header-bg: var(--gray-50);
  --table-row-hover: var(--gray-50);
}

/* ===== Dark Mode ===== */
[data-theme="dark"] {
  --primary: #4d7fee;
  --primary-dark: #3a6cd4;
  --primary-light: #1e2d4a;
  --danger: #f05252;
  --danger-light: #3b1a1a;
  --warning: #e3a008;
  --warning-light: #3b2c00;
  --success: #0e9f6e;
  --success-light: #0d2e22;
  --gray-50: #1a1a2e;
  --gray-100: #22223a;
  --gray-200: #2e2e4a;
  --gray-300: #3d3d5c;
  --gray-400: #6b6b8e;
  --gray-500: #9090b0;
  --gray-600: #b0b0cc;
  --gray-700: #c8c8e0;
  --gray-800: #e0e0f0;
  --gray-900: #f0f0ff;

  --bg-body: #12121f;
  --bg-card: #1e1e30;
  --bg-sidebar: #1a1a2e;
  --bg-input: #22223a;
  --text-base: #e0e0f0;
  --text-muted-color: #7070a0;
  --border-color: #2e2e4a;
  --table-header-bg: #22223a;
  --table-row-hover: #22223a;
  --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
}

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

html { font-size: 14px; }

body {
  font-family: 'Malgun Gothic', '맑은 고딕', 'Apple SD Gothic Neo', -apple-system, sans-serif;
  color: var(--text-base);
  background: var(--bg-body);
  line-height: 1.5;
}

a { text-decoration: none; color: inherit; }

/* ===== Topbar ===== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.topbar-menu-btn {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column;
  gap: 4px; padding: 4px;
}
.topbar-menu-btn span {
  display: block; width: 20px; height: 2px;
  background: white; border-radius: 2px;
}

.topbar-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 1rem; font-weight: 700;
  flex: 1;
}
.topbar-icon { font-size: 1.2rem; }
.topbar-right {
  display: flex; align-items: center; gap: 12px;
}
.topbar-company {
  font-size: 0.85rem; opacity: 0.85;
  background: rgba(255,255,255,0.15);
  padding: 3px 10px; border-radius: 20px;
}

.theme-toggle {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 20px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background 0.2s;
  color: white;
}
.theme-toggle:hover { background: rgba(255,255,255,0.28); }

/* ===== Layout ===== */
.layout {
  display: flex;
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 12px 0;
  z-index: 50;
  transition: transform 0.2s ease;
}

.sidebar.collapsed {
  transform: translateX(-100%);
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gray-400);
  padding: 12px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--gray-700);
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--gray-50);
  color: var(--primary);
}

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

.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

/* ===== Main Content ===== */
.content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  transition: margin-left 0.2s ease;
}

.content.sidebar-collapsed {
  margin-left: 0;
}

/* ===== Page ===== */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-subtitle {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-top: 4px;
}

.legal-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid rgba(26,86,219,0.2);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-800);
}

/* ===== Dashboard Grid ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.stat-card-icon {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.stat-card-label {
  font-size: 0.8rem;
  color: var(--gray-500);
  font-weight: 600;
}

.stat-card-count {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1;
  margin: 4px 0;
}

.stat-card-sub {
  font-size: 0.75rem;
  color: var(--gray-400);
}

.stat-card-badge {
  position: absolute;
  top: 12px; right: 12px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
}

.badge-ok { background: var(--success-light); color: var(--success); }
.badge-warn { background: var(--warning-light); color: var(--warning); }
.badge-none { background: var(--gray-100); color: var(--gray-500); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--border-radius);
  border: 1px solid transparent;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn-danger:hover { background: #a61616; }

.btn-outline {
  background: var(--bg-card);
  color: var(--text-base);
  border-color: var(--border-color);
}
.btn-outline:hover { background: var(--bg-body); }

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
  border-color: transparent;
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--gray-100); }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-xs { padding: 3px 8px; font-size: 0.75rem; }

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== Table ===== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--border-radius);
  border: 1px solid var(--border-color);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  background: var(--table-header-bg);
  color: var(--gray-600);
  font-weight: 700;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--table-row-hover); }

/* ===== Forms ===== */
.form-section {
  margin-bottom: 24px;
}

.form-section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  padding: 8px 12px;
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--border-radius) var(--border-radius) 0;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.legal-cite {
  font-size: 0.7rem;
  font-weight: normal;
  color: var(--primary);
  opacity: 0.7;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full-width { grid-column: 1 / -1; }

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-600);
}

label .required { color: var(--danger); margin-left: 2px; }

input[type="text"],
input[type="date"],
input[type="time"],
input[type="number"],
input[type="email"],
input[type="tel"],
select,
textarea {
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--gray-800);
  background: var(--bg-input);
  color: var(--text-base);
  transition: border-color 0.15s;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}

textarea { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: 0.75rem;
  color: var(--gray-400);
}

.form-info {
  font-size: 0.75rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 8px;
  border-radius: 4px;
}

/* ===== Risk Matrix ===== */
.risk-matrix {
  display: grid;
  grid-template-columns: auto repeat(5, 48px);
  gap: 3px;
  align-items: center;
  font-size: 0.75rem;
  margin: 12px 0;
}

.risk-matrix .axis-label {
  font-weight: 700;
  color: var(--gray-600);
  text-align: center;
  padding: 4px;
}

.risk-cell {
  width: 48px; height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.1s;
}
.risk-cell:hover { transform: scale(1.1); }
.risk-cell.selected { outline: 3px solid var(--gray-900); }

.risk-1-5 { background: #fef9c3; color: #713f12; }
.risk-6-9 { background: #fed7aa; color: #7c2d12; }
.risk-10-15 { background: #fecaca; color: #7f1d1d; }
.risk-16-25 { background: #dc2626; color: white; }

.risk-badge-low { background: #dcfce7; color: #166534; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 700; }
.risk-badge-medium { background: #fef9c3; color: #713f12; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 700; }
.risk-badge-high { background: #fed7aa; color: #7c2d12; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 700; }
.risk-badge-critical { background: #fecaca; color: #7f1d1d; padding: 2px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 700; }

/* ===== Status Badges ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-draft { background: var(--gray-100); color: var(--gray-600); }
.status-complete { background: var(--success-light); color: var(--success); }
.status-approved { background: var(--primary-light); color: var(--primary); }
.status-pending { background: var(--warning-light); color: var(--warning); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: var(--gray-400);
  line-height: 1; padding: 0;
}
.modal-close:hover { color: var(--gray-700); }

.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
}

.toast {
  background: var(--gray-900);
  color: white;
  padding: 10px 16px;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease;
  max-width: 300px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

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

/* ===== Checklist ===== */
.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
}

.checklist-item:last-child { border-bottom: none; }

.check-group {
  display: flex;
  gap: 16px;
}

.check-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: normal;
  cursor: pointer;
}

input[type="radio"], input[type="checkbox"] {
  width: auto;
  cursor: pointer;
}

/* ===== Progress ===== */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-fill.danger { background: var(--danger); }
.progress-fill.warning { background: var(--warning); }
.progress-fill.success { background: var(--success); }

/* ===== Compliance Table ===== */
.compliance-table td:first-child { max-width: 300px; }
.compliance-rate-chip {
  display: inline-block;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
}

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

.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.9rem; }

/* ===== Alert ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
}

.alert-info { background: var(--primary-light); color: var(--primary); border: 1px solid rgba(26,86,219,0.2); }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid rgba(194,120,3,0.2); }
.alert-danger { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(200,30,30,0.2); }
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid rgba(5,122,85,0.2); }

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

.tab {
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

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

/* ===== Dynamic Row ===== */
.dynamic-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.dynamic-table th {
  background: var(--gray-100);
  padding: 7px 8px;
  font-size: 0.78rem;
}

.dynamic-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border-color);
}

.dynamic-table input,
.dynamic-table select,
.dynamic-table textarea {
  padding: 5px 6px;
  font-size: 0.8rem;
}

/* ===== Signature Box ===== */
.signature-box {
  border: 1px solid var(--gray-300);
  border-radius: 4px;
  height: 60px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px;
  font-size: 0.7rem;
  color: var(--gray-400);
  background: white;
}

/* ===== Page Actions Bar ===== */
.page-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Print Styles ===== */
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }

  #print-area {
    font-family: 'Malgun Gothic', '맑은 고딕', sans-serif;
    font-size: 11pt;
    color: #000;
    padding: 10mm;
  }

  .print-doc {
    page-break-after: always;
  }

  .print-title {
    text-align: center;
    font-size: 16pt;
    font-weight: 900;
    margin-bottom: 8mm;
    letter-spacing: 0.2em;
  }

  .print-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10pt;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #000;
    padding: 4px 6px;
  }

  .print-table th {
    background: #f0f0f0;
    font-weight: 700;
    text-align: center;
  }

  .print-section-title {
    font-size: 11pt;
    font-weight: 700;
    background: #e8e8e8;
    padding: 4px 8px;
    margin: 6mm 0 2mm;
    border: 1px solid #999;
  }

  .print-footer {
    margin-top: 8mm;
    font-size: 8pt;
    color: #555;
    border-top: 1px solid #ccc;
    padding-top: 4px;
  }

  .print-signature-row {
    display: flex;
    gap: 16px;
    margin-top: 8mm;
  }

  .print-sign-box {
    flex: 1;
    border: 1px solid #000;
    padding: 6px;
    min-height: 40px;
  }

  .print-sign-label {
    font-size: 9pt;
    font-weight: 700;
    border-bottom: 1px solid #ccc;
    margin-bottom: 4px;
    padding-bottom: 2px;
  }

  .no-print { display: none !important; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .content {
    margin-left: 0;
  }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }
.text-muted { color: var(--gray-400); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mt-4 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mb-4 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.w-full { width: 100%; }
