:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e6ee;
  --text: #1c2333;
  --muted: #6b7487;
  --primary: #3355ff;
  --primary-dark: #2444dd;
  --success: #0f9f6e;
  --success-bg: #e3f8ef;
  --warning: #b7791f;
  --warning-bg: #fdf3dc;
  --danger: #d3384d;
  --danger-bg: #fde8eb;
  --topbar: #141a28;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 18px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.container { width: min(1440px, 100% - 40px); margin: 0 auto; padding: 26px 0 60px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  height: 60px;
  background: var(--topbar);
  color: #fff;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.brand:hover { text-decoration: none; opacity: .9; }
.nav { display: flex; gap: 18px; }
.nav a { color: #c8cfdd; font-weight: 500; }
.nav a:hover { color: #fff; text-decoration: none; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.user { color: #c8cfdd; font-size: 14px; }
.inline { display: inline; }
.btn-ghost.inline, .topbar .inline .btn { background: transparent; color: #c8cfdd; border-color: rgba(255,255,255,.2); }

h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.3px; }
h2 { font-size: 17px; margin: 0 0 16px; }
h3 { margin: 0 0 8px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.grow { flex: 1; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 20px;
}
.page-head p { margin: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.breadcrumbs { font-size: 13px; color: var(--muted); margin-bottom: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.breadcrumbs a { color: var(--muted); }
.breadcrumbs span:last-child { color: var(--text); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: #f7f8fb; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f2c4cb; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; }

.flashes { margin-top: 18px; }
.flash {
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 8px;
  border: 1px solid transparent;
  font-size: 14px;
}
.flash-success { background: var(--success-bg); color: #08734f; border-color: #b9ead7; }
.flash-danger { background: var(--danger-bg); color: #a22133; border-color: #f5c2c9; }
.flash-warning { background: var(--warning-bg); color: #8a5a11; border-color: #f1dfb2; }
.flash-info { background: #eaf0ff; color: #2545b8; border-color: #cfdaff; }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 120px); display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; padding: 34px; display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 22px; margin: 0; }
.login-card p { margin: -8px 0 8px; }
.login-logo {
  width: 48px; height: 48px; border-radius: 14px; background: #eef1ff;
  display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.login-card label, .form-stack label, .form-grid label, .filters label {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: #3a4256;
}

input[type="text"], input[type="password"], input[type="url"], input[type="search"],
input[type="date"], input[type="number"], input[type="file"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #cdd7ff;
  border-color: var(--primary);
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- projects ---------- */
.grid-projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 20px; }
.project-card { padding: 20px; display: block; color: var(--text); transition: border-color .15s, transform .1s; }
.project-card:hover { text-decoration: none; border-color: #c8d1e8; transform: translateY(-1px); }
.project-title { display: flex; justify-content: space-between; gap: 10px; font-size: 17px; font-weight: 650; }
.chevron { color: var(--muted); }
.project-stats { display: flex; gap: 18px; margin: 16px 0 12px; font-size: 13px; color: var(--muted); }
.project-stats b { font-size: 15px; color: var(--text); }
.project-cost { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.project-cost b { color: var(--text); font-size: 15px; }
.project-foot { border-top: 1px solid var(--border); padding-top: 10px; }
.tag-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 0; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #eef1ff;
  color: var(--primary);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  text-decoration: none;
}
.tag-chip:hover { background: #e2e8ff; text-decoration: none; }
.tag-chip.is-active { background: var(--primary); color: #fff; }
.tag-chip span { opacity: .7; font-weight: 500; }
.tag-chip-static { background: #f1f3f8; color: #4a5264; }
.empty-state { padding: 40px; text-align: center; grid-column: 1 / -1; }

.panel { padding: 20px; margin-bottom: 18px; }
.panel > summary { cursor: pointer; font-size: 15px; user-select: none; }
.panel > summary::marker { color: var(--muted); }
.panel[open] > summary { margin-bottom: 18px; }
.project-settings .danger-zone {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.project-settings .danger-zone p { margin: 4px 0 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .form-actions, .form-grid .or { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; }
.or { text-align: center; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow);
}
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-success .stat-value { color: var(--success); }
.stat-danger .stat-value { color: var(--danger); }
.stat-warning .stat-value { color: var(--warning); }
.stat-cost .stat-value { color: var(--primary); font-size: 20px; }
.stat-link { color: inherit; transition: border-color .15s, transform .1s; }
.stat-link:hover { text-decoration: none; border-color: #f0b6bf; transform: translateY(-1px); }

.analytics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.chart-card { margin-bottom: 0; }
.chart-box { position: relative; height: 240px; }
.chart-card .hint { margin-top: 10px; }
.chart-card .panel-head { margin-bottom: 12px; }
.chart-card .panel-head h2 { font-size: 16px; }
.top-anchors-card { margin-bottom: 0; }
.anchor-list { display: flex; flex-direction: column; gap: 13px; padding-top: 4px; }
.anchor-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 38px; gap: 10px; align-items: center; }
.anchor-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.anchor-bar { height: 8px; border-radius: 999px; background: #eef1f6; overflow: hidden; }
.anchor-bar span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.index-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 3px;
  border-radius: 5px;
  background: #cbd5e1;
  color: #475569;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}
.index-dot.index-success { background: var(--success); color: #fff; }
.index-dot.index-danger { background: var(--danger); color: #fff; }
.index-dot.index-warning { background: var(--warning); color: #fff; }
.index-dot.index-muted { background: #e2e8f0; color: #64748b; }
.history-chart-box { height: 280px; }
.chart-toggles { display: flex; align-items: center; gap: 18px; margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.chart-toggle { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.chart-toggle input { accent-color: var(--primary); }
.anchor-count { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar-info { margin-left: auto; }
.selection-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.selection-count { white-space: nowrap; }
.load-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 14px 16px;
  margin-top: 12px;
  border-style: dashed;
  background: #fbfcff;
  flex-wrap: wrap;
}
.load-more .btn[hidden] { display: none; }
.last-run { margin: -6px 0 16px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 12px; align-items: flex-end; padding: 14px 16px; margin-bottom: 14px; flex-wrap: wrap; }
.filters label { min-width: 150px; }
.filters .grow { min-width: 240px; }
.filter-actions { display: flex; gap: 8px; }

/* ---------- table ---------- */
.table-meta { margin: 0 0 8px 2px; }
.table-wrap { overflow-x: auto; }
.card.table-wrap { border-radius: var(--radius); }
.links-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.links-table th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; padding: 11px 12px;
  background: #fafbfd; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.links-table td { padding: 11px 12px; border-bottom: 1px solid #eef1f6; vertical-align: top; }
.links-table tbody tr:last-child td { border-bottom: 0; }
.links-table tbody tr:hover { background: #fafbff; }
.row-danger { background: #fffafb; }
.row-warning { background: #fffdf7; }
.check-col { width: 34px; text-align: center; }
.url-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.anchor-cell { max-width: 220px; }
.subtext { color: var(--muted); font-size: 11.5px; margin-top: 3px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.empty-cell { text-align: center; color: var(--muted); padding: 40px 20px !important; }

/* Компактная таблица проекта: помещается по ширине без горизонтальной прокрутки */
.project-table-wrap { overflow-x: hidden; }
.project-links { table-layout: fixed; width: 100%; }
.project-links th,
.project-links td {
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-links td { white-space: nowrap; }
.project-links .subtext { max-width: none; overflow: hidden; text-overflow: ellipsis; }
.project-links .col-actions { text-align: right; }
.project-links .col-price,
.project-links th.col-price { text-align: right; }

@media (max-width: 1200px) {
  .project-links .col-seller,
  .project-links .col-type { display: none; }
}
@media (max-width: 1000px) {
  .project-links .col-date,
  .project-links .col-checked { display: none; }
}
@media (max-width: 820px) {
  .project-links .col-guarantee { display: none; }
}
@media (max-width: 720px) {
  .project-links .col-donor { display: none; }
}

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: #08734f; }
.badge-warning { background: var(--warning-bg); color: #8a5a11; }
.badge-danger { background: var(--danger-bg); color: #a22133; }
.badge-muted { background: #eef0f4; color: #5d6474; }
.badge-outline { background: transparent; border: 1px solid var(--border); color: #4a5264; }
.chip { display: inline-block; background: #f0f3fa; border-radius: 6px; padding: 2px 7px; margin: 2px 4px 2px 0; font-size: 12px; }

.pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 18px; align-items: start; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; }
.panel-badges { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.balance-badge { font: inherit; cursor: pointer; }
.balance-badge:disabled { cursor: progress; opacity: .7; }

/* ---------- run progress ---------- */
.run-box { padding: 16px 18px; margin-bottom: 18px; border-color: #cfdaff; background: #f8faff; }
.run-head { display: flex; justify-content: space-between; margin-bottom: 10px; font-size: 14px; }
.progress { height: 8px; border-radius: 999px; background: #e6eaff; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.run-note { margin-top: 8px; }

/* ---------- detail ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 18px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
.history-table { font-size: 13px; }
.simple-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.simple-table th, .simple-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.simple-table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
.warning-list { margin: 0; padding-left: 20px; color: #6b4a10; font-size: 13.5px; }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .container { width: calc(100% - 24px); }
  .page-head { flex-direction: column; }
  .toolbar-info { margin-left: 0; width: 100%; }
  .project-settings .danger-zone { flex-direction: column; }
}
