:root {
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f7f8fa;
  --sidebar: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --ink: #1f242d;
  --muted: #697381;
  --line: #e2e6eb;
  --line-strong: #ccd3dc;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eaf1ff;
  --good: #16834b;
  --good-soft: #e8f7ef;
  --danger: #c4372d;
  --danger-soft: #fff0ee;
  --input: #ffffff;
  --shadow: 0 24px 80px rgba(31, 36, 45, 0.14);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --sidebar: #171a21;
  --surface: #1c2028;
  --surface-2: #151922;
  --ink: #edf1f7;
  --muted: #a0a8b4;
  --line: #2d333d;
  --line-strong: #424a57;
  --accent: #7aa7ff;
  --accent-strong: #a4c2ff;
  --accent-soft: #1d2d4c;
  --good: #7edca2;
  --good-soft: #183725;
  --danger: #ff8a80;
  --danger-soft: #3d2220;
  --input: #11151d;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  color: var(--ink);
  background: var(--bg);
}

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

button,
a.button-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 13px;
  color: white;
  background: var(--accent);
  text-decoration: none;
  cursor: pointer;
}

button:hover,
a.button-link:hover {
  background: var(--accent-strong);
}

.secondary,
a.button-link.secondary {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.secondary:hover,
a.button-link.secondary:hover {
  color: var(--ink);
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.danger {
  color: var(--danger);
  background: var(--danger-soft);
}

.danger:hover {
  color: white;
  background: var(--danger);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 8px;
  font-size: 26px;
  line-height: 1.2;
}

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

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

.sidebar {
  min-height: 100vh;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.brand {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 6px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: block;
}

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

.mode-nav {
  display: grid;
  gap: 4px;
}

.mode-nav button,
.sidebar-action {
  justify-content: flex-start;
  width: 100%;
  color: var(--ink);
  border-color: transparent;
  background: transparent;
}

.mode-nav button.active {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.sidebar-hint {
  margin-top: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  display: grid;
  gap: 5px;
  font-size: 13px;
  line-height: 1.45;
}

.sidebar-hint strong {
  color: var(--ink);
}

main {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.topbar select {
  width: 180px;
}

.topbar input {
  width: min(440px, 42vw);
}

.session {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

#status,
#userBadge,
.muted {
  color: var(--muted);
}

#status,
#userBadge {
  font-size: 13px;
  white-space: nowrap;
}

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

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

body[data-mode="pages"] .layout {
  grid-template-columns: 280px minmax(0, 1fr);
}

.documents {
  min-height: 0;
  overflow: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.document-card {
  min-height: 72px;
  width: 100%;
  padding: 10px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--ink);
  text-align: left;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
}

.document-card:hover,
.document-card.active {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-2);
}

.file-icon {
  width: 36px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 10px;
  font-weight: 800;
}

.doc-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.doc-main strong,
.doc-main span,
.doc-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-main strong {
  color: var(--ink);
  font-size: 14px;
}

.document-card span,
.document-card small {
  color: var(--muted);
  font-size: 12px;
}

.details {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: var(--bg);
}

.empty {
  min-height: calc(100vh - 58px);
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.detail-header {
  min-height: 96px;
  padding: 24px 34px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.detail-header h2 {
  margin-bottom: 7px;
}

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

.view-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
}

.view-switch button {
  min-height: 30px;
  color: var(--muted);
  border: 0;
  background: transparent;
}

.view-switch button:hover {
  color: var(--ink);
  background: transparent;
}

.view-switch button.active {
  color: white;
  background: var(--accent);
}

.preview {
  height: calc(100vh - 182px);
  min-height: 520px;
  margin: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.office-preview {
  height: calc(100vh - 132px);
  min-height: 620px;
  margin: 0;
  background: var(--surface);
}

.onlyoffice-editor {
  width: 100%;
  height: 100%;
}

.office-launcher {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.office-launcher strong {
  color: var(--ink);
  font-size: 22px;
}

.office-page {
  display: block;
  min-height: 100vh;
  background: var(--surface);
}

.office-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.office-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.office-topbar h1 {
  font-size: 18px;
}

.office-frame {
  min-height: 0;
}

.office-error {
  min-height: calc(100vh - 64px);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
}

.office-error strong {
  color: var(--danger);
}

.preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: white;
}

.preview-placeholder {
  margin: 18px;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  display: grid;
  gap: 6px;
}

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

.panel,
.login-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.version-list,
.audit-list {
  margin: 10px 18px 22px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 5px;
}

.details > h3 {
  margin: 18px 18px 0;
}

.version,
.audit-list li {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.active-version {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 42%, var(--surface));
}

.version {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.version div:first-child,
.audit-list li {
  display: grid;
  gap: 1px;
}

.version strong {
  font-size: 13px;
  line-height: 1.2;
}

.audit-event strong {
  width: max-content;
  padding: 1px 6px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 11px;
  line-height: 1.35;
}

.version span,
.version small,
.audit-event span,
.audit-event small {
  font-size: 11px;
  line-height: 1.25;
}

.audit-event small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.version .actions {
  gap: 4px;
  justify-content: flex-end;
}

.version .actions button,
.version .actions .button-link {
  min-height: 26px;
  padding: 0 8px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 650;
}

.badge {
  min-height: 21px;
  width: max-content;
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border-radius: 999px;
  color: var(--good);
  background: var(--good-soft);
  font-size: 11px;
  font-weight: 700;
}

.secondary-badge {
  margin-left: 8px;
  color: var(--accent);
  background: var(--accent-soft);
}

.page-detail-header {
  min-height: 82px;
  padding: 18px 34px;
}

.page-detail-header h2 {
  font-size: 28px;
}

.page-workspace {
  min-height: calc(100vh - 141px);
  display: block;
  background: var(--surface);
}

.page-editor {
  min-height: calc(100vh - 141px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 30px 38px 52px;
  background: var(--surface);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-meta-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(180px, 0.7fr);
  gap: 12px;
}

label {
  margin-bottom: 12px;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.page-meta-grid label,
.markdown-field {
  margin-bottom: 0;
}

.markdown-field {
  flex: 1;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--ink);
  background: var(--input);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.markdown-edit-shell {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 22px;
  align-items: stretch;
  min-height: 650px;
}

.markdown-source-field {
  margin: 0;
  min-height: 650px;
  display: flex;
  flex-direction: column;
}

.markdown-source {
  flex: 1;
  min-height: 610px;
  padding: 18px 22px;
  border-radius: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 1.35;
  resize: none;
  tab-size: 2;
}

.markdown-preview-panel {
  min-height: 650px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: auto;
}

.preview-label {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-2) 92%, transparent);
  backdrop-filter: blur(10px);
  font-size: 12px;
  font-weight: 750;
}

.markdown-live-editor,
.markdown-reader {
  min-height: 660px;
  width: 100%;
  padding: 28px 0;
  border: 0;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.markdown-live-editor:focus {
  box-shadow: inset 3px 0 0 var(--accent);
  padding-left: 18px;
}

.markdown-live-editor:empty::before {
  content: "Scrie pagina aici...";
  color: var(--muted);
}

.markdown-reader {
  max-width: 940px;
  margin: 0 auto;
  padding: 42px 54px 58px;
  white-space: normal;
}

.markdown-reader-compact {
  max-width: none;
  min-height: auto;
  padding: 22px 30px 36px;
  background: transparent;
}

.markdown-reader h1,
.markdown-reader h2,
.markdown-reader h3 {
  margin: 18px 0 6px;
  line-height: 1.18;
}

.markdown-reader h1:first-child,
.markdown-reader h2:first-child,
.markdown-reader h3:first-child {
  margin-top: 0;
}

.markdown-reader h1 {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 32px;
}

.markdown-reader h2 {
  font-size: 24px;
}

.markdown-reader h3 {
  font-size: 19px;
}

.markdown-reader p,
.markdown-reader ul,
.markdown-reader ol,
.markdown-reader blockquote,
.markdown-reader table,
.markdown-reader pre {
  margin: 0 0 9px;
}

.markdown-reader ul,
.markdown-reader ol {
  padding-left: 24px;
}

.markdown-reader li {
  margin-bottom: 2px;
}

.markdown-reader a {
  color: var(--accent);
  font-weight: 650;
  text-decoration: none;
}

.markdown-reader a:hover {
  text-decoration: underline;
}

.markdown-reader blockquote {
  padding: 8px 14px;
  border-left: 4px solid var(--accent);
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  background: var(--accent-soft);
}

.markdown-reader code {
  padding: 2px 6px;
  border-radius: 5px;
  color: var(--accent);
  background: var(--accent-soft);
}

.markdown-reader pre {
  overflow: auto;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--input);
}

.markdown-reader pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}

.markdown-reader table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}

.markdown-reader thead {
  background: var(--input);
}

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

.markdown-reader tr:last-child td {
  border-bottom: 0;
}

.markdown-reader hr {
  margin: 28px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

label.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

label.check input {
  width: auto;
}

.modal-form {
  position: fixed;
  z-index: 30;
  top: 50%;
  left: 50%;
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  transform: translate(-50%, -50%);
}

.modal-form::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

body.modal-open::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(13, 18, 27, 0.42);
  backdrop-filter: blur(3px);
}

.form-heading {
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.login-view {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-box {
  width: min(430px, 100%);
  padding: 30px;
}

.login-logo {
  width: 190px;
  max-width: 100%;
  height: auto;
  display: block;
  margin-bottom: 18px;
}

.login-box h1 {
  margin-bottom: 22px;
  font-size: 28px;
}

.auth-tabs {
  margin: 0 0 18px;
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.auth-tabs button {
  min-height: 34px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
}

.auth-tabs button.active {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 6px 18px rgba(31, 36, 45, 0.08);
}

.auth-fields {
  display: grid;
}

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

.login-view.hidden,
.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  body,
  body[data-mode="pages"] {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: auto;
  }

  .layout,
  body[data-mode="pages"] .layout,
  .page-workspace,
  .grid {
    grid-template-columns: 1fr;
  }

  .documents {
    max-height: 320px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    min-height: auto;
    flex-wrap: wrap;
  }

  .topbar input,
  .topbar select {
    width: min(100%, 360px);
  }

  .session {
    width: 100%;
    margin-left: 0;
  }

  .page-editor,
  .page-workspace {
    min-height: 0;
  }

  .page-editor {
    max-width: none;
    padding: 26px;
  }

  .markdown-edit-shell {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .markdown-source-field,
  .markdown-source,
  .markdown-preview-panel {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .sidebar,
  .topbar,
  .detail-header,
  .page-detail-header,
  .page-editor {
    padding: 16px;
  }

  .page-meta-grid,
  .version {
    grid-template-columns: 1fr;
  }

  .markdown-source-field,
  .markdown-source,
  .markdown-preview-panel,
  .markdown-live-editor,
  .markdown-reader {
    min-height: 460px;
  }

  .markdown-reader,
  .markdown-reader-compact {
    padding: 24px 20px 36px;
  }

  .actions {
    width: 100%;
  }

  .actions > * {
    flex: 1;
  }
}
