/* ============================================================
   MCRM Design System — Phase 1
   design-system.css
   모든 페이지에서 공통으로 사용하는 디자인 토큰 & 컴포넌트
   ============================================================ */

/* ── 1. CSS 변수 (Design Tokens) ── */
:root {
  /* Backgrounds */
  --bg:        #0a0c10;
  --surface:   #13161d;
  --surface2:  #1c2030;
  --surface3:  #242840;

  /* Borders */
  --border:    rgba(255, 255, 255, 0.07);
  --border2:   rgba(255, 255, 255, 0.12);

  /* Brand Colors */
  --primary:      #4f8ef7;
  --primary-dim:  rgba(79, 142, 247, 0.12);
  --primary-glow: rgba(79, 142, 247, 0.25);
  --secondary:    #7c6af5;

  /* Semantic Colors */
  --success:     #3dd68c;
  --success-dim: rgba(61, 214, 140, 0.12);
  --warning:     #f5a623;
  --warning-dim: rgba(245, 166, 35, 0.12);
  --danger:      #f76f6f;
  --danger-dim:  rgba(247, 111, 111, 0.12);
  --info:        #6fcff7;
  --info-dim:    rgba(111, 207, 247, 0.12);

  /* Text */
  --text:  #e8eaf0;
  --text2: #8b90a0;
  --text3: #555b6e;

  /* Layout */
  --radius:    14px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --nav-h:     56px;
  --sidebar-w: 220px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --t-fast: 0.15s ease;
  --t-med:  0.25s ease;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: opacity var(--t-fast); }
a:hover { opacity: 0.8; }

img { max-width: 100%; display: block; }

input, textarea, select, button { font-family: inherit; }

/* ── 3. Typography ── */
h1 { font-size: 2rem;    font-weight: 800; letter-spacing: -1px; line-height: 1.15; }
h2 { font-size: 1.5rem;  font-weight: 700; letter-spacing: -0.5px; }
h3 { font-size: 1.15rem; font-weight: 600; }
h4 { font-size: 1rem;    font-weight: 600; }

.text-sm    { font-size: 12px; }
.text-xs    { font-size: 11px; }
.text-muted { color: var(--text2); }
.text-dim   { color: var(--text3); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }

.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }

/* ── 4. Layout Utilities ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.page-content {
  padding: 32px 32px;
  max-width: 1200px;
  margin: 0 auto;
}

.flex        { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between{ display: flex; align-items: center; justify-content: space-between; }
.flex-col    { display: flex; flex-direction: column; }
.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.mt-8  { margin-top: 8px;  }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-8  { margin-bottom: 8px;  }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.mb-32 { margin-bottom: 32px; }

/* ── 5. Cards & Surfaces ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.card-sm { padding: 16px; border-radius: var(--radius-sm); }

.card-hover {
  transition: transform var(--t-med), border-color var(--t-med), box-shadow var(--t-med);
}
.card-hover:hover {
  transform: translateY(-2px);
  border-color: var(--border2);
  box-shadow: var(--shadow-md);
}

/* Stat Card */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--t-fast);
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--stat-color, var(--primary));
  opacity: 0.7;
}

.stat-card:hover { border-color: var(--border2); }

.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -1px;
  color: var(--stat-color, var(--text));
  line-height: 1;
  margin-bottom: 8px;
}

.stat-delta {
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 4px;
}

.stat-delta.up   { color: var(--success); }
.stat-delta.down { color: var(--danger); }

/* ── 6. Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--t-fast);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  user-select: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-xs  { padding: 5px 10px; font-size: 12px; border-radius: var(--radius-xs); gap: 4px; }
.btn-sm  { padding: 7px 14px; font-size: 13px; }
.btn-lg  { padding: 12px 24px; font-size: 15px; }
.btn-xl  { padding: 14px 32px; font-size: 16px; border-radius: var(--radius); }

.btn-block { width: 100%; }

/* Variants */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 0 rgba(79, 142, 247, 0);
}
.btn-primary:hover {
  background: #6ea3ff;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(79, 142, 247, 0.3);
}
.btn-primary:active { transform: translateY(0); box-shadow: none; }

