/* Reestr 2.0 components + compatibility layer for existing Django templates. */

/* Header/navigation: styles current base.html markup first; later commits may refine markup. */
header.topbar {
  position:sticky;
  top:0;
  z-index:50;
  background:var(--tm-nav-bg);
  color:var(--tm-nav-ink);
  border-bottom:0;
  box-shadow:0 1px 0 rgba(0,0,0,.25);
}

.topbar-inner {
  max-width:var(--tm-container);
  min-height:var(--tm-header-h);
  margin:0 auto;
  padding:0 24px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:18px;
}

.brand,
.tm-logo {
  color:var(--tm-nav-ink);
  font-weight:750;
  font-size:16px;
  letter-spacing:0;
  text-decoration:none;
  white-space:nowrap;
}

.brand:hover,
.tm-logo:hover { text-decoration:none; }
.brand .dot,
.tm-logo b { color:var(--tm-nav-accent); }

.who {
  display:flex;
  align-items:center;
  justify-content:flex-end;
  flex-wrap:wrap;
  gap:10px;
  color:var(--tm-nav-muted);
  font-size:13px;
}

.who a,
.tm-header__link {
  color:var(--tm-nav-muted);
  text-decoration:none;
}

.who a:hover,
.tm-header__link:hover {
  color:var(--tm-nav-ink);
  text-decoration:none;
}

.tm-header__user {
  color:var(--tm-nav-muted);
  font-size:13px;
  max-width:240px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.tm-avatar {
  width:30px;
  height:30px;
  display:grid;
  place-items:center;
  flex:0 0 auto;
  border:1px solid color-mix(in srgb,var(--tm-nav-accent) 40%,transparent);
  border-radius:50%;
  background:color-mix(in srgb,var(--tm-nav-accent) 22%,var(--tm-nav-solid));
  color:var(--tm-nav-ink);
  font-size:11px;
  font-weight:700;
  letter-spacing:0;
  text-transform:uppercase;
}

.tm-theme-toggle {
  display:inline-flex;
  align-items:center;
  gap:2px;
  padding:2px;
  border-radius:999px;
  background:var(--tm-nav-hover);
}

.tm-theme-toggle a {
  display:inline-flex;
  align-items:center;
  min-height:24px;
  padding:4px 10px;
  border-radius:999px;
  color:var(--tm-nav-muted);
  font-size:12px;
  font-weight:650;
  text-decoration:none;
}

.tm-theme-toggle a:hover {
  color:var(--tm-nav-ink);
  text-decoration:none;
}

.tm-theme-toggle a.is-active {
  background:rgba(255,255,255,.16);
  color:var(--tm-nav-ink);
}

.tm-header__logout {
  margin:0 !important;
}

.who form button {
  color:var(--tm-nav-muted) !important;
}

.who form button:hover {
  color:var(--tm-nav-ink) !important;
}

nav.main,
.tm-nav {
  max-width:var(--tm-container);
  margin:0 auto;
  padding:0 18px 0;
  min-height:40px;
  display:flex;
  align-items:stretch;
  gap:2px;
  flex-wrap:wrap;
}

.menu { position:relative; }

.menu > .trigger,
.tm-nav__item {
  height:40px;
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:0 12px;
  background:transparent;
  border:0;
  border-radius:0;
  box-shadow:inset 0 -2px 0 transparent;
  color:var(--tm-nav-muted);
  cursor:pointer;
  font:600 13px var(--sans);
  text-decoration:none;
  transition:background var(--tm-dur-fast) var(--tm-ease), color var(--tm-dur-fast) var(--tm-ease), box-shadow var(--tm-dur-fast) var(--tm-ease);
}

.menu:hover > .trigger,
.tm-nav__item:hover {
  background:var(--tm-nav-hover);
  color:var(--tm-nav-ink);
  text-decoration:none;
}

.menu .caret,
.tm-caret {
  display:inline-block;
  width:7px;
  height:7px;
  margin-left:2px;
  border-right:1.5px solid currentColor;
  border-bottom:1.5px solid currentColor;
  color:currentColor;
  opacity:.75;
  transform:rotate(45deg) translateY(-1px);
}

.dropdown,
.tm-menu {
  position:absolute;
  top:100%;
  left:0;
  min-width:240px;
  display:none;
  z-index:60;
  padding:8px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  box-shadow:var(--shadow-pop);
  color:var(--ink);
}

.menu:hover .dropdown { display:block; }

.dropdown a,
.tm-menu__item {
  display:flex;
  align-items:center;
  gap:10px;
  padding:9px 12px;
  border-radius:6px;
  color:var(--ink-2);
  font-size:14px;
  text-decoration:none;
}

.dropdown a:hover,
.tm-menu__item:hover {
  background:var(--surface-subtle);
  color:var(--ink);
  text-decoration:none;
}

/* Layout containers */
.panel,
.card,
.tm-card {
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow);
}

