:root {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-text: #1c1f26;
  --color-muted: #6b7280;
  --color-border: #e2e4e9;
  --color-accent: #2563eb;
  --color-accent-contrast: #ffffff;
  --color-error: #dc2626;
  --color-error-bg: #fef2f2;
  --color-ok: #16a34a;
  --color-ok-bg: #f0fdf4;
  --radius: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--color-accent); }

.topnav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
  padding: 0 20px;
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topnav__brand {
  font-weight: 600;
  white-space: nowrap;
}

.topnav__tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.topnav__tab {
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--color-muted);
  text-decoration: none;
  white-space: nowrap;
  font-size: 14px;
}

.topnav__tab:hover { background: var(--color-bg); }

.topnav__tab.is-active {
  color: var(--color-accent);
  background: var(--color-bg);
  font-weight: 600;
}

.topnav__right {
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  white-space: nowrap;
}

.topnav__settings {
  color: var(--color-muted);
  text-decoration: none;
  font-size: 14px;
}

.topnav__user { position: relative; }

.topnav__user-btn {
  background: none;
  border: none;
  font: inherit;
  color: var(--color-text);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
}

.topnav__user-btn:hover { background: var(--color-bg); }

.topnav__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  min-width: 160px;
  display: flex;
  flex-direction: column;
  padding: 6px;
}

.topnav__menu a,
.topnav__menu .link-button {
  padding: 8px 10px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--color-text);
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  cursor: pointer;
}

.topnav__menu a:hover,
.topnav__menu .link-button:hover { background: var(--color-bg); }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.form { display: flex; flex-direction: column; gap: 12px; max-width: 360px; }
.form--row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; max-width: none; }
.form--inline { display: inline-flex; gap: 6px; align-items: center; }

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

input, select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
}

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font: inherit;
}

.btn--primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: var(--color-accent-contrast);
}

.btn--danger { border-color: var(--color-error); color: var(--color-error); }
.btn--small { padding: 4px 10px; font-size: 13px; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}

.alert--error { background: var(--color-error-bg); color: var(--color-error); }
.alert--ok { background: var(--color-ok-bg); color: var(--color-ok); }

.muted { color: var(--color-muted); }

.auth-card {
  max-width: 360px;
  margin: 80px auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 32px;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}
.table__actions { display: flex; gap: 6px; align-items: center; }

.stub { text-align: center; padding: 60px 0; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: var(--color-surface);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 100;
}

[x-cloak] { display: none !important; }

.htmx-indicator { opacity: 0; transition: opacity 150ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

.catalog-block .btn { margin-top: 8px; }

.costs-header { margin-bottom: 16px; }

.tiles { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }

.tile {
  flex: 1 1 160px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-decoration: none;
  color: inherit;
}

.tile__value { font-size: 22px; font-weight: 700; }
.tile__label { font-size: 13px; color: var(--color-muted); }

.tile--warn { border-color: var(--color-error); cursor: pointer; }
.tile--warn .tile__value { color: var(--color-error); }

.costs-header__sync { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }

.thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--color-bg);
  display: inline-block;
}

.thumb--placeholder { border: 1px dashed var(--color-border); }

.cost-group--missing > tr:first-child { box-shadow: inset 4px 0 0 var(--color-error); }

.history-cell { background: var(--color-bg); }

.chevron { white-space: nowrap; }

@media (max-width: 720px) {
  .topnav { gap: 12px; padding: 0 12px; }
  .topnav__brand { display: none; }

  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 8px 12px;
  }
  .table td {
    border-bottom: none;
    padding: 6px 0;
  }
  .table td::before {
    content: attr(data-label);
    display: block;
    font-size: 12px;
    color: var(--color-muted);
  }
}
