:root {
  color-scheme: light dark;
  --bg: #eef1f6;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #5e6b7b;
  --line: #d9dfe8;
  --field: #f5f7fa;
  --brand: #0b4a8f;
  --brand-2: #1266c4;
  --brand-ink: #ffffff;
  --accent: #0b64c8;
  --ok: #1a7f37;
  --warn: #9a6700;
  --error: #c0362c;
  --shadow: 0 10px 30px rgba(20, 40, 70, .10);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141c;
    --panel: #161e29;
    --ink: #e7ecf2;
    --muted: #9aa7b6;
    --line: #273040;
    --field: #0f1620;
    --brand: #0b3f78;
    --brand-2: #10528f;
    --brand-ink: #eaf2ff;
    --accent: #4aa0f5;
    --ok: #3fb950;
    --warn: #d29922;
    --error: #f0837a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  }
}

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

html, body { height: 100%; margin: 0; }

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

.logo { width: 1.6em; height: 1.6em; flex: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: .2px;
}
.brand.small { font-size: 16px; }

/* ---------- Login ---------- */
.login-layout {
  min-height: 100%;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}

.brand-panel {
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-2) 100%);
  color: var(--brand-ink);
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand-panel .brand { font-size: 20px; }
.brand-copy h2 { font-size: 30px; line-height: 1.2; margin: 0 0 10px; }
.brand-copy p { margin: 0; opacity: .9; max-width: 44ch; }
.brand-points { margin: auto 0 0; padding: 0; list-style: none; display: grid; gap: 12px; }
.brand-points li { position: relative; padding-left: 26px; opacity: .95; }
.brand-points li::before {
  content: "✓"; position: absolute; left: 0; top: -1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(255, 255, 255, .18); font-size: 12px; text-align: center; line-height: 18px;
}

.login-main { display: flex; align-items: center; justify-content: center; padding: 24px; }

.login-card { width: 100%; max-width: 380px; }
.login-card h1 { font-size: 24px; margin: 0 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }

label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font-size: 15px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

button {
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
button:hover { filter: brightness(1.05); }
button:disabled { opacity: .55; cursor: progress; }
button.secondary { background: var(--panel); color: var(--ink); border-color: var(--line); }
button.ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 7px 12px; }
button.ghost:hover { color: var(--ink); }

#login-button { width: 100%; margin-top: 22px; }

.foot { color: var(--muted); font-size: 12px; margin-top: 20px; text-align: center; }

/* ---------- App / editor ---------- */
.app-shell { min-height: 100%; display: flex; flex-direction: column; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.header-actions { display: flex; align-items: center; gap: 14px; }
.meta { color: var(--muted); font-size: 12px; }

.app-main { flex: 1; display: flex; justify-content: center; padding: 20px; }

.panel {
  width: 100%; max-width: 920px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; font-size: 18px; }
.hint { color: var(--muted); font-size: 13px; }

textarea {
  width: 100%; min-height: 48vh; resize: vertical;
  padding: 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--field); color: var(--ink);
  font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  tab-size: 4;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.message { min-height: 1.4em; margin: 2px 0 0; white-space: pre-line; font-size: 14px; }
.message.ok { color: var(--ok); }
.message.warn { color: var(--warn); }
.message.error { color: var(--error); }

@media (max-width: 820px) {
  .login-layout { grid-template-columns: 1fr; }
  .brand-panel { padding: 28px 24px; gap: 18px; }
  .brand-copy h2 { font-size: 24px; }
  .brand-points { margin: 4px 0 0; }
}

/* ---------- Workspace ---------- */
.workspace { height: 100%; display: flex; flex-direction: column; position: relative; }
.ws-body { flex: 1; display: grid; grid-template-columns: 260px 1fr; min-height: 0; }

.explorer {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex; flex-direction: column; min-height: 0;
}
.explorer-tools { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.explorer-tools button { padding: 6px 10px; font-size: 13px; }

.tree { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; }
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.node { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; cursor: pointer; user-select: none; }
.node:hover { background: var(--field); }
.node.active { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.node .nname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.node .nicon { width: 16px; text-align: center; opacity: .8; flex: none; }
.node .nact { opacity: 0; display: flex; gap: 2px; }
.node:hover .nact { opacity: 1; }
.node .nact button { background: transparent; border: none; color: var(--muted); padding: 2px 5px; font-size: 12px; cursor: pointer; border-radius: 4px; }
.node .nact button:hover { color: var(--ink); background: var(--bg); }

.ws-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 6px 8px 0; border-bottom: 1px solid var(--line); overflow-x: auto; background: var(--panel); }
.tab { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; background: var(--field); color: var(--muted); cursor: pointer; font-size: 13px; white-space: nowrap; }
.tab.active { background: var(--panel); color: var(--ink); }
.tab .dot { color: var(--warn); }
.tab .x { border: none; background: transparent; color: inherit; cursor: pointer; font-size: 14px; padding: 0 2px; }

.editor-host { flex: 1; min-height: 0; overflow: auto; }
.editor-host .cm-editor { height: 100%; }
.editor-host .cm-scroller { font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.binary-panel { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; }
.empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); }

.ws-actions { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.message.small { font-size: 12px; padding: 0 10px 8px; }

.drop-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border: 3px dashed var(--accent); color: var(--ink); font-size: 20px; font-weight: 700; z-index: 10;
}

.file-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.file-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; gap: 6px; flex: none; }
.file-actions .icon { padding: 6px 10px; font-size: 13px; background: var(--field); color: var(--ink); border: 1px solid var(--line); }
.file-actions .icon:hover { background: var(--bg); }
#save-button { background: var(--accent); color: #fff; border-color: transparent; }

.preview-host { flex: 1; min-height: 0; overflow: auto; padding: 20px 28px; }
.media-host { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--field); }
.media-host img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

.ws-msg { padding: 8px 14px; margin: 0; border-top: 1px solid var(--line); }

/* Markdown render */
.markdown-body { line-height: 1.6; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1.2em 0 .5em; line-height: 1.25; }
.markdown-body h1 { font-size: 1.7em; border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.markdown-body h2 { font-size: 1.4em; border-bottom: 1px solid var(--line); padding-bottom: .2em; }
.markdown-body p, .markdown-body ul, .markdown-body ol, .markdown-body blockquote, .markdown-body pre, .markdown-body table { margin: .6em 0; }
.markdown-body code { background: var(--field); padding: .15em .4em; border-radius: 4px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .9em; }
.markdown-body pre { background: var(--field); padding: 12px 14px; border-radius: 8px; overflow: auto; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote { border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); }
.markdown-body a { color: var(--accent); }
.markdown-body table { border-collapse: collapse; }
.markdown-body th, .markdown-body td { border: 1px solid var(--line); padding: 6px 10px; }
.markdown-body img { max-width: 100%; }

/* Barra de progresso de upload */
.upload-progress { padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.up-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.up-track { height: 8px; background: var(--field); border-radius: 999px; overflow: hidden; }
.up-bar { height: 100%; width: 0%; background: var(--accent); transition: width .15s ease; }

@media (max-width: 820px) {
  .ws-body { grid-template-columns: 1fr; }
  .explorer { max-height: 38vh; }
}