.panel,
.card { padding:20px; }

.tm-card--compact { padding:14px 16px; }

.page-shell {
  padding:0;
  background:none;
  border:0;
  box-shadow:none;
}

.auth-panel {
  max-width:420px;
  margin:0 auto;
}

.page-head {
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:18px;
  margin-bottom:18px;
}

.page-head p { max-width:760px; }

.tm-dashboard .page-head,
.tm-list-page .page-head,
.tm-form-page .page-head {
  margin-bottom:18px;
}

.page-actions,
.actions,
.quick-actions,
.tm-row {
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:8px;
}

.section-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(280px,1fr));
  gap:14px;
  margin:16px 0;
}

.metric-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(170px,1fr));
  gap:12px;
  margin:12px 0;
}

.metric-card,
.stat-card,
.tm-metric {
  min-height:96px;
  padding:16px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow);
}

.metric-value,
.tm-metric__value {
  color:var(--ink);
  font-family:var(--mono);
  font-variant-numeric:tabular-nums;
  font-size:28px;
  font-weight:650;
  letter-spacing:0;
  line-height:1.1;
}

.action-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(240px,1fr));
  gap:10px;
  margin-top:8px;
}

.action-card {
  min-height:72px;
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px 14px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  color:var(--ink);
  text-decoration:none;
}

.action-card:hover {
  border-color:var(--accent);
  box-shadow:var(--shadow-2);
  text-decoration:none;
}

.action-card .count {
  min-width:38px;
  height:38px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:var(--radius);
  background:var(--accent-soft);
  color:var(--accent);
  font-family:var(--mono);
  font-weight:700;
}

.task-list {
  margin:6px 0 0;
  padding:0;
  list-style:none;
}

.task-list li {
  padding:8px 0;
  border-top:1px solid var(--border);
}

.task-list li:first-child { border-top:0; }

.empty-state,
.tm-empty {
  padding:16px;
  background:var(--surface-subtle);
  border:1px dashed var(--border-strong);
  border-radius:var(--radius-lg);
  color:var(--muted);
}

.filter-bar {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(180px,1fr));
  gap:10px;
  align-items:end;
  margin:14px 0;
}

.tm-filter-bar {
  margin:12px 0 16px;
  gap:12px;
}

.tm-filter-bar p { margin:0; }

.tm-filter-actions {
  min-height:100%;
  display:flex;
  align-items:end;
  gap:8px;
}

.tm-count-row {
  display:flex;
  align-items:center;
  flex-wrap:wrap;
  gap:8px;
}

.tm-count-row__total {
  margin-right:4px;
  color:var(--ink);
  font-weight:700;
}

.tm-supplier-grid {
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(220px,1fr));
  gap:12px;
  margin:14px 0 18px;
}

.tm-supplier-card {
  min-height:190px;
  display:flex;
  flex-direction:column;
  justify-content:space-between;
  gap:14px;
}

.tm-supplier-card__head {
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:10px;
}

.tm-supplier-card h2 {
  margin:0;
  font-size:18px;
  line-height:1.25;
}

.tm-supplier-card__legal {
  display:-webkit-box;
  margin:10px 0 0;
  color:var(--muted);
  font-size:14px;
  line-height:1.45;
  overflow:hidden;
  -webkit-box-orient:vertical;
  -webkit-line-clamp:2;
}

.tm-supplier-card__foot {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding-top:12px;
  border-top:1px solid var(--border);
}

/* Forms */
label,
.field-label,
.tm-label {
  display:block;
  margin:14px 0 6px;
  color:var(--muted);
  font-size:14px;
  font-weight:600;
}

