:root {
  color-scheme: light;
  --ink: #17221d;
  --muted: #637068;
  --line: #dce4df;
  --line-strong: #c9d4cd;
  --surface: #ffffff;
  --surface-soft: #f6f8f6;
  --canvas: #edf1ee;
  --green: #174f3d;
  --green-hover: #0f3e2f;
  --green-soft: #e8f1ed;
  --gold: #c8a96a;
  --danger: #a33a3a;
  --shadow: 0 16px 42px rgba(28, 46, 37, 0.12);
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: var(--canvas);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

[hidden] {
  display: none !important;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-outline-button {
  min-height: 40px;
  border-radius: 9px;
  padding: 0 16px;
  border: 1px solid transparent;
  font-weight: 750;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

.primary-button {
  color: #fff;
  background: var(--green);
}

.primary-button:hover:not(:disabled) {
  background: var(--green-hover);
  transform: translateY(-1px);
}

.secondary-button {
  color: var(--green);
  border-color: #afc4ba;
  background: var(--green-soft);
}

.secondary-button:hover {
  border-color: var(--green);
}

.ghost-button {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--surface);
}

.ghost-button:hover {
  background: var(--surface-soft);
}

.ghost-button.compact {
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
}

.danger-outline-button {
  min-height: 36px;
  color: var(--danger);
  border-color: #ddb6b6;
  background: #fffafa;
  font-size: 12px;
}

.danger-outline-button:hover {
  border-color: var(--danger);
  background: #fff2f2;
}

/* Login */
.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 18% 12%, rgba(200, 169, 106, 0.2), transparent 27rem),
    linear-gradient(145deg, #e8eeea, #f6f4ee 68%, #e2ebe6);
}

.login-card {
  width: min(440px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  padding: 42px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand-mark,
.mini-brand {
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--green);
  font-family: Georgia, serif;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.brand-mark {
  width: 52px;
  height: 52px;
  margin-bottom: 26px;
  border-radius: 14px;
  font-size: 25px;
}

.login-card h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: -0.04em;
}

.login-description {
  margin: 10px 0 30px;
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 750;
}

.login-form input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0 14px;
  outline: none;
  background: #fff;
}

.login-form input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 79, 61, 0.12);
}

.login-form .primary-button {
  margin-top: 14px;
  min-height: 48px;
}

.form-error {
  margin: 6px 0 0;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}

.maintenance-card {
  text-align: left;
}

.maintenance-message {
  margin: 22px 0 28px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
  word-break: keep-all;
}

.maintenance-logout {
  width: 100%;
}

/* Main layout */
.editor-page {
  height: 100vh;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.96);
}

.topbar-title,
.session-actions {
  display: flex;
  align-items: center;
}

.topbar-title {
  gap: 12px;
}

.mini-brand {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.03em;
}

.session-actions {
  gap: 10px;
}

.user-chip {
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 13px;
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(520px, 47%) minmax(520px, 53%);
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - 72px);
  min-height: 0;
  min-width: 1040px;
  overflow: hidden;
}

.file-panel,
.editor-panel {
  min-height: 0;
  min-width: 0;
  background: var(--surface);
}

.file-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--line-strong);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px 18px;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 18px;
}

.admin-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.service-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  gap: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 5px 9px;
  background: var(--surface-soft);
  cursor: pointer;
  user-select: none;
}

.service-toggle-copy {
  display: grid;
  gap: 1px;
  font-size: 10px;
  line-height: 1.2;
  text-align: right;
}

.service-toggle-copy strong {
  font-size: 11px;
}

.service-toggle-copy > span {
  color: var(--muted);
}

.service-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #aeb9b3;
  transition: background 140ms ease;
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(23, 34, 29, 0.25);
  transition: transform 140ms ease;
}

.service-toggle input:checked + .toggle-track {
  background: var(--green);
}

.service-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}

.service-toggle input:focus-visible + .toggle-track {
  outline: 3px solid rgba(23, 79, 61, 0.2);
  outline-offset: 2px;
}

.service-toggle:has(input:disabled) {
  cursor: wait;
  opacity: 0.65;
}

.compact-admin-button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 12px;
}

.count-badge {
  display: inline-flex;
  vertical-align: 2px;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  margin-left: 4px;
  border-radius: 999px;
  padding: 0 8px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
}

.notice {
  padding: 9px 16px;
  border-bottom: 1px solid #edc8c8;
  color: #7e2929;
  background: #fff2f2;
  font-size: 12px;
}

.table-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.file-table {
  width: 100%;
  min-width: 819px;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 12px;
}

