/* ========== 기본 변수 ========== */
:root {
  --bg: #0f1216;
  --bg-2: #161b22;
  --bg-3: #1c2128;
  --bg-hover: #22272e;
  --border: #2c3340;
  --border-light: #3a4250;
  --text: #e6edf3;
  --text-2: #b8c2cc;
  --text-3: #7d8590;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;

  --stage-prep: #6b7280;
  --stage-tech: #10b981;
  --stage-nda: #8b5cf6;
  --stage-rfi: #3b82f6;
  --stage-quote: #f59e0b;
  --stage-rfq: #ef4444;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.3), 0 4px 10px rgba(0,0,0,.2);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "맑은 고딕", "Apple SD Gothic Neo", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --bg-2: #ffffff;
    --bg-3: #f0f3f6;
    --bg-hover: #e9eef3;
    --border: #d0d7de;
    --border-light: #e1e6ec;
    --text: #1f2328;
    --text-2: #4b5563;
    --text-3: #6e7681;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select {
  font-family: inherit; font-size: 15px;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; outline: none; width: 100%;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
textarea { resize: vertical; min-height: 80px; font-family: var(--font); }

/* ========== 로고 ========== */
.logo-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  position: relative;
  flex-shrink: 0;
}
.logo-mark::after {
  content: "Y";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 18px;
}

/* ========== 로그인 ========== */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 30% 20%, rgba(59,130,246,.08), transparent 60%),
              radial-gradient(circle at 70% 80%, rgba(139,92,246,.08), transparent 60%);
}
.login-box {
  width: 100%; max-width: 380px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-logo h1 { font-size: 18px; }
.login-logo .muted { color: var(--text-3); font-size: 13px; }
.login-box label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.login-box button {
  width: 100%; padding: 10px; margin-top: 16px;
  background: var(--accent); color: #fff; border-radius: var(--radius);
  font-weight: 600; font-size: 15px;
}
.login-box button:hover { background: var(--accent-2); }
.error { color: var(--danger); margin-top: 10px; font-size: 14px; }

/* ========== 상단 헤더 ========== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 16px; }
.tabs { display: flex; gap: 4px; }
.tab {
  padding: 7px 14px; border-radius: var(--radius);
  color: var(--text-2); font-size: 15px; font-weight: 500;
}
.tab:hover { background: var(--bg-3); color: var(--text); }
.tab.active { background: var(--bg-3); color: var(--text); }
.user-area { display: flex; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius);
  color: var(--text-2); font-size: 18px;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }

/* 모바일 헤더 */
.mobile-tabs { display: none; }
@media (max-width: 768px) {
  .topbar .tabs { display: none; }
  .topbar { padding: 10px 14px; }
  .mobile-tabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--bg-2); border-top: 1px solid var(--border);
    z-index: 100;
    padding: 6px 4px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .mtab {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 6px 4px; font-size: 12px; color: var(--text-3);
    border-radius: var(--radius);
  }
  .mtab.active { color: var(--accent); }
  .mtab > span { font-size: 11px; }
  main#view { padding-bottom: 80px; }
}

/* ========== 메인 영역 ========== */
main#view { max-width: 1280px; margin: 0 auto; padding: 20px; }

.section-title { font-size: 18px; font-weight: 600; color: var(--text); margin: 0 0 14px; }
.section-sub { color: var(--text-3); font-size: 13px; }
.muted { color: var(--text-3); }

/* ========== 카드 ========== */
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; }
.card-title { font-size: 15px; font-weight: 600; color: var(--text-2); margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; }
.card-title .link { color: var(--accent); font-size: 14px; cursor: pointer; }