input,
select,
textarea,
.tm-input,
.tm-select,
.tm-textarea {
  width:100%;
  padding:10px 12px;
  background:var(--surface);
  border:1px solid var(--border-strong);
  border-radius:var(--radius);
  color:var(--ink);
  font:inherit;
  transition:border-color var(--tm-dur-fast) var(--tm-ease), box-shadow var(--tm-dur-fast) var(--tm-ease), background var(--tm-dur-fast) var(--tm-ease);
}

input::placeholder,
textarea::placeholder { color:var(--faint); }

input:focus,
select:focus,
textarea:focus,
.tm-input:focus,
.tm-select:focus,
.tm-textarea:focus {
  outline:none;
  border-color:var(--accent);
  box-shadow:var(--tm-focus);
}

textarea,
.tm-textarea {
  min-height:88px;
  resize:vertical;
  line-height:1.5;
}

input[type=checkbox],
input[type=radio] {
  width:auto;
  padding:0;
  margin:0 8px 0 0;
  display:inline-block;
  vertical-align:middle;
  box-shadow:none;
}

ul li label,
label.chk {
  display:inline-flex;
  align-items:center;
  gap:8px;
  margin:4px 0;
}

.form-grid,
.tm-form-grid {
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(260px,1fr));
  gap:0 22px;
}

.form-grid p { margin:0 0 10px; }
.form-grid p:has(textarea),
.tm-col-2 { grid-column:1 / -1; }

.tm-form-stack {
  display:flex;
  flex-direction:column;
  gap:16px;
}

.tm-form-card {
  padding:18px;
}

.tm-section-title {
  margin:0 0 14px;
  padding-bottom:10px;
  border-bottom:1px solid var(--border);
  color:var(--ink);
  font-size:13px;
  font-weight:750;
  letter-spacing:.04em;
  text-transform:uppercase;
}

.tm-inline-hint {
  margin:0 0 4px;
  padding:9px 12px;
  background:var(--surface-subtle);
  border:1px solid var(--border);
  border-radius:var(--radius);
}

.tm-milestone-editor {
  padding:12px;
  background:var(--surface-subtle);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
}

.tm-form-actions {
  display:flex;
  align-items:center;
  justify-content:flex-end;
  flex-wrap:wrap;
  gap:10px;
  padding:14px 18px;
}

.actions form {
  max-width:100%;
  margin:0;
  display:flex;
  flex:0 0 auto;
  flex-wrap:nowrap;
  align-items:center;
  gap:8px;
}

.actions input[type=text],
.actions select {
  width:auto;
  min-width:220px;
  max-width:340px;
}

/* Buttons */
button,
.button,
.tm-btn {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:10px 16px;
  border:1px solid transparent;
  border-radius:var(--radius);
  background:var(--accent);
  color:#fff;
  cursor:pointer;
  font:650 14px var(--sans);
  line-height:1;
  text-decoration:none;
  white-space:nowrap;
  transition:background var(--tm-dur-fast) var(--tm-ease), border-color var(--tm-dur-fast) var(--tm-ease), transform var(--tm-dur-fast) var(--tm-ease), box-shadow var(--tm-dur-fast) var(--tm-ease);
}

button:hover,
.button:hover,
.tm-btn:hover {
  background:var(--accent-hover);
  text-decoration:none;
}

button:active,
.button:active,
.tm-btn:active { transform:translateY(1px); }

button:disabled,
.button[aria-disabled="true"],
.tm-btn:disabled {
  opacity:.55;
  cursor:not-allowed;
  transform:none;
}

button.secondary,
.button.secondary,
.secondary,
.tm-btn:not(.tm-btn--primary) {
  background:var(--surface);
  color:var(--ink);
  border-color:var(--border-strong);
}

button.secondary:hover,
.button.secondary:hover,
.secondary:hover {
  background:var(--surface-subtle);
}

button.danger,
.button.danger,
.danger,
.tm-btn--danger {
  background:transparent;
  color:var(--danger);
  border-color:var(--danger-line);
}

button.danger:hover,
.button.danger:hover,
.danger:hover,
.tm-btn--danger:hover {
  background:var(--danger-bg);
}

.linklike {
  border:0;
  background:transparent;
  color:var(--accent);
  padding:0;
  font:inherit;
  cursor:pointer;
}

.linklike:hover { text-decoration:underline; }

/* Badges */
.badge,
.tm-badge {
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 10px;
  border:1px solid var(--border);
  border-radius:999px;
  background:var(--surface-subtle);
  color:var(--ink-2);
  font-size:12px;
  font-weight:650;
  line-height:1;
  white-space:nowrap;
}

