:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0ea5e9;
  --brand-ink: #0b86bf;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius-xl: 18px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 12px 24px rgba(0, 0, 0, 0.06), 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 8px 16px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.04);
  --focus: 0 0 0 3px rgba(14, 165, 233, 0.18);
  --gap: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic",
    "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  letter-spacing: 0.2px;
}

a {
  color: inherit;
  text-decoration: none;
}

/* 앱 프레임 */
.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

/* 상단바 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  margin: 14px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 6px rgba(14, 165, 233, 0.12);
}

/* 컨테이너 */
.container {
  padding: 10px 14px 28px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--gap);
  align-items: start;
}

/* 사이드바 */
.sidebar {
  position: sticky;
  top: 90px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 20px;
}

.sidebar-section {
  margin-bottom: 24px;
}

.sidebar-section:last-child {
  margin-bottom: 0;
}

.sidebar-section h3 {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-item:hover {
  background: #f3f4f6;
}

.nav-item.active {
  background: var(--brand);
  color: white;
  font-weight: 600;
}

.nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

/* 메인 콘텐츠 */
.main-content {
  min-width: 0;
}

/* 패널/카드 */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  margin-bottom: var(--gap);
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 24px;
}

.panel h3 {
  margin: 0 0 16px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* 폼 */
.form {
  display: grid;
  gap: 16px;
}

.row {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: #fbfbfc;
  border-radius: 14px;
  padding: 12px 14px;
}

.field input,
.field select,
.field textarea {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  color: var(--text);
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
}

.field:focus-within {
  border-color: var(--brand);
  box-shadow: var(--focus);
}

/* 버튼 */
.btn {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-block;
  color: var(--text);
}

.btn:hover {
  box-shadow: var(--shadow-sm);
}

.btn.primary {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
}

.btn.primary:hover {
  background: var(--brand-ink);
}

.btn.full {
  width: 100%;
}

.btn-small {
  padding: 6px 12px;
  font-size: 0.875rem;
  display: inline-block;
  background: var(--brand);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-small:hover {
  background: var(--brand-ink);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

/* 유틸리티 클래스 */
.flex {
  display: flex;
}

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gap-sm {
  gap: 8px;
}

.gap-md {
  gap: 12px;
}

.gap-lg {
  gap: 16px;
}

.mt-sm {
  margin-top: 8px;
}

.mt-md {
  margin-top: 16px;
}

.mt-lg {
  margin-top: 24px;
}

.mb-sm {
  margin-bottom: 8px;
}

.mb-md {
  margin-bottom: 16px;
}

.mb-lg {
  margin-bottom: 24px;
}

.text-center {
  text-align: center;
}

.text-muted {
  color: var(--muted);
}

/* 협력사 빠른 선택 리스트 */
.partner-quick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.partner-quick-item {
  display: block;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text);
}

.partner-quick-item:hover {
  background: #f9fafb;
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.partner-quick-item .partner-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
  color: var(--text);
}

.partner-quick-item .partner-info {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.partner-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.partner-pagination .page-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.partner-pagination .page-btn:hover {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.partner-pagination .page-info {
  font-size: 12px;
  color: var(--muted);
  min-width: 50px;
  text-align: center;
}

/* 대표사 정보 표시 */
.company-info-display {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}

.company-info-display h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--brand);
  display: flex;
  align-items: center;
  gap: 8px;
}

.company-info-display .info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  font-size: 13px;
}

.company-info-display .info-item {
  display: flex;
  justify-content: space-between;
}

.company-info-display .info-label {
  color: var(--muted);
}

.company-info-display .info-value {
  font-weight: 600;
  color: var(--text);
}

/* 결과 박스 */
.result-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 20px;
  margin-top: var(--gap);
}

.result-box.success {
  border-color: var(--success);
  background: #ecfdf5;
}

.result-box.danger {
  border-color: var(--danger);
  background: #fef2f2;
}

/* 메트릭 */
.metric {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 8px 0;
}

.metric.success {
  color: var(--success);
}

.metric.danger {
  color: var(--danger);
}

/* 상세 정보 */
.detail-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.detail-item {
  padding: 12px;
  background: #fafafa;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.detail-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.detail-value {
  font-size: 16px;
  font-weight: 600;
}

/* 배지 */
.badge {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  display: inline-block;
}

.badge.ok {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

.badge.warn {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

.badge.error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

/* 회사 카드 */
.company-card {
  background: #fafafa;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.company-card.primary-company {
  background: #e0f2fe;
  border-color: var(--brand);
}

.company-card h4 {
  margin: 0 0 12px;
  font-size: 16px;
}

/* 정보 박스 */
.info-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
  line-height: 1.7;
  color: #92400e;
}

.info-box strong {
  display: block;
  margin-bottom: 8px;
  color: #78350f;
}

/* 공식 박스 */
.formula-box {
  background: #f0f9ff;
  border: 2px solid var(--brand);
  border-radius: 12px;
  padding: 20px;
  margin: 16px 0;
  text-align: center;
}

.formula {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.8;
}

/* 공식 테이블 */
.formula-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.formula-table thead {
  background: #f3f4f6;
}

.formula-table th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--line);
}

.formula-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.formula-table tbody tr:last-child td {
  border-bottom: none;
}

.formula-table tbody tr:hover {
  background: #fafafa;
}

/* 알림 메시지 */
.alert {
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 24px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #0c4a6e;
}

.alert.alert-success {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #065f46;
}

.alert.alert-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.alert p {
  margin: 0;
}

/* 반응형 */
@media (max-width: 1024px) {
  .container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    top: 0;
  }
}

@media (max-width: 768px) {
  .row {
    grid-template-columns: 1fr;
  }

  .sidebar-nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}
