:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1e242c;
  --muted: #66717f;
  --line: #d9dee7;
  --accent: #1769aa;
  --danger: #b42318;
  --ok: #13795b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
}

button:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.danger {
  background: #fff;
  color: var(--danger);
  border-color: #efb5ad;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-panel {
  width: min(380px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 14px;
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

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

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
}

.shell.collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.shell.collapsed .sidebar {
  border-right: 0;
}

.toolbar, .detail-header {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar strong {
  flex: 1;
}

.selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px 8px;
}

.search {
  margin: 0 16px 10px;
}

.folder-bar {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 8px;
  padding: 0 16px 8px;
}

.folder-bar button {
  min-width: 0;
  padding-inline: 8px;
}

.folder-path {
  margin: 0 16px 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #f9fbfd;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  padding: 0 16px 8px;
  font-size: 12px;
}

.feedback, .status, .error {
  color: var(--danger);
}

.feedback {
  padding: 0 16px 8px;
}

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow: auto;
}

.doc-item {
  border-top: 1px solid var(--line);
  padding: 11px 16px;
  cursor: pointer;
}

.doc-item:hover, .doc-item.active {
  background: #eef5fb;
}

.doc-item strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-item span, #doc-path {
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.detail {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.detail-header {
  background: var(--panel);
  justify-content: space-between;
}

.detail-header h2 {
  margin: 0;
  font-size: 18px;
}

.detail-header p {
  margin: 2px 0 0;
}

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

.status {
  min-height: 28px;
  padding: 6px 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.empty {
  margin: auto;
  color: var(--muted);
}

.preview {
  overflow: auto;
  padding: 24px 32px 80px;
  max-width: 980px;
  width: 100%;
}

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  line-height: 1.25;
  margin-top: 1.4em;
  margin-bottom: .4em;
}

.preview h1 { font-size: 1.9em; border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.preview h2 { font-size: 1.5em; border-bottom: 1px solid var(--line); padding-bottom: .2em; }
.preview h3 { font-size: 1.2em; }

.preview p { margin: .6em 0 .8em; }

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

.preview ul, .preview ol {
  padding-left: 1.8em;
  margin: .4em 0 .8em;
}

.preview li { margin: .25em 0; }

.preview li input[type="checkbox"] {
  margin-right: .4em;
}

.preview blockquote {
  margin: .8em 0;
  padding: .4em 1em;
  border-left: 4px solid var(--line);
  color: var(--muted);
  background: #f9fbfd;
  border-radius: 0 4px 4px 0;
}

.preview blockquote p { margin: .2em 0; }

.preview pre, .diff {
  background: #101820;
  color: #e8eef6;
  border-radius: 6px;
  padding: 14px;
  overflow: auto;
}

.preview pre code {
  background: none;
  padding: 0;
  font-size: .9em;
}

.preview code {
  background: #eef1f6;
  color: #c7254e;
  padding: .15em .35em;
  border-radius: 4px;
  font: 87.5%/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.preview table {
  border-collapse: collapse;
  width: 100%;
  margin: .8em 0;
  font-size: .95em;
}

.preview th, .preview td {
  border: 1px solid var(--line);
  padding: 7px 12px;
  text-align: left;
}

.preview th {
  background: #f0f4f8;
  font-weight: 600;
}

.preview tr:nth-child(even) td {
  background: #f9fbfd;
}

.preview hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.5em 0;
}

.preview img {
  max-width: 100%;
  border-radius: 4px;
}

.split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
}

#editor {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  resize: none;
  padding: 18px;
  font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.diff {
  margin: 18px;
  flex: 1;
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 45vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .shell.collapsed .sidebar {
    display: none;
  }
  .split {
    grid-template-columns: 1fr;
  }
  #editor {
    min-height: 40vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

