:root {
  --bg: #f8f8f8;
  --surface: #ffffff;
  --surface-soft: #f5f8ff;
  --surface-muted: #f4f6fb;
  --text: #161616;
  --muted: #6b6b6b;
  --border: #e9e9e9;
  --primary: #0364ff;
  --success: #1f9d4b;
  --danger: #d23232;
  font-family: "Inter", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  display: grid;
  gap: 14px;
}

.auth-card h1 {
  margin: 0;
  font-size: 30px;
}

.auth-card p {
  margin: 0;
  color: var(--muted);
}

.auth-card label {
  display: grid;
  gap: 8px;
}

.auth-card label span {
  font-size: 13px;
  color: #262626;
  font-weight: 600;
}

.auth-card input,
.auth-card button {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  font-size: 14px;
}

.auth-card button {
  cursor: pointer;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

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

.admin-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: #fcfcfc;
  padding: 14px;
  display: grid;
  gap: 14px;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar__head button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.sidebar__group h3 {
  margin: 0 0 8px;
  color: #2f2f2f;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar__group {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.menu-list {
  display: grid;
  gap: 12px;
  max-height: 100%;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.menu-subgroup {
  display: grid;
  gap: 6px;
}

.menu-subgroup__title {
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #63708d;
}

.menu-item {
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px;
  background: transparent;
  cursor: pointer;
}

.menu-item strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.menu-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.menu-item:hover {
  background: #f2f6ff;
}

.menu-item.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.menu-item.active small {
  color: #dfe9ff;
}

.editor {
  height: 100vh;
  padding: 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.editor__head {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 8;
}

.editor__head h2 {
  margin: 0;
}

.editor__head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.editor__actions {
  display: flex;
  gap: 8px;
}

.editor__actions button {
  min-height: 38px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

#saveButton {
  background: var(--success);
  border: 0;
  color: #fff;
  box-shadow: 0 8px 20px rgba(31, 157, 75, 0.3);
}

#saveButton:hover {
  background: #1a8740;
}

#saveButton:focus-visible {
  outline: 2px solid rgba(31, 157, 75, 0.45);
  outline-offset: 2px;
}

#cancelButton {
  background: #fff6eb;
  border-color: #ffd39e;
  color: #9a4c00;
}

.editor__body {
  min-height: 0;
  overflow: auto;
}

#screenContent {
  display: grid;
  gap: 18px;
}

.section-card {
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  box-shadow: 0 8px 30px rgba(17, 32, 73, 0.06);
  padding: 16px;
  display: grid;
  gap: 14px;
}

.section-card__head {
  display: grid;
  gap: 6px;
}

.section-card__head h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.section-card__head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 860px;
}

.field-grid {
  display: grid;
  gap: 12px 14px;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.field-grid--single {
  grid-template-columns: 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 5px;
  min-width: 0;
}

.field label {
  color: #2e2e2e;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}

.field small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px;
  font-size: 14px;
  background: var(--surface);
}

.field textarea {
  min-height: 108px;
  resize: vertical;
}

.field--markdown {
  gap: 8px;
}

.markdown-editor__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f6f9ff;
}

.markdown-editor__toolbar button {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 12px;
  color: #2a3752;
}

.markdown-editor__toolbar button:hover {
  background: #edf2ff;
}

.markdown-editor__toolbar select {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 4px 8px;
  font-size: 12px;
  color: #2a3752;
}

.markdown-editor__input {
  width: 100%;
  min-height: 320px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  padding: 12px;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.markdown-editor__preview-label {
  font-size: 12px;
  font-weight: 700;
  color: #45557b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.markdown-editor__preview {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  max-height: 360px;
  overflow: auto;
  font-size: 14px;
  line-height: 1.55;
}

.markdown-editor__preview h1,
.markdown-editor__preview h2,
.markdown-editor__preview h3,
.markdown-editor__preview h4,
.markdown-editor__preview h5,
.markdown-editor__preview h6 {
  margin-top: 14px;
  margin-bottom: 8px;
}

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

.markdown-editor__preview table {
  width: 100%;
  border-collapse: collapse;
}

.markdown-editor__preview th,
.markdown-editor__preview td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.markdown-editor__preview blockquote {
  margin-left: 0;
  padding-left: 10px;
  border-left: 3px solid #9db4e7;
  color: #4d5e87;
}

.field--checkbox {
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 9px 11px;
}

.field--checkbox.field--warning {
  background: #fff6e9;
  border: 1px solid #ffd39a;
}

.field__checkbox {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 500;
  cursor: pointer;
}

.field__checkbox-label {
  font-size: 13px;
  line-height: 1.35;
  color: #232f4b;
}

.field__switch {
  position: relative;
  width: 42px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.field__switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.field__switch-marker {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #c8d2e6;
  position: relative;
  transition: background-color 0.18s ease;
}

.field__switch-marker::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.22);
  transition: transform 0.18s ease;
}

