/* ══════════════════════════════════════════════════════════════
   온체인 투표 시스템 — style.css
   ══════════════════════════════════════════════════════════════ */

/* ─── Reset & CSS 변수 ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary:       #4f46e5;
  --color-primary-hover: #4338ca;
  --color-secondary:     #6b7280;
  --color-success:       #10b981;
  --color-success-bg:    #d1fae5;
  --color-danger:        #ef4444;
  --color-danger-bg:     #fee2e2;
  --color-warning:       #f59e0b;
  --color-warning-bg:    #fef3c7;
  --color-bg:            #f3f4f6;
  --color-card:          #ffffff;
  --color-border:        #e5e7eb;
  --color-text:          #111827;
  --color-text-muted:    #6b7280;
  --color-text-light:    #9ca3af;
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.06);
  --shadow:     0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 25px rgba(0,0,0,0.12);
}

/* ─── 기반 ──────────────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR",
               sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "Fira Code", "Cascadia Code", monospace;
  font-size: 0.85em;
  background: #f3f4f6;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}

/* ─── 헤더 ──────────────────────────────────────────────────────── */
#app-header {
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.header-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
}

.header-wallet {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.wallet-chip {
  font-family: monospace;
  font-size: 0.85rem;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  padding: 4px 14px;
  color: var(--color-primary);
  font-weight: 500;
}

.header-network {
  background: #f0fdf4;
  border-top: 1px solid #bbf7d0;
  padding: 5px 20px;
  font-size: 0.75rem;
  color: #15803d;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

/* ─── 메인 ──────────────────────────────────────────────────────── */
#app-main {
  flex: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px;
  width: 100%;
}

/* ─── 푸터 ──────────────────────────────────────────────────────── */
#app-footer {
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  padding: 14px 20px;
  text-align: center;
  font-size: 0.85rem;
}

/* ─── 버튼 ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-block { width: 100%; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
  box-shadow: 0 2px 6px rgba(79,70,229,0.4);
}

.btn-secondary {
  background: #f3f4f6;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover:not(:disabled) {
  background: #e5e7eb;
}

.btn-success {
  background: var(--color-success);
  color: #fff;
}
.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}
.btn-outline:hover:not(:disabled) {
  background: #eef2ff;
}

/* ─── 카드 ──────────────────────────────────────────────────────── */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── 오버레이 (SCR-04, SCR-05) ─────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.overlay-icon { font-size: 2.8rem; margin-bottom: 14px; }
.overlay-card h2 { font-size: 1.2rem; margin-bottom: 10px; }
.overlay-card p  { color: var(--color-text-muted); line-height: 1.6; }

.overlay-section {
  margin: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.overlay-section p { margin-bottom: 0; font-size: 0.875rem; }

.network-info-box {
  background: var(--color-warning-bg);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 14px;
  margin: 16px 0;
  text-align: left;
  font-size: 0.875rem;
  line-height: 2;
}

/* ─── 상태 배지 ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-preparing { background: var(--color-warning-bg); color: #92400e; }
.badge-ongoing   { background: var(--color-success-bg); color: #065f46; }
.badge-ended     { background: var(--color-danger-bg);  color: #991b1b; }

/* ─── 프로그레스 바 ──────────────────────────────────────────────── */
.progress-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin: 6px 0 2px;
}
.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 0;
}
.progress-fill.winner { background: var(--color-success); }

/* ─── 후보자 카드 (Phase 6에서 사용) ────────────────────────────── */
.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.candidate-card {
  background: var(--color-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.candidate-card:hover { border-color: var(--color-primary); box-shadow: var(--shadow); }
.candidate-card.winner-card {
  border-color: var(--color-success);
  background: #f0fdf4;
}

.candidate-photo {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  background: #f3f4f6;
  margin-bottom: 12px;
}
.candidate-photo-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: #f3f4f6;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: #d1d5db;
}

.candidate-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 8px;
}

.vote-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

/* ─── 폼 ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-text);
}
.form-input {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: #fff;
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}
.form-input::placeholder { color: var(--color-text-light); }
.form-input:disabled {
  background: #f9fafb;
  color: var(--color-text-muted);
  cursor: not-allowed;
}

.form-error {
  font-size: 0.8rem;
  color: var(--color-danger);
  margin-top: 4px;
}

.form-input-file {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: #f8fafc;
  color: var(--color-text);
  cursor: pointer;
}
.form-input-file:hover { border-color: var(--color-primary); }

/* ─── 스피너 ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
.spinner-dark {
  border-color: rgba(0,0,0,0.1);
  border-top-color: var(--color-primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 토스트 알림 ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  z-index: 2000;
  max-width: 90%;
  text-align: center;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.2s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ─── 플레이스홀더 화면 (Phase 3+ 완성 전) ──────────────────────── */