.file-table th {
  position: sticky;
  z-index: 2;
  top: 0;
  height: 43px;
  border-bottom: 1px solid var(--line-strong);
  border-right: 1px solid var(--line);
  padding: 0;
  text-align: left;
  background: #f4f7f5;
}

.file-table th:nth-child(1) { width: 127px; }
.file-table th:nth-child(2) { width: 47px; }
.file-table th:nth-child(3) { width: 280px; }
.file-table th:nth-child(4) { width: 130px; }
.file-table th:nth-child(5) { width: 130px; }
.file-table th:nth-child(6) { width: 105px; }

.file-table th button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0 10px;
  color: #39463f;
  background: transparent;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.file-table th button:hover {
  background: #eaf0ec;
}

.file-table th:nth-child(2) button {
  gap: 2px;
  padding: 0 5px;
  font-size: 10px;
}

.sort-mark {
  color: #819087;
  font-size: 12px;
}

.file-table td {
  height: 60px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid #edf1ee;
  padding: 9px 10px;
  overflow: hidden;
  color: #3e4a44;
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.file-table td:nth-child(2),
.file-table td:nth-child(3) {
  white-space: normal;
  line-height: 1.4;
}

.file-table td:nth-child(3) {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.file-table tr {
  outline: none;
  cursor: pointer;
}

.file-table tbody tr:hover td,
.file-table tbody tr:focus td {
  background: #f1f6f3;
}

.file-table tr.selected td {
  background: var(--green-soft);
}

.file-table tr.selected td:first-child {
  box-shadow: inset 4px 0 0 var(--green);
}

.file-table tr.locked:not(.selected) td {
  background: #faf9f5;
}

.file-table td strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
}

.file-name-line {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lock-badge {
  display: inline-block;
  margin-top: 5px;
  border-radius: 999px;
  padding: 3px 7px;
  color: #765718;
  background: #f7eac8;
  font-size: 10px;
  font-weight: 750;
}

.table-empty {
  padding: 50px 20px;
  color: var(--muted);
  text-align: center;
}

/* Editor */
.editor-panel {
  position: relative;
  overflow-y: auto;
  background: var(--surface-soft);
}

.editor-empty {
  display: grid;
  min-height: 100%;
  place-content: center;
  padding: 40px;
  color: var(--muted);
  text-align: center;
}

.editor-empty h2 {
  margin: 12px 0 7px;
  color: var(--ink);
  font-size: 22px;
}

.editor-empty p {
  margin: 0;
}

.empty-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto;
  border: 1px solid #b8cbc1;
  border-radius: 16px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 28px;
  line-height: 50px;
}

.editor-toolbar {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 12px 20px;
  gap: 18px;
  border-bottom: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
}

.active-file {
  min-width: 0;
}

.active-file h2 {
  margin: 0;
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-status {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-status[data-tone="dirty"] { color: #9b6713; }
.editor-status[data-tone="success"] { color: #18704f; }
.editor-status[data-tone="error"] { color: var(--danger); }

.toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
}

.preference-control {
  display: grid;
  grid-template-columns: auto 28px 42px 28px;
  align-items: center;
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
}

.preference-control > span {
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.preference-control button {
  height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--green);
  background: #f8faf8;
  font-size: 16px;
  font-weight: 800;
}

.preference-control button:hover:not(:disabled) {
  background: var(--green-soft);
}

.preference-control output {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
}

.save-button {
  min-height: 38px;
}

.rules-button {
  color: var(--green);
  white-space: nowrap;
}

.editor-form {
  --editor-font-size: 16px;
  --editor-line-height: 1.7;
  --level-2-title-color: #2563eb;
  --level-3-title-color: #172554;
  --level-2-indent: 24px;
  --level-3-indent: 48px;
  display: grid;
  gap: 14px;
  padding: 20px;
}

.field-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(32, 48, 40, 0.035);
}

.field-label {
  display: block;
  margin-bottom: 9px;
  color: #344139;
  font-size: 13px;
  font-weight: 850;
}

.category-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.category-card .field-label {
  margin-bottom: 5px;
}

.category-value {
  color: var(--green);
  font-size: 14px;
  line-height: 1.5;
}

.editable-control {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 12px 13px;
  color: #202b25;
  outline: none;
  background: #fcfdfc;
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.editable-control:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 79, 61, 0.1);
  background: #fff;
}

.title-input {
  min-height: 48px;
  font-weight: 700;
}

textarea.editable-control {
  display: block;
  min-height: 86px;
  overflow: hidden;
  resize: none;
  white-space: pre-wrap;
}

.section-syntax-editor {
  display: block;
  min-height: 86px;
  overflow: hidden;
  cursor: text;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.section-syntax-line {
  min-height: 1.2em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.section-syntax-line.syntax-level-2 {
  padding-left: var(--level-2-indent);
}

.section-syntax-line.syntax-level-3 {
  padding-left: var(--level-3-indent);
}

.section-syntax-line.syntax-title-level-2 {
  color: var(--level-2-title-color);
  font-weight: 800;
}

.section-syntax-line.syntax-title-level-3 {
  color: var(--level-3-title-color);
  font-weight: 800;
}

.block-section .field-label {
  color: var(--green);
  font-size: 15px;
}

.block-editor_summary {
  border-left: 4px solid var(--gold);
}

.block-box {
  border-color: #d9c99f;
  background: #fffdf8;
}

.block-box .field-label {
  color: #80642e;
}

/* Dialogs */
.app-dialog {
  width: min(620px, calc(100vw - 36px));
  max-height: min(720px, calc(100vh - 36px));
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(18, 35, 27, 0.28);
}

.app-dialog::backdrop {
  background: rgba(17, 29, 23, 0.48);
  backdrop-filter: blur(2px);
}

.app-dialog form {
  padding: 22px;
}

.dialog-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.dialog-heading h2 {
  margin: 0;
  font-size: 21px;
}

.dialog-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 24px;
  line-height: 1;
}

.dialog-description {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.category-options {
  display: grid;
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.category-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  line-height: 1.45;
}

.category-option:last-child {
  border-bottom: 0;
}

.category-option:hover {
  background: var(--surface-soft);
}

.category-option:has(input:checked) {
  color: var(--green);
  background: var(--green-soft);
  font-weight: 750;
}

.category-option input {
  margin-top: 3px;
  accent-color: var(--green);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.message-dialog {
  width: min(440px, calc(100vw - 36px));
}

.message-text {
  margin: 20px 0 0;
  color: #455149;
  line-height: 1.7;
  white-space: pre-wrap;
}

/* Rules */
.rules-page {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(232, 241, 237, 0.75), transparent 260px),
    var(--canvas);
}

.rules-header {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 16px max(24px, calc((100vw - 900px) / 2));
  gap: 20px;
  border-bottom: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(9px);
}

.rules-header h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.03em;
}

.rules-document {
  display: grid;
  width: min(900px, calc(100% - 32px));
  margin: 28px auto 60px;
  gap: 14px;
}

.rule-section {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  background: var(--surface);
  box-shadow: 0 3px 12px rgba(30, 48, 39, 0.045);
}

.rule-section.priority-rule {
  border-top: 4px solid var(--green);
}

.rule-number {
  display: grid;
  width: 44px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.rule-section h2 {
  margin: 1px 0 14px;
  font-size: 20px;
  letter-spacing: -0.025em;
}

.rule-section p,
.rule-section li {
  color: #46534c;
  font-size: 14px;
  line-height: 1.75;
}

.rule-section p {
  margin: 10px 0;
}

.rule-section ul {
  margin: 14px 0;
  padding-left: 22px;
}

.rule-section code {
  border-radius: 5px;
  padding: 2px 5px;
  color: #164735;
  background: #edf4f0;
  font-family: Consolas, "D2Coding", monospace;
  font-size: 0.94em;
}

.rule-section > div > pre {
  overflow-x: auto;
  border: 1px solid #cad9d1;
  border-radius: 10px;
  padding: 14px;
  background: #f3f7f4;
}

.rule-section pre code {
  padding: 0;
  background: transparent;
  white-space: pre;
}

.rule-example {
  display: grid;
  gap: 7px;
  margin: 16px 0;
  border-left: 4px solid var(--gold);
  border-radius: 8px;
  padding: 14px 16px;
  background: #fffaf0;
  color: #574c38;
  font-size: 13px;
  line-height: 1.65;
}

.rule-example pre {
  margin: 4px 0 0;
  overflow-x: auto;
}

.rule-example pre code {
  color: #443d30;
  background: transparent;
}

.parsing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 18px 0;
}

.parsing-grid article {
  display: grid;
  align-content: start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface-soft);
}

.parsing-grid article > code {
  justify-self: start;
  font-size: 13px;
}

.parsing-grid article strong {
  color: var(--green);
  font-size: 13px;
}

.parsing-grid article p {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 1260px) {
  .workspace {
    grid-template-columns: 48% 52%;
  }

  .editor-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 700px) {
  .rules-header {
    padding: 14px 16px;
  }

  .rule-section {
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .parsing-grid {
    grid-template-columns: 1fr;
  }
}
