/*
 * Pretendard v1.3.9 (SIL Open Font License 1.1) — static/fonts/ 에 자체 호스팅.
 * 인터넷이 없는 환경에서도 동일하게 표시된다.
 */
@font-face {
  font-family: "Pretendard Variable";
  font-weight: 45 920;
  font-style: normal;
  font-display: swap;
  src: url("/static/fonts/PretendardVariable.woff2") format("woff2-variations");
}

:root {
  --font-sans: "Pretendard Variable", Pretendard, -apple-system,
    BlinkMacSystemFont, system-ui, "Segoe UI", "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: #d9e2ec;
  --accent: #0f766e;
  --accent-hover: #0d9488;
  --danger: #b91c1c;
  --error-bg: #fef2f2;
  --ok-bg: #ecfdf5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  letter-spacing: -0.01em;
}

/* 폼 요소는 폰트를 상속하지 않으므로 명시한다. */
button,
input,
select,
textarea {
  font-family: inherit;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -15%, #dcfbf5 0%, transparent 62%),
    var(--bg);
}

.auth-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 30px 28px;
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(15, 23, 42, 0.09);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.auth-logo {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
}

.auth-brand h1 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.25;
}

.auth-tagline {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-card input {
  padding: 11px 12px;
}

.auth-submit {
  margin-top: 4px;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
}

.auth-divider {
  height: 1px;
  background: var(--line);
  margin: 22px 0 14px;
}

.auth-hint {
  margin: 0 0 16px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

a.button {
  display: inline-block;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

a.button.secondary { background: #334155; }
a.button.secondary:hover { background: #475569; }

.auth-links {
  margin: 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--muted);
}

.auth-links a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.auth-links a:hover { text-decoration: underline; }

.alert.ok {
  background: var(--ok-bg);
  color: #065f46;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

.data-table code {
  font-size: 0.8rem;
  word-break: break-all;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions form { margin: 0; }

.topbar h1, .auth-card h1, .panel h2 {
  margin: 0 0 6px;
}

.muted, .hint {
  color: var(--muted);
  font-size: 0.92rem;
}

.layout {
  display: grid;
  gap: 16px;
  padding: 20px 24px 40px;
  max-width: 980px;
  margin: 0 auto;
}

/* 입력 폼 하나만 있는 화면(비밀번호 변경 등)은 좁게 잡는다. */
.layout.narrow {
  max-width: 480px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.pager .button {
  padding: 5px 12px;
  font-size: 0.82rem;
}

.pager .disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.pager-pos {
  min-width: 70px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.small-note {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  line-height: 1.5;
}

/*
 * 메인 화면은 페이지 스크롤 없이 한 뷰포트에 들어가야 한다.
 * 셸이 화면 높이를 잡고, 넘칠 때는 페이지 대신 패널 내부만 스크롤한다.
 */
.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-shell .topbar {
  flex: 0 0 auto;
  padding: 12px 20px;
}

.app-shell .topbar h1 { font-size: 1.25rem; }
.app-shell .topbar .muted { margin: 2px 0 0; font-size: 0.85rem; }

.app-shell .layout {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  padding: 14px 20px;
  max-width: 1500px;
  width: 100%;
}

.app-shell .panel {
  padding: 16px 18px;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.app-shell .panel h2 { font-size: 1.05rem; margin-bottom: 10px; }
.app-shell .form-grid { gap: 10px; }
.app-shell .site-picker { margin-bottom: 10px; }
.app-shell .option-row { margin-top: 10px; }
.app-shell .check-row { font-size: 0.88rem; }
.app-shell .actions { margin-top: 12px; }
.app-shell .preview { margin-top: 10px; padding: 9px 12px; }
.app-shell .hint { margin: 10px 0 0; font-size: 0.85rem; }

.app-shell input[type="text"],
.app-shell input[type="date"],
.app-shell select {
  padding: 8px 10px;
  font-size: 0.95rem;
}

.app-shell .topbar button,
.app-shell a.button {
  padding: 7px 12px;
  font-size: 0.88rem;
}

.app-shell .conn-error-detail { max-height: 110px; }

@media (max-width: 1080px) {
  .app-shell { height: auto; overflow: visible; }
  .app-shell .layout { grid-template-columns: 1fr; }
  .app-shell .panel { overflow: visible; }
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 600;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.4;
}

.option-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 14px;
}

.option-row .check-row {
  flex: 1 1 auto;
  min-width: 0;
  margin-top: 0;
}

.option-row button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.check-row input[type="checkbox"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="date"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.site-picker {
  margin-bottom: 12px;
}

.site-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.site-row select { flex: 1 1 auto; min-width: 0; }
.site-row button { flex: 0 0 auto; white-space: nowrap; }

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: #334155; }
button.secondary:hover { background: #475569; }
button.danger { background: var(--danger); }
button.danger:hover { background: #991b1b; }
button.warn { background: #b45309; }
button.warn:hover { background: #d97706; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.modal-card {
  position: relative;
  width: min(640px, 100%);
  max-height: 85vh;
  overflow: auto;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.3);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.icon-close {
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 4px;
}

.icon-close:hover { background: transparent; color: var(--text); }

.modal-body { padding: 16px 20px; }

.modal-body p { margin: 0 0 10px; }

.req-lead {
  background: #fffbeb;
  color: #92400e;
  padding: 10px 12px;
  border-radius: 8px;
}

.req-list {
  margin: 14px 0 10px;
  display: grid;
  gap: 10px;
}

.req-list > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  align-items: center;
}

.req-list dt {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
}

.req-list dd { margin: 0; }

.req-list code {
  background: #f1f5f9;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.95rem;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.copy-row button {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  padding: 12px 20px 18px;
}

/* --- 사용 안내 --- */

.modal-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.modal-section h3 {
  margin: 0 0 12px;
  font-size: 0.98rem;
}

.guide-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 12px;
}

.guide-steps > li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: start;
}

.guide-steps > li::before {
  content: counter(step);
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.guide-steps b { font-size: 0.92rem; }

.guide-steps > li > div > span {
  display: block;
  margin-top: 3px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
}

.guide-steps code {
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.guide-features {
  margin: 0;
  display: grid;
  gap: 8px;
}

.guide-features > div {
  display: grid;
  grid-template-columns: 116px 1fr;
  gap: 10px;
  font-size: 0.85rem;
  align-items: baseline;
}

.guide-features dt { font-weight: 700; }

.guide-features dd {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.guide-notes {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.55;
}

.guide-warn {
  margin: 10px 0 0;
  background: var(--error-bg);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.55;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.preview {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--ok-bg);
}

/* 저장된 목록에서 고르기만 하고 아직 현장 DB로 확인하지 않은 상태 */
.preview.pending {
  background: #fffbeb;
  color: #92400e;
}

.hidden { display: none; }

.alert.error {
  background: var(--error-bg);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.alert.warn {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fde68a;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  line-height: 1.5;
}

/* 임시 비밀번호는 한 번만 보여주므로 눈에 잘 띄고 그대로 읽히게 한다. */
.temp-pw {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.temp-pw code {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid #fde68a;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  user-select: all;
}

#connError {
  border: 1px solid var(--danger);
}

.conn-error-title {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: 1rem;
}

.conn-error-list {
  margin: 0;
  padding-left: 20px;
  font-size: 0.92rem;
  line-height: 1.6;
}

.conn-error-detail {
  margin: 10px 0 0;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 160px;
  overflow: auto;
}

.job-meta {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.job-meta > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 오류 메시지는 잘리면 곤란하므로 두 줄까지 접어서 보여준다. */
.job-meta .msg {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.4;
}

.tables { display: grid; gap: 6px; margin-top: 10px; }

.app-shell .tables {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  align-content: start;
}

/* 테이블별 진행률은 한 줄에 이름 / 진행바 / 상태를 함께 보여준다. */
.table-row {
  display: grid;
  grid-template-columns: minmax(96px, 1.1fr) minmax(60px, 2fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

.t-name {
  font-weight: 600;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.t-meta {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.t-msg {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 0.76rem;
  line-height: 1.4;
  word-break: break-all;
}

/* 작업 설정 패널의 남는 높이를 최근 작업 목록이 채운다. */
.recent {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.recent-head h3 { margin: 0; font-size: 0.95rem; }

.app-shell .recent-head button {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.recent-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 6px;
}

.recent-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
}

.recent-title {
  font-weight: 600;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-sub {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  color: var(--muted);
  font-size: 0.75rem;
  min-width: 0;
}

.recent-sub-text {
  flex: 1 1 auto;
  min-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 색만으로 구분하지 않도록 아이콘과 단어를 함께 표시한다. */
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  background: #f8fafc;
  color: #475569;
}

.chip.ok { background: var(--ok-bg); color: #065f46; border-color: #a7f3d0; }
.chip.bad { background: var(--error-bg); color: var(--danger); border-color: #fecaca; }
.chip.run { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.recent-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 6px 2px;
}

.badge {
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  background: #e2e8f0;
  color: #334155;
}

.badge.ok { background: var(--ok-bg); color: #065f46; }
.badge.bad { background: var(--error-bg); color: var(--danger); }
.badge.warn { background: #fffbeb; color: #92400e; }
.badge.run { background: #eff6ff; color: #1d4ed8; }

.bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s ease;
}

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}