.btn-secondary {
  background: var(--primary-dim);
  color: var(--primary);
  border-color: var(--primary-glow);
}
.btn-secondary:hover { background: rgba(79, 142, 247, 0.2); }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); border-color: var(--border2); }

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: rgba(247, 111, 111, 0.25);
}
.btn-danger:hover { background: rgba(247, 111, 111, 0.2); }

.btn-success {
  background: var(--success-dim);
  color: var(--success);
  border-color: rgba(61, 214, 140, 0.25);
}
.btn-success:hover { background: rgba(61, 214, 140, 0.2); }

.btn-warning {
  background: var(--warning-dim);
  color: var(--warning);
  border-color: rgba(245, 166, 35, 0.25);
}

/* Icon button */
.btn-icon {
  width: 36px; height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
}
.btn-icon.btn-sm { width: 30px; height: 30px; }

/* ── 7. Form Elements ── */
.form-group { margin-bottom: 18px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 7px;
}

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

.form-label .hint {
  color: var(--text3);
  font-weight: 400;
  margin-left: 6px;
}

.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 10px 14px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
  -webkit-appearance: none;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-dim);
}

.form-control::placeholder { color: var(--text3); }

.form-control:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
}

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b90a0' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.form-control.is-error { border-color: var(--danger); }
.form-control.is-error:focus { box-shadow: 0 0 0 3px var(--danger-dim); }

.form-control.is-success { border-color: var(--success); }

.form-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-hint {
  font-size: 12px;
  color: var(--text3);
  margin-top: 5px;
}

/* Char counter */
.form-counter {
  display: flex;
  justify-content: flex-end;
  font-size: 11px;
  color: var(--text3);
  margin-top: 4px;
}

.form-counter.near-limit { color: var(--warning); }
.form-counter.at-limit   { color: var(--danger); }

/* ── 8. Badges & Tags ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-primary { background: var(--primary-dim);  color: var(--primary); }
.badge-success { background: var(--success-dim);  color: var(--success); }
.badge-warning { background: var(--warning-dim);  color: var(--warning); }
.badge-danger  { background: var(--danger-dim);   color: var(--danger);  }
.badge-info    { background: var(--info-dim);     color: var(--info);    }
.badge-neutral { background: rgba(255,255,255,0.06); color: var(--text2); }

/* ── 9. Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table th {
  background: var(--surface2);
  color: var(--text3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }

.table tbody tr {
  background: var(--surface);
  transition: background var(--t-fast);
}

.table tbody tr:hover { background: var(--surface2); }

.table-compact th, .table-compact td { padding: 9px 12px; }

/* ── 10. Alerts / Toasts ── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid transparent;
  margin-bottom: 16px;
}

.alert-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }

.alert-primary { background: var(--primary-dim); border-color: var(--primary-glow); color: var(--primary); }
.alert-success { background: var(--success-dim); border-color: rgba(61,214,140,0.25); color: var(--success); }
.alert-warning { background: var(--warning-dim); border-color: rgba(245,166,35,0.25); color: var(--warning); }
.alert-danger  { background: var(--danger-dim);  border-color: rgba(247,111,111,0.25); color: var(--danger);  }

.alert p { margin-top: 4px; font-size: 13px; opacity: 0.85; }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  background: var(--surface3);
  border: 1px solid var(--border2);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.25s ease forwards;
  pointer-events: auto;
  min-width: 240px;
}

.toast.hiding { animation: toastOut 0.25s ease forwards; }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--primary); }
.toast-warning { border-left: 3px solid var(--warning); }

@keyframes toastIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(20px); } }

/* ── 11. Modals ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  animation: slideUp 0.25s ease;
}

.modal-lg { max-width: 680px; }
.modal-xl { max-width: 860px; }

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

.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  width: 30px; height: 30px;
  background: transparent;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--text3);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: all var(--t-fast);
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

.modal-body    { padding: 24px; }
.modal-footer  {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ── 12. Credit Warning Banner ── */
.credit-banner {
  background: var(--warning-dim);
  border-bottom: 1px solid rgba(245, 166, 35, 0.2);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--warning);
  font-weight: 500;
}