.placeholder-screen {
  text-align: center;
  padding: 80px 20px;
  color: var(--color-text-muted);
}
.placeholder-screen h2 {
  font-size: 1.4rem;
  color: var(--color-text);
  margin: 12px 0;
}

/* ─── 유틸리티 ──────────────────────────────────────────────────── */
.hidden         { display: none !important; }
.text-muted     { color: var(--color-text-muted); }
.text-center    { text-align: center; }
.text-success   { color: var(--color-success); }
.text-danger    { color: var(--color-danger); }
.font-mono      { font-family: monospace; }
.font-bold      { font-weight: 600; }

.mt-1  { margin-top:  4px; }
.mt-2  { margin-top:  8px; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-2  { margin-bottom:  8px; }
.mb-4  { margin-bottom: 16px; }
.gap-2 { gap: 8px; }

.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; }

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 20px 0;
}

/* ─── SCR-00: 컨트랙트 배포/연결 화면 ──────────────────────────── */
.scr00-wrap {
  max-width: 600px;
  margin: 0 auto;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

.deploy-status {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 12px;
}
.deploy-status.hidden  { display: none; }
.deploy-status-info    { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.deploy-status-error   { background: var(--color-danger-bg); color: #991b1b; border: 1px solid #fca5a5; }

.deploy-success { text-align: center; }
.deploy-success-icon { font-size: 2.5rem; margin-bottom: 12px; }
.deploy-success h3    { font-size: 1.2rem; margin-bottom: 4px; }

.address-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 6px;
}
.address-box code { flex: 1; min-width: 0; word-break: break-all; }

/* ─── SCR-01: 메인 투표 화면 ────────────────────────────────────── */
.scr01-wrap {
  max-width: 960px;
  margin: 0 auto;
}

.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  border: 1px solid transparent;
}
.status-banner-preparing {
  background: var(--color-warning-bg);
  border-color: #fde68a;
}
.status-banner-ongoing {
  background: var(--color-success-bg);
  border-color: #6ee7b7;
}
.status-banner-ended {
  background: var(--color-danger-bg);
  border-color: #fca5a5;
}

/* ─── 관리자 패널 (SCR-02) ──────────────────────────────────────── */
.admin-panel {
  margin-top: 32px;
  border-top: 2px solid var(--color-border);
  padding-top: 24px;
}
.admin-panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--color-text);
}
.admin-section {
  margin-bottom: 16px;
}

/* 관리자 패널 후보자 목록 아이템 */
.candidate-admin-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}
.candidate-admin-item:last-child { border-bottom: none; }
.cand-num {
  min-width: 24px;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.cand-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: #f3f4f6;
}
.cand-admin-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 이미지 미리보기 */
.img-preview-wrap {
  margin-top: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  background: #f8fafc;
}
.img-preview {
  max-width: 160px;
  max-height: 160px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  display: block;
}

/* ─── SCR-03: 결과 화면 (Phase 7) ──────────────────────────────── */
.scr03-wrap {
  max-width: 960px;
  margin: 0 auto;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--color-border);
}

.result-winner,
.result-tie {
  text-align: center;
  padding: 28px 20px;
  background: var(--color-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}
.result-icon   { font-size: 3rem; display: block; margin-bottom: 8px; }
.result-title  { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.result-names  { font-size: 1.25rem; font-weight: 600; color: var(--color-primary); }
.result-sub    { color: var(--color-text-muted); margin-top: 4px; }
.result-no-votes { text-align: center; color: var(--color-text-muted); padding: 20px 0; }

.result-grid { margin-top: 0; }

.result-card { position: relative; }
.rank-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  font-size: 1.3rem;
  line-height: 1;
}

.result-vote-count {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}
.result-vote-count strong { color: var(--color-text); }

.result-admin-bar {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 2px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/* ─── SCR-01: 투표 버튼 (Phase 6) ──────────────────────────────── */
.btn-vote {
  width: 100%;
  margin-top: 4px;
}

.vote-done-badge {
  display: block;
  width: 100%;
  padding: 7px 0;
  border-radius: var(--radius);
  background: var(--color-success-bg);
  color: #065f46;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  margin-top: 4px;
}

.vote-need-wallet {
  font-size: 0.78rem;
  color: var(--color-text-light);
  text-align: center;
  margin-top: 4px;
}

/* ─── 반응형 ─────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-inner  { padding: 10px 14px; }
  #app-main      { padding: 18px 14px; }
  .overlay-card  { padding: 28px 20px; }
  .candidate-grid { grid-template-columns: 1fr; }
  .status-banner { flex-direction: column; align-items: flex-start; gap: 6px; }
}