/* ========== KPI 카드 ========== */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
@media (max-width: 768px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; } }
.kpi { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; }
.kpi-label { color: var(--text-3); font-size: 13px; margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-value.danger { color: var(--danger); }
.kpi-delta { color: var(--text-3); font-size: 12px; margin-top: 4px; }

/* ========== 깔때기 차트 ========== */
.dual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
@media (max-width: 768px) { .dual-grid { grid-template-columns: 1fr; } }
.split-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; margin-bottom: 14px; }
@media (max-width: 768px) { .split-grid { grid-template-columns: 1fr; } }
.funnel-row { display: grid; grid-template-columns: 80px 1fr 32px; gap: 8px; align-items: center; font-size: 13px; margin-bottom: 6px; }
.funnel-bar { height: 22px; background: var(--bg-3); border-radius: 4px; overflow: hidden; position: relative; }
.funnel-fill { height: 100%; transition: width .3s; }
.funnel-count { text-align: right; font-weight: 600; font-size: 13px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-prep { background: rgba(107,114,128,.2); color: #9ca3af; }
.badge-tech { background: rgba(16,185,129,.2); color: #34d399; }
.badge-nda { background: rgba(139,92,246,.2); color: #a78bfa; }
.badge-rfi { background: rgba(59,130,246,.2); color: #60a5fa; }
.badge-quote { background: rgba(245,158,11,.2); color: #fbbf24; }
.badge-rfq { background: rgba(239,68,68,.2); color: #f87171; }

.item-pill { display: inline-block; padding: 2px 8px; border-radius: 4px; background: var(--bg-3); font-size: 12px; color: var(--text-2); font-family: var(--font-mono); margin-right: 4px; margin-bottom: 2px; }

/* ========== 활동 피드 ========== */
.activity-item { padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.activity-item:last-child { border-bottom: none; }
.activity-item:hover { background: var(--bg-3); padding-left: 8px; padding-right: 8px; border-radius: 4px; }
.activity-date { font-size: 13px; color: var(--text-3); margin-bottom: 3px; }
.activity-title { font-size: 15px; font-weight: 500; line-height: 1.5; }

/* ========== 알림 ========== */
.alert-item { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.alert-item:last-child { border-bottom: none; }
.alert-icon { width: 28px; height: 28px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.alert-icon.danger { background: rgba(239,68,68,.15); color: var(--danger); }
.alert-icon.warning { background: rgba(245,158,11,.15); color: var(--warning); }
.alert-icon.info { background: rgba(59,130,246,.15); color: var(--accent); }
.alert-body { flex: 1; }
.alert-title { font-weight: 600; }
.alert-sub { color: var(--text-3); font-size: 13px; margin-top: 2px; }

/* ========== 고객 리스트 (기본) ========== */
.cust-row { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.cust-row:last-child { border-bottom: none; }
.cust-row:hover { background: var(--bg-3); border-radius: 4px; padding-left: 8px; padding-right: 8px; }
.cust-name { font-size: 15px; }
.cust-name-main { font-weight: 700; color: var(--text); } 
.cust-name-sub { font-weight: 400; color: var(--text-3); } 
.cust-sub { font-size: 13px; color: var(--text-3); margin-top: 2px; }

/* ========== 고객 리스트 페이지 ========== */
.list-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.list-toolbar .search { flex: 1; min-width: 200px; max-width: 320px; }
.list-toolbar select { width: auto; min-width: 110px; }
.list-toolbar button { padding: 8px 14px; border-radius: var(--radius); font-size: 14px; }

.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-secondary { background: var(--bg-3); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; }

.cust-table { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.cust-table-row {
  display: grid; grid-template-columns: 1fr 80px 110px 110px 80px;
  gap: 12px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 15px;
}
.cust-table-row:last-child { border-bottom: none; }
.cust-table-row:hover { background: var(--bg-3); }
.cust-table-row.head {
  background: var(--bg-3); cursor: default;
  font-size: 14px; color: var(--text-2); text-transform: uppercase; letter-spacing: .5px; font-weight: 700;
}
@media (max-width: 768px) {
  .cust-table-row { grid-template-columns: 1fr auto; }
  .cust-table-row > :not(:first-child):not(:last-child) { display: none; }
  .cust-table-row.head { display: none; }
}

/* ========== 상세 패널 (드로어) ========== */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; opacity: 0; transition: opacity .2s; }
.drawer-backdrop.show { opacity: 1; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: 100%; max-width: 580px; background: var(--bg-2); border-left: 1px solid var(--border); z-index: 201; transform: translateX(100%); transition: transform .25s; display: flex; flex-direction: column; }
.drawer.show { transform: translateX(0); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 18px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.field-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 10px 0; align-items: center; border-bottom: 1px solid var(--border); }
.field-label { font-size: 14px; color: var(--text-3); }
.field-value { font-size: 15px; word-break: break-word; white-space: pre-wrap; }

/* ========== 활동 페이지 및 카드 ========== */
.activity-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; margin-bottom: 8px; cursor: pointer; }
.activity-card:hover { background: var(--bg-3); }
.activity-card .head { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-3); margin-bottom: 6px; }
.activity-card .head .cust-link { color: var(--accent); font-weight: 600; }
.activity-card .title-text { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.activity-card .content-text { font-size: 14px; color: var(--text-2); white-space: pre-wrap; word-break: break-word; max-height: 80px; overflow: hidden; position: relative; }

/* ========== 캘린더 ========== */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.cal-nav { display: flex; gap: 8px; align-items: center; }
.cal-nav button { padding: 6px 12px; }
.cal-month { font-size: 18px; font-weight: 600; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 8px; }
.cal-dow { text-align: center; font-size: 13px; color: var(--text-3); padding: 6px 0; font-weight: 600; }
.cal-day { background: var(--bg-3); border-radius: 6px; padding: 6px 8px; min-height: 80px; font-size: 14px; cursor: pointer; transition: background .15s; display: flex; flex-direction: column; gap: 2px; }
.cal-day:hover { background: var(--bg-hover); }
.cal-day.other { opacity: .35; }
.cal-day.today { border: 1px solid var(--accent); }

/* ========== 모달 ========== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; transition: opacity .2s; }
.modal-backdrop.show { opacity: 1; }
.modal { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0; width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; transform: scale(.95); transition: transform .2s; }
.modal-backdrop.show .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ========== FAB & 토스트 ========== */
.fab { position: fixed; right: 20px; bottom: 84px; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 28px; font-weight: 300; box-shadow: var(--shadow-lg); z-index: 90; }
@media (min-width: 769px) { .fab { bottom: 24px; } }
#toast-root { position: fixed; top: 80px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-2); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 12px 16px; border-radius: var(--radius); font-size: 14px; box-shadow: var(--shadow-lg); animation: slideIn .25s; }

/* ========== 인라인 편집 및 칩 ========== */
.inline-editable { cursor: pointer; transition: background .12s; }
.inline-editable:hover { background: var(--bg-3); border-radius: 4px; }
.inline-editable .inline-edit-hint { font-size: 12px; color: var(--text-3); margin-left: 8px; opacity: 0; }
.inline-editable:hover .inline-edit-hint { opacity: 0.6; }
.item-pill-lg { display: inline-block; padding: 6px 14px; border-radius: 6px; background: linear-gradient(135deg, rgba(59,130,246,.15), rgba(139,92,246,.15)); border: 1px solid var(--border-light); font-size: 14px; font-weight: 600; color: var(--text); font-family: var(--font-mono); }
.item-list-inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ========== 🛠️ 6단계 진행상태 띠 (테스트 적용 완료 버전) ========== */
.stage-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  width: 100%;
}
.stage-chip {
  display: block;
  padding: 6px 2px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 4px;
  background: rgba(255,255,255,.04);
  color: var(--text-3);
  white-space: nowrap;
  
  /* 미선택 단계는 얇고 옅은 테두리 */
  border: 1px solid rgba(255, 255, 255, 0.15); 
  
  letter-spacing: -0.3px;
  text-align: center;
  transition: all 0.2s ease;
}

/* 선택된 단계는 투명한 테두리와 어두운 배경, 흰색 텍스트 및 그림자 효과 */
.stage-chip.current {
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  border: 1px solid transparent; 
  padding: 6px 2px; 
}
.stage-strip.compact { gap: 2px; }
.stage-strip.compact .stage-chip { 
  padding: 4px 1px; 
  font-size: 12px;
}
.stage-strip.compact .stage-chip.current {
  padding: 4px 1px; 
}

/* 밝은 텍스트가 뚜렷하게 보이도록 채도를 약간 낮춘 어두운 배경색 적용 */
.stage-chip.current.badge-prep  { background: #4b5563; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); } 
.stage-chip.current.badge-tech  { background: #059669; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); } 
.stage-chip.current.badge-nda   { background: #6d28d9; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); } 
.stage-chip.current.badge-rfi   { background: #2563eb; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); } 
.stage-chip.current.badge-quote { background: #d97706; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); } 
.stage-chip.current.badge-rfq   { background: #dc2626; color: #ffffff; text-shadow: 0 1px 2px rgba(0,0,0,0.3); } 

/* ========== 고객 리스트 레이아웃 크기 상향 ========== */
.cust-table-row.new-layout { grid-template-columns: 1.5fr 60px 2.5fr 90px 60px; gap: 16px; align-items: center; padding: 12px 16px; }
.level-tag { display: inline-block; padding: 2px 8px; font-size: 12px; font-weight: 600; background: var(--bg-3); color: var(--text-2); border-radius: 4px; border: 1px solid var(--border); }
.recent-cell { font-size: 13px; text-align: center; padding: 4px 0; }
.recent-cell.danger { color: var(--danger); font-weight: 600; }
.count-cell { text-align: center; font-weight: 600; color: var(--text-2); font-size: 14px; }

@media (max-width: 768px) {
  .cust-table-row.new-layout { grid-template-columns: 1fr auto; gap: 8px; }
  .cust-table-row.new-layout > :nth-child(2), .cust-table-row.new-layout > :nth-child(3), .cust-table-row.new-layout > :nth-child(4) { display: none; }
}

/* ========== 타임라인 및 연도 하이라이트 ========== */
.timeline { position: relative; padding-left: 0; }
.timeline-item { display: grid; grid-template-columns: 64px 1fr; gap: 14px; padding: 10px 0; cursor: pointer; position: relative; border-radius: 6px; transition: background .12s; }
.timeline-item:hover { background: var(--bg-3); }
.timeline-item:not(.last)::before { content: ''; position: absolute; left: 32px; top: 64px; bottom: -10px; width: 2px; background: var(--border); }
.timeline-date { width: 64px; background: linear-gradient(135deg, #3b82f6, #2563eb); border-radius: 8px; padding: 8px 4px; color: #fff; display: flex; flex-direction: column; align-items: center; height: fit-content; box-shadow: 0 2px 6px rgba(59,130,246,.25); }
.td-year { font-size: 11px; font-weight: 500; opacity: 0.85; letter-spacing: .5px; }
.td-year.highlight-year { color: #ffeb3b !important; font-weight: 800; opacity: 1; text-shadow: 0 0 4px rgba(255, 235, 59, 0.5); }
.td-mmdd { font-size: 18px; font-weight: 700; line-height: 1.1; margin-top: 2px; font-family: var(--font-mono); letter-spacing: -0.5px; }
.timeline-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; word-break: break-word; }
.timeline-content { font-size: 14px; color: var(--text-2); white-space: pre-wrap; word-break: break-word; max-height: 80px; overflow: hidden; line-height: 1.5; }