:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1c2430;
  --muted: #5f6b7a;
  --accent: #2f5bd3;
  --accent-soft: #e6ecfb;
  --ok: #1f7a4d;
  --ok-soft: #e3f4ea;
  --busy: #8a5a00;
  --busy-soft: #fdf1d8;
  --warn: #9a4b00;
  --warn-soft: #fde8d6;
  --error: #b42318;
  --error-soft: #fde7e5;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151a;
    --surface: #1a1f26;
    --surface-2: #232a33;
    --border: #2e3640;
    --text: #e6e9ee;
    --muted: #9aa5b3;
    --accent: #7c9cf0;
    --accent-soft: #23304d;
    --ok: #5cc790;
    --ok-soft: #173326;
    --busy: #e7b24c;
    --busy-soft: #3a2e14;
    --warn: #f0a060;
    --warn-soft: #3d2715;
    --error: #f08377;
    --error-soft: #3d1c1a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); }
.topbar-note { color: var(--muted); font-size: 13px; }

.content { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-header h2 { margin: 0; font-size: 16px; }
.pad { padding: 16px 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.code { font: 600 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--accent); }

.upload { padding: 18px; display: grid; gap: 14px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px 16px;
  text-align: center; cursor: pointer; transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.busy { cursor: progress; opacity: .7; }
.dropzone-icon { font-size: 28px; color: var(--accent); }
.dropzone-title { font-weight: 600; margin: 4px 0; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 6px; font: inherit; font-size: 14px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

.upload-results { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.upload-results li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 8px 12px; border-radius: 8px; }
.result-name { font-weight: 600; overflow-wrap: anywhere; }
.result-created { background: var(--ok-soft); }
.result-duplicate { background: var(--surface-2); }
.result-rejected { background: var(--error-soft); color: var(--error); }

.alert { padding: 10px 14px; border-radius: 8px; margin: 12px 18px; }
.alert-error { background: var(--error-soft); color: var(--error); }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.file-link { font-weight: 600; word-break: break-word; }
.col-file { min-width: 170px; }
.col-doc { min-width: 220px; }
.actions { white-space: nowrap; text-align: right; }
.error-text { color: var(--error); max-width: 280px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-busy { background: var(--busy-soft); color: var(--busy); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-neutral { background: var(--surface-2); color: var(--muted); }
.spinner { width: 10px; height: 10px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn { display: inline-block; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 6px 12px; border-radius: 7px; font: inherit; font-size: 14px; cursor: pointer; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); padding: 4px 8px; }
.btn-ghost.danger { color: var(--error); }
.btn-danger { background: var(--error); border-color: var(--error); color: var(--surface); font-weight: 600; }
.btn-danger:hover { background: var(--error); opacity: .9; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--surface); font-weight: 600; }
.btn-primary:hover { background: var(--accent); opacity: .9; }
.btn:disabled { opacity: .6; cursor: default; }

.narrow { max-width: 480px; width: 100%; justify-self: center; }
.form { display: grid; gap: 12px; }
.form p { margin: 0; }
.field { display: grid; gap: 4px; font-size: 14px; }
.input { font: inherit; font-size: 15px; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 100%; box-sizing: border-box; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.danger-zone { border-color: var(--error); }
.danger-zone .card-header h2 { color: var(--error); }
.danger-body { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.danger-title { font-weight: 600; }

.back { display: inline-block; font-size: 14px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 18px; }
.detail-head h1 { margin: 2px 0 4px; font-size: 22px; }
.detail-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
select { font: inherit; font-size: 14px; padding: 6px 10px; border-radius: 7px; border: 1px solid var(--border); background: var(--surface); color: var(--text); max-width: 100%; }

.sections { padding: 8px 18px 18px; }
.part-title { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.section { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.section-text { background: var(--surface-2); }
.section-header { display: flex; align-items: baseline; gap: 10px; font-size: 13px; }
.section-path { color: var(--muted); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.doc { max-width: 820px; margin: 0 auto; padding: 8px 18px 32px; line-height: 1.6; }
.doc-part { font-size: 18px; margin: 28px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.doc-heading { font-size: 15px; margin: 22px 0 6px; }
.doc-section { position: relative; padding: 2px 10px; margin: 0 -10px; border-radius: 6px; }
.doc-section > .section-link { position: absolute; right: -18px; top: 8px; opacity: 0; }
.doc-section:hover > .section-link { opacity: .6; }
@media (hover: none) { .doc-section > .section-link { opacity: .35; right: -14px; } }
.doc-section.highlight { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.section.highlight { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.section-link { font-size: 13px; opacity: .45; }
.section-link:hover { opacity: 1; text-decoration: none; }
.clause { font: 600 12px ui-monospace, Menlo, monospace; background: var(--accent-soft); color: var(--accent); padding: 1px 7px; border-radius: 5px; }
.amendments summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.amendments pre { white-space: pre-wrap; font-size: 12px; color: var(--muted); margin: 6px 0 0; }

.markdown { overflow-wrap: anywhere; }
.markdown p { margin: 8px 0; }
.markdown table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; }
.markdown td, .markdown th { border: 1px solid var(--border); padding: 4px 8px; vertical-align: top; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .table th:nth-child(3), .table td:nth-child(3), .table th:nth-child(6), .table td:nth-child(6) { display: none; }
}