.badge.ok,
.badge.approved,
.badge.granted,
.tm-badge--ok {
  background:var(--success-bg);
  border-color:var(--success-line);
  color:var(--success);
}

.badge.warn,
.badge.pending,
.tm-badge--warn {
  background:var(--warn-bg);
  border-color:var(--warn-line);
  color:var(--warn);
}

.badge.bad,
.badge.blocked,
.badge.rejected,
.tm-badge--danger {
  background:var(--danger-bg);
  border-color:var(--danger-line);
  color:var(--danger);
}

.tm-badge--info {
  background:var(--info-bg);
  border-color:var(--info-line);
  color:var(--info);
}

/* Tables */
table,
.tm-table {
  width:100%;
  margin-top:8px;
  border-collapse:collapse;
  overflow:hidden;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow);
}

.tm-table-wrap {
  width:100%;
  overflow:auto;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  box-shadow:var(--shadow);
}

.tm-table-wrap table,
.tm-table-wrap .tm-table {
  margin:0;
  border:0;
  border-radius:0;
  box-shadow:none;
}

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

.tm-task-title {
  display:flex;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}

th {
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  background:var(--surface-subtle);
  color:var(--muted);
  font-size:12px;
  font-weight:750;
  letter-spacing:0;
  text-align:left;
  text-transform:uppercase;
  white-space:nowrap;
}

td {
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  color:var(--ink);
  vertical-align:top;
}

tr:last-child td { border-bottom:0; }
tbody tr:hover { background:var(--surface-subtle); }

tbody tr.tm-table-row--overdue {
  background:color-mix(in srgb,var(--danger-bg) 55%,var(--surface));
}

tbody tr.tm-table-row--overdue:hover {
  background:color-mix(in srgb,var(--danger-bg) 75%,var(--surface-subtle));
}

tbody tr.tm-table-row--overdue td:first-child {
  box-shadow:inset 3px 0 0 var(--danger);
}

.tm-table__id {
  color:var(--accent);
  font-family:var(--mono);
  font-variant-numeric:tabular-nums;
  font-weight:600;
}

/* Messages and lightweight helpers */
.msg {
  margin-bottom:12px;
  padding:11px 16px;
  background:var(--surface);
  border:1px solid var(--border);
  border-left:3px solid var(--accent);
  border-radius:var(--radius);
  box-shadow:var(--shadow);
}

.meta,
.line { color:var(--muted); }

[class^="dir-"],
[class*=" dir-"] {
  border-color:var(--border);
}

.tm-spinner {
  width:16px;
  height:16px;
  display:inline-block;
  border:2px solid color-mix(in srgb,currentColor 25%,transparent);
  border-top-color:currentColor;
  border-radius:50%;
  animation:tm-spin .7s linear infinite;
}

@keyframes tm-spin { to { transform:rotate(360deg); } }

.htmx-request.tm-btn,
.htmx-request.button,
.htmx-request button {
  opacity:.75;
  pointer-events:none;
}

.tm-skeleton {
  border-radius:6px;
  background:linear-gradient(100deg,var(--tm-skeleton-a) 30%,var(--tm-skeleton-b) 50%,var(--tm-skeleton-a) 70%);
  background-size:200% 100%;
  animation:tm-shimmer 1.4s linear infinite;
}

.tm-skeleton--line { height:14px; }
@keyframes tm-shimmer { from { background-position:200% 0; } to { background-position:-200% 0; } }

@media (max-width:720px) {
  .topbar-inner {
    min-height:auto;
    align-items:flex-start;
    flex-direction:column;
    padding:12px 16px;
  }

  nav.main {
    flex-wrap:nowrap;
    overflow-x:auto;
    padding:0 12px 8px;
  }

  .dropdown {
    position:fixed;
    left:16px;
    right:16px;
    min-width:auto;
  }

  .page-head { flex-direction:column; }
  .tm-form-card,
  .tm-form-actions { padding:16px; }
  .tm-filter-actions { align-items:stretch; }
  .tm-filter-actions > * { flex:1 1 auto; }
  .actions form {
    flex:1 1 100%;
    flex-wrap:wrap;
  }
  .actions input[type=text],
  .actions select {
    width:100%;
    max-width:none;
  }
  table { display:block; overflow-x:auto; white-space:nowrap; }
}