.credit-banner a {
  color: var(--warning);
  text-decoration: underline;
  font-weight: 700;
}

/* ── 13. Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.page-header-left h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.page-header-left p { font-size: 14px; color: var(--text2); }

/* ── 14. Loading States ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-xs);
}

@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── 15. Divider ── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── 16. Empty State ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  color: var(--text3);
  text-align: center;
}

.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state-title { font-size: 16px; font-weight: 600; color: var(--text2); margin-bottom: 8px; }
.empty-state-desc  { font-size: 14px; margin-bottom: 20px; }

/* ── 17. Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-btn {
  min-width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  transition: all var(--t-fast);
  padding: 0 6px;
  font-family: inherit;
}

.page-btn:hover { background: var(--surface2); color: var(--text); }
.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── 18. Animations ── */
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp  { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.fade-in  { animation: fadeIn  0.3s ease forwards; }
.slide-up { animation: slideUp 0.3s ease forwards; }

/* ── 19. Responsive Utilities ── */
@media (max-width: 1024px) {
  .page-content { padding: 24px 20px; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .page-content { padding: 20px 16px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}

@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr; }
  .modal  { margin: 0; border-radius: var(--radius) var(--radius) 0 0; max-width: 100%; }
}

/* ── 20. Utility: Scrollbar ── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ══════════════════════════════════════════════════
   라이트 모드 (html[data-theme="light"])
   ══════════════════════════════════════════════════ */
html[data-theme="light"] {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --surface2:  #f0f3f9;
  --surface3:  #e4e9f4;
  --border:    rgba(0,0,0,0.08);
  --border2:   rgba(0,0,0,0.14);
  --text:      #111827;
  --text2:     #374151;
  --text3:     #9ca3af;
}
html[data-theme="light"] body { background: var(--bg); color: var(--text); }
html[data-theme="light"] .card { box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
html[data-theme="light"] .table tbody tr:hover { background: #f8faff; }
html[data-theme="light"] .form-control { background: #fff; }
html[data-theme="light"] .user-dropdown { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }

/* ══════════════════════════════════════════════════
   반응형 강화 (모바일 최적화)
   ══════════════════════════════════════════════════ */

/* 터치 친화적 최소 영역 */
@media (max-width: 768px) {
  .btn       { min-height: 44px; }
  .btn-sm    { min-height: 36px; }
  .btn-xs    { min-height: 30px; }
  .form-control { font-size: 16px; } /* iOS 줌 방지 */
  .nav-link  { padding: 10px 14px; }
  .page-content { padding: 16px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 1.6rem; }
  .card      { padding: 16px; }
  .table th, .table td { padding: 10px 10px; }
  .modal     { margin: 0; border-radius: var(--radius) var(--radius) 0 0;
               position: fixed; bottom: 0; left: 0; right: 0; max-width: 100%; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  #toast-container { bottom: 16px; right: 16px; left: 16px; }
  .toast { min-width: 0; }
  .pagination { gap: 2px; }
  .page-btn  { min-width: 30px; height: 30px; font-size: 12px; }
}

@media (max-width: 480px) {
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  .page-header { gap: 10px; }
  .page-header .btn { width: 100%; justify-content: center; }
  .send-actions { flex-direction: column; }
  .send-actions-right { width: 100%; flex-direction: column; }
  .send-actions-right .btn { width: 100%; }
  .stat-card { padding: 14px; }
  .table-wrap { border-radius: var(--radius-sm); }
}

/* 프린트 */
@media print {
  .site-header, .site-footer, .hamburger, .mobile-drawer { display: none !important; }
  .header-spacer { height: 0 !important; }
  body { background: #fff; color: #000; }
  .card { border: 1px solid #ddd; box-shadow: none; }
}
