:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #14181f;
  --muted: #6b7280;
  --line: #dfe3e8;
  --accent: #1f3a5f;
  --accent-soft: #e8edf4;
  --ok: #1c7c4a;
  --warn: #9a6700;
  --err: #b3261e;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

/* --- Боковая панель --- */
.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: #101822;
  color: #e7ebf0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: block; color: #fff; padding: 4px 8px 18px; border-bottom: 1px solid #23303f; margin-bottom: 12px; }
.brand:hover { text-decoration: none; }
.brand-title { display: block; font-size: 19px; font-weight: 700; letter-spacing: 0.2px; }
.brand-sub { display: block; font-size: 12px; color: #93a1b1; margin-top: 3px; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav a {
  color: #c7d0da;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.nav a:hover { background: #1b2634; color: #fff; text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }

.sidebar-footer { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid #23303f; }
.who { display: flex; flex-direction: column; margin-bottom: 8px; font-size: 13px; }
.who span { color: #93a1b1; }
.link-button {
  background: none;
  border: 0;
  color: #c7d0da;
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}
.link-button:hover { color: #fff; }

/* --- Контент --- */
.main { flex: 1; padding: 24px 28px 60px; min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h1 { font-size: 24px; margin: 0; font-weight: 650; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; margin-bottom: 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card.narrow { max-width: 640px; }
.card h2 { font-size: 17px; margin: 0 0 12px; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-head h2 { margin-bottom: 12px; }

.kpi { display: flex; flex-direction: column; gap: 4px; margin-bottom: 0; }
.kpi-label { font-size: 13px; color: var(--muted); }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.kpi-hint { font-size: 13px; color: var(--muted); }

/* --- Таблицы --- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table tr.total td { font-weight: 600; border-top: 2px solid var(--line); }
.table tr.row-muted td { color: var(--muted); }
.right { text-align: right; }
.actions { white-space: nowrap; }
.actions form { display: inline; }
.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Кнопки --- */
.btn {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  line-height: 1.2;
}
.btn:hover { background: var(--accent-soft); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #16304f; }
.btn.danger { color: var(--err); border-color: #e6c3c0; }
.btn.danger:hover { background: #fbeceb; }
.btn.small { padding: 4px 9px; font-size: 13px; }

/* --- Формы --- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.form input[type="text"], .form input[type="url"], .form input[type="password"],
.form input[type="number"], .form select, .form textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--ink);
  width: 100%;
}
.form textarea { resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid #b9c8da; outline-offset: 0; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.form legend { padding: 0 6px; font-weight: 600; }
.checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
.checkbox input { width: auto; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 6px 16px; }
.hint, .muted { color: var(--muted); }
.hint { font-size: 12px; font-weight: 400; }
.small { font-size: 13px; }

.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type="text"], .filters select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  font: inherit;
  min-width: 220px;
  background: #fff;
}

/* --- Служебные блоки --- */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; border: 1px solid transparent; }
.flash.ok { background: #eaf5ee; border-color: #bfe0cb; color: var(--ok); }
.flash.err { background: #fbeceb; border-color: #ecc8c5; color: var(--err); }

.status {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #f4f5f7;
  white-space: nowrap;
}
.status-done, .status-resolved { background: #eaf5ee; color: var(--ok); border-color: #bfe0cb; }
.status-sending, .status-in_progress { background: #fdf4e0; color: var(--warn); border-color: #ecd9ac; }
.status-failed { background: #fbeceb; color: var(--err); border-color: #ecc8c5; }
.status-partial { background: #fdf4e0; color: var(--warn); border-color: #ecd9ac; }
.status-queued, .status-new { background: var(--accent-soft); color: var(--accent); border-color: #c2d0e2; }

.props { display: grid; grid-template-columns: 180px 1fr; gap: 8px 12px; margin: 0 0 12px; }
.props dt { color: var(--muted); font-size: 13px; }
.props dd { margin: 0; }

.pagination { display: flex; gap: 10px; align-items: center; margin-top: 14px; }

.errors { margin: 8px 0 0; padding-left: 20px; color: var(--err); font-size: 13px; }
.errors li { margin-bottom: 3px; }

pre.message {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  margin: 0 0 14px;
}
pre.doc {
  background: #fff;
  border: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 14px;
  margin: 0;
}
.preview-image { max-width: 480px; max-height: 360px; border: 1px solid var(--line); border-radius: 6px; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; }
.inline-form select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  background: #fff;
}

/* --- Вход --- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #101822; }
.login-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-note { margin: 16px 0 0; color: var(--muted); font-size: 12px; }
.login-card .form label { font-weight: 500; }
.login-card .btn { width: 100%; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 18px 16px 40px; }
  .props { grid-template-columns: 130px 1fr; }
  .truncate { max-width: 220px; }
}
