/* =============================================
   헬스케어 발송문 관리 플랫폼 - 메인 스타일
   ============================================= */

:root {
  --primary: #3b7dd8;
  --primary-dark: #2563bd;
  --primary-light: #e8f0fd;
  --secondary: #64748b;
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #06b6d4;
  --info-light: #cffafe;
  --orange: #f97316;
  --orange-light: #ffedd5;

  --bg-body: #f0f4f8;
  --bg-white: #ffffff;
  --bg-sidebar: #1e2a3a;
  --bg-sidebar-hover: #2d3f55;
  --bg-sidebar-active: #3b7dd8;

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-sidebar: #cbd5e1;
  --text-sidebar-active: #ffffff;

  --border: #e2e8f0;
  --border-focus: #3b7dd8;

  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow: 0 2px 8px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);

  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --header-height: 60px;

  --transition: all .2s ease;
}

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

body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

/* ===== 사이드바 ===== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  display: flex;
  flex-direction: column;
  transition: var(--transition);
  z-index: 100;
  overflow: hidden;
}

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-item span:not(.badge-nav),
.sidebar.collapsed .nav-section-label { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px; }
.sidebar.collapsed .nav-item i { margin: 0; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--header-height);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
}

.logo i { color: #f87171; font-size: 20px; }
.logo-text { white-space: nowrap; }

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-sidebar);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: var(--transition);
}
.sidebar-toggle:hover { background: rgba(255,255,255,.1); color: #fff; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  padding: 12px 8px 4px;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-sidebar);
  text-decoration: none;
  transition: var(--transition);
  font-size: 13.5px;
  position: relative;
  margin-bottom: 2px;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.badge-nav {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
  display: none;
}
.badge-nav.show { display: inline-block; }

/* ===== 메인 래퍼 ===== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left .2s ease;
}
.main-wrapper.expanded { margin-left: var(--sidebar-collapsed); }

/* ===== 상단 헤더 ===== */
.top-header {
  height: var(--header-height);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-left { display: flex; align-items: center; gap: 14px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.menu-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: none;
}

.page-title { font-size: 17px; font-weight: 700; color: var(--text-primary); }
.today-date { font-size: 13px; color: var(--text-muted); }

/* ===== 콘텐츠 영역 ===== */
.content-area {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ===== 카드 ===== */
.card {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: #f8fafc; }

/* ===== 스탯 카드 ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-icon.blue  { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.yellow{ background: var(--warning-light); color: var(--warning); }
.stat-icon.red   { background: var(--danger-light);  color: var(--danger); }
.stat-icon.orange{ background: var(--orange-light);  color: var(--orange); }
.stat-icon.teal  { background: var(--info-light);    color: var(--info); }

.stat-info {}
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; color: var(--text-primary); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ===== 테이블 ===== */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; }
thead { background: #f8fafc; }
th {
  padding: 12px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  color: var(--text-primary);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ===== 배지/태그 ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-blue    { background: var(--primary-light);  color: var(--primary); }
.badge-green   { background: var(--success-light);  color: #16a34a; }
.badge-yellow  { background: var(--warning-light);  color: #b45309; }
.badge-red     { background: var(--danger-light);   color: #dc2626; }
.badge-orange  { background: var(--orange-light);   color: #c2410c; }
.badge-gray    { background: #f1f5f9;               color: var(--text-secondary); }
.badge-teal    { background: var(--info-light);     color: #0e7490; }

/* ===== 버튼 ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary  { background: var(--primary);   color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success);   color: #fff; }
.btn-success:hover  { background: #16a34a; }
.btn-danger   { background: var(--danger);    color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-warning  { background: var(--warning);   color: #fff; }
.btn-warning:hover  { background: #d97706; }
.btn-ghost    { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover    { background: #f1f5f9; }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; }
.btn-icon { padding: 6px; border-radius: 6px; }

/* ===== 폼 요소 ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-white);
  transition: var(--transition);
  outline: none;
}
.form-control:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(59,125,216,.12); }
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled { background: #f8fafc; cursor: not-allowed; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
textarea.form-control { resize: vertical; min-height: 80px; line-height: 1.6; }

.form-row { display: grid; gap: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ===== 검색/필터 바 ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-box i {
  position: absolute;
  left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
}
.search-box input {
  padding-left: 32px;
}

/* ===== 모달 ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg-white);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
.modal.modal-lg { max-width: 820px; }
.modal.modal-xl { max-width: 1000px; }

@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer; padding: 4px;
  border-radius: 6px; font-size: 16px;
  transition: var(--transition);
}
.modal-close:hover { background: var(--danger-light); color: var(--danger); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ===== 토스트 알림 ===== */
.toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--bg-white);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid;
  min-width: 280px;
  animation: toastIn .3s ease;
  font-size: 13.5px;
  font-weight: 500;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
.toast.info    { border-color: var(--primary); }
.toast i { font-size: 16px; }
.toast.success i { color: var(--success); }
.toast.error i   { color: var(--danger); }
.toast.warning i { color: var(--warning); }
.toast.info i    { color: var(--primary); }

/* ===== 빈 상태 ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state p { font-size: 15px; }

/* ===== 로딩 ===== */
.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 대시보드 ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 8px;
}

.alert-list { list-style: none; }
.alert-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.alert-item:last-child { border-bottom: none; }
.alert-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.alert-dot.red    { background: var(--danger); }
.alert-dot.orange { background: var(--orange); }
.alert-dot.yellow { background: var(--warning); }

/* ===== 문안 미리보기 ===== */
.message-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  white-space: pre-wrap;
  line-height: 1.8;
  font-size: 13.5px;
  color: var(--text-primary);
  min-height: 120px;
  max-height: 400px;
  overflow-y: auto;
}
.message-preview.short {
  background: #fffbeb;
  border-color: var(--warning);
}
.char-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
}
.char-count.over { color: var(--danger); font-weight: 700; }

/* ===== QA 상태 표시 ===== */
.qa-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius);
}
.qa-ok      { background: var(--success-light); color: #16a34a; }
.qa-error   { background: var(--danger-light);  color: var(--danger); }
.qa-warning { background: var(--warning-light); color: #b45309; }

/* ===== 탭 ===== */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}
.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  white-space: nowrap;
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ===== 페이지네이션 ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-top: 16px;
}
.page-btn {
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  background: var(--bg-white);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== 조건부 색상 행 강조 ===== */
tr.row-danger  td { background: #fff5f5; }
tr.row-warning td { background: #fffbeb; }
tr.row-success td { background: #f0fdf4; }
tr.row-info    td { background: #f0f9ff; }

/* ===== 반응형 ===== */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0 !important; }
  .menu-btn { display: flex !important; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .content-area { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
}

/* ===== 유틸리티 ===== */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success{ color: var(--success); }
.text-warning{ color: var(--warning); }
.fw-bold { font-weight: 700; }
.mt-0  { margin-top: 0; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-0  { margin-bottom: 0; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12{ gap: 12px; }
.gap-16{ gap: 16px; }
.w-full{ width: 100%; }