.field__switch input:checked + .field__switch-marker {
  background: #1b74ff;
}

.field__switch input:checked + .field__switch-marker::before {
  transform: translateX(18px);
}

.array {
  display: grid;
  gap: 10px;
}

.array__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.array__head h4 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.array__head button,
.array-item__remove,
.file-tools button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 6px 10px;
  cursor: pointer;
}

.array-item {
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 11px;
  display: grid;
  gap: 11px;
  border-left: 4px solid #d6e2ff;
}

.array-item--depth-2 {
  background: #f7faff;
  border-left-color: #c6dafd;
}

.array-item--depth-3 {
  background: #f6fbf6;
  border-left-color: #b9dfbe;
}

.array-item--depth-4 {
  background: #fff9f2;
  border-left-color: #ffd39d;
}

.array-item__head {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}

.array-item__head::-webkit-details-marker {
  display: none;
}

.array-item__title {
  font-weight: 700;
  font-size: 16px;
}

.array-item__chevron {
  color: #5b6f95;
  font-size: 13px;
  transition: transform 0.18s ease;
}

.array-item[open] > .array-item__head .array-item__chevron {
  transform: rotate(90deg);
}

.array-item__remove {
  color: var(--danger);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}

.btn--success {
  background: #e7f8ec !important;
  border-color: #9ed7aa !important;
  color: #176c34;
}

#saveButton.btn--success {
  background: var(--success) !important;
  border-color: transparent !important;
  color: #fff !important;
}

.btn--danger {
  background: #ffecec !important;
  border-color: #f2b2b2 !important;
  color: #b42323 !important;
}

.btn__icon {
  font-size: 14px;
  line-height: 1;
}

.file-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.file-tools input[type="file"] {
  display: none;
}

.image-preview {
  width: 100%;
  max-width: 340px;
  max-height: 180px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafafa;
}

.image-preview-wrap {
  position: relative;
  display: inline-flex;
  width: 100%;
  max-width: 340px;
}

.image-preview-link {
  position: absolute;
  right: 8px;
  bottom: 8px;
  opacity: 0;
  transition: opacity 0.18s ease;
  background: rgba(16, 22, 37, 0.74);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 4px 8px;
  text-decoration: none;
  max-width: calc(100% - 16px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-preview-wrap:hover .image-preview-link {
  opacity: 1;
}

.status {
  min-height: 20px;
  color: #1f4d9e;
  font-size: 13px;
}

.news-manager__tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.news-manager__tools button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 6px 12px;
  cursor: pointer;
}

.news-manager__tools button:disabled {
  opacity: 0.5;
  cursor: default;
}

.news-manager__table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}

.news-manager__table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.news-manager__table th,
.news-manager__table td {
  border-bottom: 1px solid #eef1f6;
  padding: 9px 10px;
  font-size: 13px;
  text-align: left;
  vertical-align: top;
}

.news-manager__table thead th {
  font-size: 12px;
  text-transform: uppercase;
  color: #61708f;
  letter-spacing: 0.04em;
  background: #f8fbff;
}

.news-manager__table tr.is-selected td {
  background: #f0f6ff;
}

.news-manager__title-cell {
  min-width: 280px;
}

.news-manager__title-button {
  border: 0;
  background: transparent;
  color: #1746a2;
  text-align: left;
  padding: 0;
  font-size: 13px;
  cursor: pointer;
}

.news-manager__title-button:hover {
  text-decoration: underline;
}

.news-manager__empty {
  text-align: center !important;
  color: #6f7c99;
  padding: 20px 10px !important;
}

.news-manager__pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.news-manager__pagination button {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 6px 12px;
  cursor: pointer;
}

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  z-index: 999;
  pointer-events: none;
}

.toast {
  min-width: 240px;
  max-width: 460px;
  border-radius: 12px;
  padding: 11px 13px;
  color: #fff;
  font-size: 13px;
  line-height: 1.35;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 10px 26px rgba(12, 21, 54, 0.2);
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.toast--info {
  background: #2f4a8c;
}

.toast--success {
  background: var(--success);
}

.toast--error {
  background: var(--danger);
}

.global-loader {
  position: fixed;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 1100;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  box-shadow: 0 10px 30px rgba(3, 16, 48, 0.35);
}

body.is-busy .editor__actions button,
body.is-busy .menu-item,
body.is-busy .array__head button,
body.is-busy .array-item__remove,
body.is-busy .file-tools button {
  pointer-events: none;
  opacity: 0.65;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 900px) {
  .field-grid {
    grid-template-columns: 1fr;
  }
}
