:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --border: #dde1e6;
  --text: #1f2328;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --error: #dc2626;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.link-button {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}

.auth-card {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1 { font-size: 22px; }
h2 { font-size: 16px; margin-top: 24px; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
}

textarea { resize: vertical; }

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

button[type="submit"], .button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-weight: 500;
}

button[type="submit"]:hover, .button:hover { background: var(--primary-hover); }

.error {
  color: var(--error);
  font-size: 14px;
}

.muted { color: var(--muted); font-size: 13px; }

table.list {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

table.list th, table.list td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

table.list th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover { background: #f9fafb; }
table.list tbody tr:last-child td { border-bottom: none; }

.truncate {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.amount { font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: #e5e7eb;
  color: #374151;
}

.badge[data-status="Черновик"]     { background: #e5e7eb; color: #374151; }
.badge[data-status="Проверенная"]  { background: #dbeafe; color: #1e40af; }
.badge[data-status="Согласованная"]{ background: #cffafe; color: #0e7490; }
.badge[data-status="Оплаченная"]   { background: #dcfce7; color: #166534; }
.badge[data-status="Закрыта"]      { background: #f3f4f6; color: #6b7280; }

dl.details {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 8px 16px;
  margin: 16px 0;
}

dl.details dt { color: var(--muted); font-size: 13px; }
dl.details dd { margin: 0; }

ul.history {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.autocomplete-results {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 4px;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
}

.autocomplete-results:empty { border: none; margin: 0; }

.autocomplete-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

.autocomplete-item:hover { background: #f3f4f6; }
