:root {
  --purple: #735bf6;
  --purple-dark: #5d48d9;
  --bg: #fafaf9;
  --surface: #ffffff;
  --border: #e5e5e5;
  --text: #1a1a1a;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #10b981;
  --warning: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
}

body { min-height: 100vh; }

a { color: var(--purple); }

button {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  padding: 8px 14px;
  border-radius: 6px;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
button:hover { border-color: var(--purple); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.primary {
  background: var(--purple);
  color: white;
  border-color: var(--purple);
  font-weight: 600;
}
button.primary:hover { background: var(--purple-dark); border-color: var(--purple-dark); }
button.danger { color: var(--danger); border-color: var(--danger); }

input, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--purple); outline-offset: -1px; border-color: var(--purple); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }

/* --- Login --- */
.login-wrap {
  max-width: 420px;
  margin: 12vh auto;
  background: var(--surface);
  padding: 40px 32px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.login-wrap h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
}
.login-wrap .sub {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 14px;
}
.login-wrap label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
}
.login-wrap .row { margin-bottom: 16px; }
.login-wrap button { width: 100%; padding: 12px; font-weight: 600; }
.login-wrap .msg {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13px;
}
.login-wrap .msg.info { background: #eff6ff; color: #1e40af; }
.login-wrap .msg.err { background: #fef2f2; color: var(--danger); }

/* --- Page picker --- */
.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
}
.sidebar h2 {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 20px 0 8px;
}
.sidebar h2:first-child { margin-top: 0; }
.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 24px;
  color: var(--purple);
}
.sidebar .me {
  font-size: 12px;
  color: var(--muted);
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.sidebar .me button {
  margin-top: 8px;
  font-size: 12px;
  padding: 4px 8px;
  width: 100%;
}
.page-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 2px;
  cursor: pointer;
}
.page-btn:hover { background: #f3f4f6; }
.page-btn.active { background: #f3f0ff; color: var(--purple); font-weight: 600; }
.page-btn .legal-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  font-weight: 600;
}

/* --- Editor pane --- */
.editor {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}
.toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.toolbar .title { font-weight: 700; font-size: 16px; flex: 1; }
.toolbar .status {
  font-size: 12px;
  color: var(--muted);
  padding: 4px 10px;
  background: #f3f4f6;
  border-radius: 999px;
}
.toolbar .status.dirty { background: #fef3c7; color: #92400e; }
.toolbar .status.saving { background: #dbeafe; color: #1e40af; }
.toolbar .status.saved { background: #d1fae5; color: #065f46; }
.toolbar .status.error { background: #fee2e2; color: var(--danger); }

.editor-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}
.fields {
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
}
.preview {
  border-left: 1px solid var(--border);
  background: #000;
  position: relative;
}
.preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}
.preview .preview-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 6px 12px;
  font-size: 11px;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
}
.preview select {
  background: white;
  color: var(--text);
  border: 0;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
}

/* --- Language picker --- */
.lang-picker-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; margin-bottom: 6px; }
.lang-picker { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.lang-btn { padding: 6px 12px; font-size: 12px; font-weight: 600; border-radius: 999px; background: white; }
.lang-btn.active { background: var(--purple); color: white; border-color: var(--purple); }
.lang-btn:not(.active):hover { background: #f3f0ff; }

.editor-controls { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; position: sticky; top: 0; background: var(--bg); padding-bottom: 8px; z-index: 5; }
.editor-controls input[type="search"] { flex: 1; }
.stale-toggle { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; white-space: nowrap; cursor: pointer; }
.stale-toggle input { width: auto; margin: 0; }

/* --- i18n key card --- */
.i18n-key {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
}
.i18n-key.stale { border-color: var(--warning); box-shadow: 0 0 0 1px var(--warning); }
.i18n-key.dirty { border-color: var(--purple); }
.i18n-key.verified-now { border-color: var(--success); }

.i18n-key-head {
  padding: 8px 14px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.i18n-key-head .key-name {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.stale-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.i18n-reference {
  display: grid;
  grid-template-columns: 60px 1fr;
  border-bottom: 1px dashed #e5e5e5;
  background: #fafafa;
}
.i18n-reference .ref-label {
  padding: 10px 12px;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}
.i18n-reference .ref-text {
  padding: 10px 12px;
  font-size: 13px;
  color: #374151;
  white-space: pre-wrap;
}

.i18n-edit-row {
  display: grid;
  grid-template-columns: 60px 1fr;
  align-items: stretch;
}
.i18n-edit-row .lang {
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--purple);
  background: #f3f0ff;
  display: flex;
  align-items: center;
}
.i18n-edit-row textarea {
  border: 0;
  border-radius: 0;
  padding: 10px 12px;
  min-height: 40px;
  background: white;
  font-size: 13px;
}
.i18n-edit-row textarea:focus { outline: 2px solid var(--purple); outline-offset: -2px; }
.i18n-key.dirty .i18n-edit-row textarea { background: #fffbeb; }

.i18n-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f9fafb;
  border-top: 1px solid #f3f4f6;
  font-size: 11px;
  color: var(--muted);
}
.verify-btn {
  padding: 3px 10px;
  font-size: 11px;
  background: white;
  color: var(--success);
  border-color: var(--success);
  border-radius: 4px;
  font-weight: 600;
}
.verify-btn:hover { background: var(--success); color: white; }
.verified-now-tag { color: var(--success); font-weight: 600; }

/* --- Legal block editor --- */
.legal-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  padding: 12px 14px;
}
.legal-block .meta {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.legal-block textarea { min-height: 60px; font-size: 13px; }
.legal-block.dirty { border-color: var(--warning); background: #fffbeb; }

/* --- Legal confirmation modal --- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: white;
  border-radius: 12px;
  padding: 28px;
  max-width: 480px;
  width: 100%;
}
.modal h2 { margin-top: 0; font-size: 18px; color: var(--danger); }
.modal p { color: var(--muted); }
.modal .actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

.search-box {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 0 0 12px;
}
.search-box input { width: 100%; }
