:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #d9e1ec;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #1f5f99;
  --primary-dark: #164a78;
  --danger: #b42318;
  --soft: #eef5fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  font-size: 13px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background: #eef2f7;
}

.login-panel {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 40px;
  align-items: center;
  padding: 48px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

.login-panel h1 {
  margin: 8px 0 14px;
  font-size: 34px;
}

.eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.primary,
.ghost,
.button-link {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 11px;
  font-weight: 700;
  text-decoration: none;
  font-size: 12px;
}

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

.primary:hover {
  background: var(--primary-dark);
}

.ghost,
.button-link {
  color: var(--primary);
  background: #fff;
  border-color: var(--line);
}

.error {
  min-height: 20px;
  color: var(--danger);
  margin: 0;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.sidebar {
  background: #1f2937;
  color: #fff;
  padding: 16px 12px;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong {
  font-size: 17px;
}

.brand span {
  color: #bac4d2;
  font-size: 13px;
}

.sidebar nav {
  display: grid;
  gap: 4px;
  margin-top: 14px;
}

.sidebar button {
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  color: #dbe4ef;
  background: transparent;
  text-align: left;
}

.sidebar button.active,
.sidebar button:hover {
  color: #fff;
  background: #315778;
}

.workspace {
  min-width: 0;
  padding: 16px 20px 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: 20px;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stats-grid article,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-grid article {
  padding: 12px 14px;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.stats-grid strong {
  font-size: 24px;
}

.panel {
  padding: 12px;
}

.toc-panel {
  margin-top: 12px;
}

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

.panel-actions {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.panel h3 {
  margin: 0 0 9px;
  font-size: 15px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 180px 160px auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 10px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

th {
  background: #f8fafc;
  color: #334155;
  font-weight: 800;
  white-space: nowrap;
}

tr:hover td {
  background: #fbfdff;
}

.document-list-wrap {
  border-radius: 0;
}

.document-list-table {
  min-width: 1040px;
  table-layout: fixed;
}

.document-list-table th,
.document-list-table td {
  height: 35px;
  padding: 0 8px;
  border-right: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.25;
  vertical-align: middle;
  white-space: nowrap;
}

.document-list-table th {
  height: 36px;
  background: #eef3f8;
  color: #0f172a;
  font-weight: 800;
  text-align: center;
}

.document-list-table td {
  overflow: hidden;
  text-overflow: ellipsis;
}

.document-list-table th:nth-child(1),
.document-list-table td:nth-child(1) {
  width: 90px;
}

.document-list-table th:nth-child(2),
.document-list-table td:nth-child(2) {
  width: 110px;
}

.document-list-table th:nth-child(3),
.document-list-table td:nth-child(3) {
  width: 340px;
}

.document-list-table th:nth-child(4),
.document-list-table td:nth-child(4) {
  width: 80px;
}

.document-list-table th:nth-child(5),
.document-list-table td:nth-child(5),
.document-list-table th:nth-child(6),
.document-list-table td:nth-child(6) {
  width: 100px;
}

.document-list-table th:nth-child(7),
.document-list-table td:nth-child(7) {
  width: 110px;
}

.document-list-table th:nth-child(8),
.document-list-table td:nth-child(8) {
  width: 90px;
}

.document-list-table th:nth-child(9),
.document-list-table td:nth-child(9) {
  width: 70px;
}

.document-list-table th:last-child,
.document-list-table td:last-child {
  border-right: 0;
  text-align: center;
}

.document-list-table td:nth-child(2),
.document-list-table td:nth-child(4),
.document-list-table td:nth-child(5),
.document-list-table td:nth-child(6),
.document-list-table td:nth-child(8) {
  text-align: center;
}

.document-list-table .badge {
  min-width: 50px;
  padding: 3px 8px;
  font-size: 10px;
}

.document-list-table .ghost {
  min-width: 42px;
  padding: 4px 8px;
  font-size: 11px;
}

.badge {
  display: inline-flex;
  min-width: 54px;
  justify-content: center;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 800;
  font-size: 11px;
}

.badge.danger {
  background: #fff1f0;
  color: var(--danger);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.wide,
.form-actions,
.message {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.revision-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  background: #eff6ff;
  color: #1e3a8a;
}

.revision-notice strong {
  white-space: nowrap;
}

.message {
  min-height: 20px;
  margin: 0;
  color: var(--primary);
  font-weight: 700;
}

dialog {
  width: min(1180px, calc(100vw - 56px));
  max-height: calc(100vh - 56px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.small-dialog {
  width: min(560px, calc(100vw - 40px));
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.dialog-head h3 {
  margin: 0;
}

.detail-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.replace-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 132px;
  padding: 16px;
  border: 2px dashed #93c5fd;
  border-radius: 8px;
  background: #f8fbff;
  color: #1f2937;
  cursor: pointer;
  text-align: center;
}

.drop-zone.dragging {
  border-color: var(--primary);
  background: #eff6ff;
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-zone span {
  color: var(--muted);
  font-size: 13px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.info-grid div {
  min-height: 48px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
}

.info-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 2px;
}

.info-grid strong {
  font-size: 12px;
  line-height: 1.35;
  word-break: keep-all;
}

.pdf-frame {
  width: 100%;
  height: 560px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.pdf-js-viewer {
  width: 100%;
  height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef1f4;
}

.pdf-viewer-meta {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
}

.pdf-page-list {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 12px;
}

.pdf-page {
  display: grid;
  justify-items: center;
  gap: 5px;
}

.pdf-page-label {
  color: #475569;
  font-size: 11px;
}

.pdf-page canvas {
  max-width: 100%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.16);
}

.pdf-preview-error {
  margin: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.inline-upload {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 6px 0 10px;
}

.inline-upload input {
  max-width: 420px;
}

.rule-content {
  max-height: 62vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: keep-all;
  line-height: 1.7;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  color: #1f2937;
  font-family: "Malgun Gothic", "Segoe UI", Arial, sans-serif;
  font-size: 12px;
}

.admin-panel p {
  color: var(--muted);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .sidebar nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats-grid,
  .form-grid,
  .login-panel,
  .info-grid {
    grid-template-columns: 1fr;
  }

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