:root {
    --bg: #f7f8fa;
    --card: #ffffff;
    --text: #1a1f2e;
    --muted: #6b7280;
    --accent: #2563eb;
    --border: #e5e7eb;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
header { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; padding: 12px 20px; }
.header-inner { max-width: 900px; margin: 0 auto; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 17px; text-decoration: none; color: var(--text); white-space: nowrap; }
.search-form { flex: 1; min-width: 200px; }
.search-form input { width: 100%; padding: 10px 16px; font-size: 15px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.btn-admin, .btn-logout { padding: 8px 14px; background: transparent; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; text-decoration: none; color: var(--muted); cursor: pointer; }
main { max-width: 900px; margin: 0 auto; padding: 24px 20px 80px; }
h1 { font-size: 24px; margin-bottom: 16px; }
.subtitle { color: var(--muted); margin-bottom: 20px; }
.back-link { display: inline-block; margin-bottom: 16px; color: var(--accent); text-decoration: none; }
.roles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.role-card { display: block; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 24px; text-decoration: none; color: var(--text); transition: .2s; }
.role-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(37,99,235,.1); }
.role-card .emoji { font-size: 32px; margin-bottom: 8px; }
.role-card h3 { font-size: 18px; margin-bottom: 4px; }
.role-card p { color: var(--muted); font-size: 14px; }
.articles-list { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.article-item { display: block; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; text-decoration: none; color: var(--text); transition: .2s; }
.article-item:hover { border-color: var(--accent); background: #f8faff; }
.article-item .title { font-weight: 600; font-size: 16px; }
.article-item .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.article-body { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 32px; }
.article-body h2 { font-size: 20px; margin: 24px 0 12px; }
.article-body p { margin-bottom: 12px; }
.article-body ul, .article-body ol { margin: 0 0 16px 22px; }
.admin-form { display: flex; flex-direction: column; gap: 12px; background: var(--card); padding: 20px; border-radius: 12px; border: 1px solid var(--border); margin-bottom: 30px; }
.admin-form input, .admin-form select, .admin-form textarea { padding: 10px; font-size: 15px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; }
.admin-form button { padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; }
.admin-article-item { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; }
.admin-article-item .actions { display: flex; gap: 10px; align-items: center; }
.btn-edit, .btn-delete { font-size: 14px; text-decoration: none; cursor: pointer; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: transparent; }
.btn-delete { color: #dc2626; }
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--card); padding: 32px; border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,.08); width: 100%; max-width: 380px; text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-card input { padding: 14px; font-size: 16px; border: 1px solid var(--border); border-radius: 10px; }
.login-card button { padding: 14px; background: var(--accent); color: #fff; border: none; border-radius: 10px; font-size: 16px; font-weight: 600; cursor: pointer; }
.error { color: #dc2626; font-size: 14px; }
.no-results { text-align: center; padding: 60px 20px; color: var(--muted); }
@media (max-width: 640px) {
    .header-inner { gap: 10px; }
    .search-form { order: 3; flex-basis: 100%; }
    .article-body { padding: 22px; }
    main { padding: 16px 14px 60px; }
}

/* Кнопка primary */
.btn-primary {
    display: inline-block; padding: 10px 18px; background: var(--accent);
    color: #fff; border-radius: 10px; text-decoration: none;
    font-size: 15px; font-weight: 600; margin-bottom: 16px;
}

/* Бейдж роли */
.role-badge {
    display: inline-block; padding: 3px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600; margin-left: 8px;
}
.role-admin  { background: #fee2e2; color: #991b1b; }
.role-editor { background: #dbeafe; color: #1e40af; }
.role-viewer { background: #e5e7eb; color: #374151; }

/* Имя пользователя в шапке */
.user-name {
    font-size: 14px; text-decoration: none; color: var(--text);
    padding: 8px 12px; border-radius: 10px;
}
.user-name small { color: var(--muted); }
.user-name:hover { background: var(--bg); }

/* Блоки-сообщения */
.error-box, .success-box {
    padding: 12px 16px; border-radius: 10px;
    margin-bottom: 16px; font-size: 14px;
}
.error-box   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.success-box { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* Редактор Quill */
#editor-new, #editor-edit {
    background: #fff; border-radius: 10px; min-height: 240px;
    font-size: 15px;
}
.ql-toolbar.ql-snow { border-radius: 10px 10px 0 0; border-color: var(--border); }
.ql-container.ql-snow { border-radius: 0 0 10px 10px; border-color: var(--border); font-family: inherit; }
.ql-editor { min-height: 220px; }
.ql-editor h2 { font-size: 20px; margin: 16px 0 8px; }
.ql-editor blockquote { border-left: 4px solid var(--accent); padding-left: 12px; color: #444; }

/* Список пользователей */
.users-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* Формы в админке */
.admin-form label { font-size: 14px; color: var(--muted); font-weight: 600; }

/* === Картинки в статьях — не вылезают за пределы === */
.article-body img,
.ql-editor img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 12px 0;
  display: block;
}

/* Обтекание текстом (float) */
.article-body img[style*="float:left"],
.ql-editor img[style*="float:left"] {
  float: left;
  margin: 4px 16px 12px 0;
  display: inline;
}
.article-body img[style*="float:right"],
.ql-editor img[style*="float:right"] {
  float: right;
  margin: 4px 0 12px 16px;
  display: inline;
}

/* По центру */
.article-body img[style*="margin:0 auto"],
.article-body img[style*="margin: 0 auto"],
.ql-editor img[style*="margin:0 auto"],
.ql-editor img[style*="margin: 0 auto"] {
  display: block;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* Обёртка статьи не должна «ломаться» длинным словом */
.article-body {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Чтобы float не выходил из блока — clearfix */
.article-body::after,
.ql-editor::after {
  content: "";
  display: table;
  clear: both;
}