/* COSAP Design System v2 — Premium Fintech */
:root {
  --bg: #f8f9fb;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --text: #111827;
  --text2: #6b7280;
  --text3: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  --transition: 0.2s ease;
}

/* ── Dark Theme ── */
:root.dark {
  --bg: #111827;
  --card: #1f2937;
  --primary: #60a5fa;
  --primary-light: #1e3a5f;
  --primary-dark: #93bbfd;
  --success: #34d399;
  --success-light: #064e3b;
  --warning: #fbbf24;
  --warning-light: #78350f;
  --danger: #f87171;
  --danger-light: #7f1d1d;
  --text: #f3f4f6;
  --text2: #9ca3af;
  --text3: #6b7280;
  --border: #374151;
  --border-light: #1f2937;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.2);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Top Bar ── */
.cosap-topbar {
  background: var(--card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 52px;
}
.cosap-back {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  background: none;
  border: none;
  font-size: 18px;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.cosap-back:active { background: var(--border-light); }
.cosap-back svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; }
.cosap-topbar-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Language Toggle ── */
.cosap-lang {
  display: flex;
  background: var(--border-light);
  border-radius: 20px;
  padding: 2px;
  gap: 1px;
}
.cosap-lang-btn {
  border: none;
  border-radius: 18px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text3);
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.cosap-lang-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37,99,235,0.3);
}

/* ── Content ── */
.cosap-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: 40px;
}
.cosap-content::-webkit-scrollbar { display: none; }

/* ── Cards ── */
.cosap-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
  border: none;
}
.cosap-card-header {
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cosap-card-body { padding: 16px; }

/* ── Buttons ── */
.cosap-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  gap: 8px;
}
.cosap-btn:active { transform: scale(0.97); }
.cosap-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.cosap-btn-primary { background: var(--primary); color: #fff; width: 100%; }
.cosap-btn-primary:hover { background: var(--primary-dark); }
.cosap-btn-success { background: var(--success); color: #fff; }
.cosap-btn-danger { background: var(--danger); color: #fff; }
.cosap-btn-secondary { background: var(--border-light); color: var(--text); width: 100%; }
.cosap-btn-ghost { background: none; color: var(--primary); padding: 8px 16px; }

/* ── Badges/Pills ── */
.cosap-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  line-height: 1.4;
}
.cosap-badge-primary { background: var(--primary-light); color: var(--primary); }
.cosap-badge-success { background: var(--success-light); color: var(--success); }
.cosap-badge-warning { background: var(--warning-light); color: var(--warning); }
.cosap-badge-danger { background: var(--danger-light); color: var(--danger); }

/* ── Spinner ── */
.cosap-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: cosap-spin 0.7s linear infinite;
  margin: 40px auto;
}
@keyframes cosap-spin { to { transform: rotate(360deg); } }
.cosap-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  color: var(--text2);
  font-size: 13px;
}

/* ── Empty State ── */
.cosap-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.cosap-empty-icon {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
  background: var(--border-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}
.cosap-empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.cosap-empty-desc { font-size: 13px; color: var(--text2); }

/* ── Error ── */
.cosap-error { text-align: center; padding: 40px 20px; color: var(--danger); font-size: 14px; }

/* ── Forms ── */
.cosap-form-group { margin-bottom: 16px; }
.cosap-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}
.cosap-input, .cosap-select, .cosap-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  background: var(--card);
  color: var(--text);
  transition: border-color var(--transition);
  min-height: 44px;
}
.cosap-input:focus, .cosap-select:focus, .cosap-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.cosap-textarea { min-height: 100px; resize: vertical; }

/* ── Tabs ── */
.cosap-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.cosap-tabs::-webkit-scrollbar { display: none; }
.cosap-tab {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--card);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text2);
}
.cosap-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Rows ── */
.cosap-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}
.cosap-row:last-child { border-bottom: none; }
.cosap-row-label { color: var(--text2); }
.cosap-row-value { font-weight: 600; color: var(--text); }

/* ── KPI Grid ── */
.cosap-kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.cosap-kpi {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.cosap-kpi-label { font-size: 11px; color: var(--text2); font-weight: 600; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.02em; }
.cosap-kpi-value { font-size: 22px; font-weight: 700; }

/* ── List Items ── */
.cosap-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.cosap-list-item:active { background: var(--border-light); }

/* ── Info Box ── */
.cosap-info-box {
  background: var(--border-light);
  padding: 14px;
  border-radius: 10px;
  margin-bottom: 12px;
}

/* ── Detail Overlay ── */
.cosap-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
  padding: 16px;
  display: none;
  padding-top: env(safe-area-inset-top);
}
.cosap-overlay.show { display: block; }

/* ── Section Title ── */
.cosap-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 20px 0 10px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cosap-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Bar Charts ── */
.cosap-bar-track {
  height: 8px;
  background: var(--border-light);
  border-radius: 4px;
  overflow: hidden;
}
.cosap-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ── Toast ── */
.cosap-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  display: none;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  max-width: calc(100% - 40px);
  text-align: center;
  animation: cosapToastIn 0.2s ease;
}
.cosap-toast.success { background: var(--green, #16a34a); }
.cosap-toast.error { background: var(--red, #dc2626); }
.cosap-toast.info { background: var(--primary, #2563eb); }
.cosap-toast.removing { opacity: 0; transition: opacity 0.2s ease; }
@keyframes cosapToastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ── Action Row ── */
.cosap-action-row {
  display: flex;
  gap: 8px;
}
.cosap-action-row .cosap-btn { flex: 1; }

/* ── Toggle Switch ── */
.cosap-toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.cosap-toggle input { opacity: 0; width: 0; height: 0; }
.cosap-toggle-track {
  position: absolute; inset: 0; background: var(--border); border-radius: 12px;
  cursor: pointer; transition: background 0.2s;
}
.cosap-toggle-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.cosap-toggle input:checked + .cosap-toggle-track { background: var(--primary); }
.cosap-toggle input:checked + .cosap-toggle-track::after { transform: translateX(20px); }

/* ── Settings Rows ── */
.settings-section { padding: 0 16px; margin-bottom: 20px; }
.settings-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text3); padding: 0 0 8px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border-light); min-height: 44px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row-label { font-size: 14px; font-weight: 500; color: var(--text); flex: 1; }
.settings-row-value { font-size: 13px; color: var(--text2); }
.settings-row-chevron { color: var(--text3); flex-shrink: 0; }

/* ── Utilities ── */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text2) !important; }
.text-caption { color: var(--text3) !important; font-size: 12px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* ── Prevent zoom ── */
@media (max-width: 768px) {
  input, select, textarea { font-size: 16px !important; }
}

/* Hide old i18n toggle */
#cfaLangToggle { display: none !important; }
