:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1c2430;
  --muted: #68737f;
  --border: #dde3ea;
  --primary: #2563eb;
  --primary-dark: #1e4fc4;
  --danger: #dc2626;
  --ok: #16803c;
  --warn: #b45309;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}

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

.topbar {
  background: #101827;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 56px;
  flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 17px; }
.brand:hover { text-decoration: none; }
.brand-version { font-size: 11px; font-weight: 400; color: #8b98a9; vertical-align: super; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
  color: #cbd5e1;
  padding: 8px 12px;
  border-radius: 8px;
}
.topbar nav a:hover { color: #fff; background: rgba(255,255,255,.08); text-decoration: none; }
.topbar nav a.active { color: #fff; background: rgba(255,255,255,.14); }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-badge { color: #cbd5e1; font-size: 13px; }

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

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 24px; }
.breadcrumbs { margin: 0 0 4px; font-size: 13px; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 17px; }

.collapsible summary {
  cursor: pointer;
  font-weight: 600;
  user-select: none;
}
.collapsible[open] summary { margin-bottom: 12px; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.flash-success { background: #ecfdf3; color: var(--ok); border-color: #b7e4c7; }
.flash-error { background: #fef2f2; color: var(--danger); border-color: #f5c2c2; }
.flash-info { background: #eff6ff; color: var(--primary-dark); border-color: #c3d7f7; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.checkbox { flex-direction: row; align-items: center; gap: 6px; padding-top: 18px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="search"], select, textarea {
  font: inherit;
  color: var(--text);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  min-width: 0;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(37, 99, 235, .35);
  border-color: var(--primary);
}
textarea { width: 100%; resize: vertical; }

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
form.stacked { display: flex; flex-direction: column; gap: 12px; max-width: 380px; }
form.stacked button { align-self: flex-start; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.profile-grid .card { margin-bottom: 0; }
.form-row .grow { flex: 1; min-width: 200px; }
.form-row button { margin-bottom: 1px; }
form.inline { display: inline-block; margin: 0; }

.btn {
  font: inherit;
  display: inline-block;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-danger { background: #fff; border-color: #f2b8b8; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #cbd5e1; }
.btn-ghost:hover { background: rgba(255,255,255,.1); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-block { width: 100%; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table thead th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap;
  background: #fafbfd;
}
.table tbody tr:hover { background: #f8fafc; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { margin-left: 4px; }
.cell-title { max-width: 480px; }
.row-error { background: #fff7f7; }
.table-scroll { overflow-x: auto; }

.sortable thead th[data-sort] { cursor: pointer; user-select: none; }
.sortable thead th[data-sort]:hover { color: var(--text); }
.sortable thead th.sorted-asc::after { content: " ▲"; font-size: 10px; }
.sortable thead th.sorted-desc::after { content: " ▼"; font-size: 10px; }

.table-tools {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.table-tools input[type="search"] { min-width: 260px; }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.tag-ok { background: #ecfdf3; color: var(--ok); }
.tag-warn { background: #fff7ed; color: var(--warn); }
.tag-busy { background: #eff6ff; color: var(--primary-dark); }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, monospace; }
.empty { color: var(--muted); text-align: center; padding: 12px; }
.folder-link { font-weight: 600; }

.table-footer {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  flex-wrap: wrap;
}
.inline-label { flex-direction: row; align-items: center; gap: 8px; white-space: nowrap; }
.table-tools-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.select-compact { width: auto; padding: 6px 8px; }

.pager { display: flex; gap: 6px; justify-content: center; align-items: center; flex-wrap: wrap; }
.pager .page-current { background: var(--primary); border-color: var(--primary); color: #fff; cursor: default; }
.pager-ellipsis { color: var(--muted); padding: 0 2px; }

.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 360px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% - 18px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(16, 24, 39, .12);
  z-index: 20;
  max-height: 320px;
  overflow-y: auto;
}
.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text);
}
.autocomplete-item:hover, .autocomplete-item.selected { background: #eff6ff; }
.autocomplete-item img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.autocomplete-item .subs { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.autocomplete-header {
  padding: 8px 12px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

.user-badge:hover { color: #fff; text-decoration: none; }

.api-wait-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 18, 28, .6);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.api-wait-overlay[hidden] { display: none; }
.api-wait-card {
  background: var(--card);
  border-radius: 16px;
  padding: 34px 44px 26px;
  text-align: center;
  max-width: 400px;
  box-shadow: 0 24px 60px rgba(13, 18, 28, .4);
  animation: api-wait-in .22s cubic-bezier(.2, .9, .3, 1.2);
}
.api-wait-spinner {
  width: 58px;
  height: 58px;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 12%, #93c5fd 45%, var(--primary) 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  animation: api-wait-spin .9s linear infinite;
  position: relative;
}
.api-wait-core {
  position: absolute;
  top: -1px;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
}
.api-wait-message { font-weight: 600; font-size: 16px; margin: 18px 0 2px; }
.api-wait-elapsed { margin: 2px 0 6px; font-variant-numeric: tabular-nums; }
@keyframes api-wait-spin { to { transform: rotate(360deg); } }
@keyframes api-wait-in {
  from { opacity: 0; transform: translateY(14px) scale(.94); }
  to { opacity: 1; transform: none; }
}
