:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #657181;
  --line: #d8dee7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #e6f4f1;
  --warn: #9a3412;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button, input { font: inherit; }

.shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }

.topbar { border-bottom: 1px solid var(--line); background: var(--panel); }
.topbar-inner {
  max-width: 1440px; margin: 0 auto; padding: 16px 24px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.brand h1 { margin: 0; font-size: 19px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 13px; max-width: 720px; }
.badge {
  border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; white-space: nowrap; font-weight: 500;
}

.workspace {
  max-width: 1440px; width: 100%; margin: 0 auto; padding: 20px 24px 36px;
  display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px;
}

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }

.sidebar { align-self: start; position: sticky; top: 16px; padding: 16px; display: grid; gap: 14px; }

.tabs { display: flex; gap: 6px; background: #eef1f5; padding: 4px; border-radius: 8px; }
.tab {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 6px;
  cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 500;
}
.tab.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.inputblock { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.field.row { grid-template-columns: 1fr auto; align-items: center; }
.field input[type=file] { font-size: 12px; }
.field input[type=number] { width: 110px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); }

.primary, .secondary {
  border: 0; border-radius: 7px; padding: 10px 12px; cursor: pointer; font-weight: 600; font-size: 13px;
}
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: .5; cursor: not-allowed; }
.secondary { background: var(--accent-soft); color: var(--accent-dark); }
.secondary:hover { background: #d7ece8; }

.controls { border-top: 1px solid var(--line); padding-top: 14px; display: grid; gap: 10px; }
.controls h3 { margin: 0; font-size: 14px; }
.views { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
.download {
  display: inline-block; margin-top: 4px; color: var(--accent-dark); font-weight: 600;
  font-size: 13px; text-decoration: none; padding: 8px 0;
}
.download:hover { text-decoration: underline; }

.meta { color: var(--muted); font-size: 12px; line-height: 1.5; }
.error { color: var(--warn); font-size: 13px; line-height: 1.5; }

.main { display: grid; gap: 20px; min-width: 0; align-content: start; }
.empty { padding: 56px 24px; text-align: center; color: var(--muted); }

.section { padding: 16px; border-top: 1px solid var(--line); }
.section:first-child { border-top: 0; }
.section h2, .section h3 { margin: 0 0 10px; font-size: 15px; }
.tag { font-size: 11px; background: var(--accent-soft); color: var(--accent-dark); padding: 2px 8px; border-radius: 999px; font-weight: 500; }
.summary { margin: 0; line-height: 1.6; }
.list { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.6; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 0; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td:first-child, td:nth-child(4) { white-space: normal; overflow-wrap: anywhere; }
th { color: var(--muted); font-weight: 500; }

.chat { display: flex; flex-direction: column; min-height: 380px; }
.chat-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.chat-head h3 { margin: 0; font-size: 15px; }
.chat-log { flex: 1; min-height: 220px; max-height: 56vh; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { padding: 9px 13px; border-radius: 12px; font-size: 13px; line-height: 1.55; max-width: 84%; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble.assistant { background: #eef1f5; color: var(--ink); align-self: flex-start; border-bottom-left-radius: 4px; }
.system-note { align-self: center; font-size: 12px; color: var(--accent-dark); background: var(--accent-soft); padding: 6px 12px; border-radius: 999px; }
.system-note a { color: var(--accent-dark); font-weight: 600; }
.chat-input { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.chat-input input { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--ink); }

.hidden { display: none !important; }

/* ---- 사용자바 / 링크 버튼 ---- */
.userbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.userbar #whoami { font-weight: 600; color: var(--ink); }
.linkbtn {
  border: 1px solid var(--line); background: var(--panel); color: var(--accent-dark);
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.linkbtn:hover { background: var(--accent-soft); }

/* ---- 로그인 / 회원가입 카드 ---- */
.auth-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px 26px; box-shadow: 0 6px 24px rgba(17,32,42,.06);
}
.auth-card h1 { margin: 0 0 4px; font-size: 20px; }
.auth-sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.auth-form { display: grid; gap: 14px; }
.auth-form .field span { font-weight: 500; }
.auth-form input[type=text], .auth-form input[type=password],
.code-form input[type=text] {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--ink);
}
.auth-form .hint { color: var(--muted); font-size: 11px; }
.auth-form .primary { margin-top: 4px; }
.auth-foot { margin: 16px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.auth-foot a { color: var(--accent-dark); font-weight: 600; }
.auth-notice {
  margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; font-size: 13px; line-height: 1.5;
  background: #fef3c7; color: #92400e; border: 1px solid #fcd9a3;
}
.auth-notice.ok { background: var(--accent-soft); color: var(--accent-dark); border-color: #bfe3dc; }

/* ---- 관리자 패널 ---- */
.admin-main { display: grid; grid-template-columns: 1fr; gap: 20px; align-content: start; }
.admin-main .panel { padding: 16px 18px; }
.admin-main .panel h3 { margin: 0 0 6px; font-size: 15px; }
.code-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.code-form input { min-width: 200px; }
.admin-table th, .admin-table td { vertical-align: middle; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.role-admin { background: #ede9fe; color: #5b21b6; }
.role-user { background: #eef1f5; color: var(--muted); }
.st-approved { background: var(--accent-soft); color: var(--accent-dark); }
.st-pending { background: #fef3c7; color: #92400e; }
.st-disabled { background: #f3f4f6; color: #6b7280; }
.st-rejected { background: #fee2e2; color: #b91c1c; }
.rowactions { white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; }
.rowbtn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer; font-weight: 500;
}
.rowbtn:hover { background: #f1f4f7; }
.rowbtn:disabled { opacity: .5; cursor: not-allowed; }
.rowbtn.ok { color: var(--accent-dark); border-color: #bfe3dc; }
.rowbtn.warn { color: var(--warn); border-color: #f0c9a8; }
.rowbtn.danger { color: #b91c1c; border-color: #f3b4b4; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}
