:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #171b24;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #7c9cff;
  --border: #2a3140;
  --radius: 12px;
  --max-width: 42rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

main {
  width: min(100% - 2rem, var(--max-width));
  margin: 0 auto;
  padding: 1.5rem 0 3rem;
}

header {
  padding: 1rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.75rem;
}

h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
}

h2 {
  font-size: 1.125rem;
  color: var(--muted);
  font-weight: 500;
}

p {
  margin: 0 0 1rem;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.meta {
  color: var(--muted);
  font-size: 0.875rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: #22293a;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

nav.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-top: 1.5rem;
}

nav.links a {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

/* --- Digest (task 5.1) --- */

.digest-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.digest-item {
  position: relative;
}

.digest-rank {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--muted);
  opacity: 0.6;
}

.digest-item h2 {
  font-size: 1.125rem;
  color: var(--text);
  padding-right: 2rem;
}

.digest-reason {
  font-size: 0.9375rem;
  color: var(--muted);
}

.digest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  margin-top: 0.75rem;
}

.btn-link,
.btn-bitrix {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #1a2030;
  color: var(--accent);
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-bitrix:hover,
.btn-link:hover {
  background: #22293a;
  text-decoration: none;
}

.vote-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.vote-label {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-right: 0.25rem;
}

.vote-btn {
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.75rem;
  cursor: pointer;
}

.vote-btn.selected,
.vote-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.longread-lead .lead {
  font-size: 1.0625rem;
  color: var(--text);
}

.toc ol {
  margin: 0;
  padding-left: 1.25rem;
}

.longread-body p {
  margin-bottom: 0.875rem;
}

/* --- Context editor (mobile-first) --- */

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.editor-section {
  margin-bottom: 1rem;
}

.editor-section h2 {
  font-size: 1rem;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 1rem;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="url"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.625rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  min-height: 5rem;
  resize: vertical;
  line-height: 1.5;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa0a6' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  min-width: 2.75rem;
  padding: 0.625rem 1rem;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #0f1117;
  border-color: var(--accent);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
  min-height: 2.25rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-danger {
  background: #3a1f24;
  color: #ff8a8a;
  border-color: #5c2a32;
}

.btn-icon {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.btn-save {
  width: 100%;
  font-size: 1rem;
  min-height: 3rem;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1rem;
}

.list-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.list-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9375rem;
  word-break: break-word;
}

.list-item-body a {
  font-size: 0.8125rem;
  color: var(--muted);
}

.tag {
  display: inline-block;
  align-self: flex-start;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #22293a;
  color: var(--accent);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.note-content {
  white-space: pre-wrap;
}

.notes-group {
  margin-bottom: 0.5rem;
}

.notes-date {
  font-size: 0.8125rem;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 0.75rem;
}

.add-form {
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.form-message,
.status-bar {
  font-size: 0.875rem;
  margin-top: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 8px;
}

.form-message[data-type="error"],
.status-bar[data-type="error"] {
  background: #3a1f24;
  color: #ff8a8a;
}

.form-message[data-type="success"],
.status-bar[data-type="success"] {
  background: #1a2e24;
  color: #7dcea0;
}

.form-message[data-type="info"],
.status-bar[data-type="info"] {
  background: #22293a;
  color: var(--muted);
}

.save-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin: 0 -1rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.auth-card h2 {
  font-size: 1rem;
  color: var(--text);
  font-weight: 600;
}

@media (min-width: 480px) {
  .save-bar {
    margin: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .btn-save {
    max-width: 20rem;
  }
}

