:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --text: #172026;
  --muted: #63707a;
  --line: #dce3e8;
  --primary: #126b5c;
  --primary-dark: #0b4f44;
  --danger: #a33a2c;
  --warning: #8a6500;
  --ok: #1f6f42;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a {
  color: inherit;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: #101820;
  color: white;
}

.topbar span {
  margin-left: 10px;
  color: #b9c7cf;
}

.topbar nav {
  align-items: center;
  display: flex;
  gap: 18px;
}

.topbar a {
  color: white;
  text-decoration: none;
  font-size: 14px;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  border: 0;
  padding: 0;
  background: transparent;
  color: white;
  cursor: pointer;
  font: inherit;
  font-size: 14px;
}

.auth-body {
  min-height: 100vh;
  background: #101820;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  border: 1px solid #263742;
  border-radius: 8px;
  padding: 28px;
  background: white;
}

.auth-brand {
  display: flex;
  gap: 10px;
  margin-bottom: 22px;
}

.auth-brand span {
  color: var(--muted);
}

.auth-panel h1 {
  font-size: 26px;
}

.auth-panel p {
  color: var(--muted);
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.title-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.page-title p,
.hint,
.muted {
  color: var(--muted);
}

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 14px;
  background: white;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  cursor: pointer;
}

.button:disabled {
  cursor: wait;
  opacity: 0.8;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.button-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.toolbar,
.panel,
.empty-state,
.stat-card,
.alert {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  margin-bottom: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(160px, 0.8fr) minmax(160px, 0.8fr) minmax(160px, 0.8fr) auto;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--text);
  background: white;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  padding: 18px;
}

.stat-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  font-size: 24px;
}

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  padding: 18px;
}

.sync-form,
.company-form {
  display: grid;
  gap: 14px;
}

.sync-form {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

.sync-form.is-loading .button-spinner {
  display: inline-block;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-panel {
  max-width: 720px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.mono {
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 10px;
  background: #eef2f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.success,
.badge.downloaded {
  background: #e3f5ea;
  color: var(--ok);
}

.badge.failed {
  background: #fae7e3;
  color: var(--danger);
}

.badge.running,
.badge.listed {
  background: #fff4cf;
  color: var(--warning);
}

.run-list {
  display: grid;
  gap: 10px;
}

.run-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}

.run-row p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.row-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.empty-state {
  padding: 36px;
  text-align: center;
}

.alert {
  margin-bottom: 18px;
  padding: 14px 18px;
  color: var(--danger);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(16, 24, 32, 0.42);
}

.loading-overlay.is-visible {
  display: flex;
}

.loading-box {
  width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: white;
  text-align: center;
  box-shadow: 0 18px 50px rgba(16, 24, 32, 0.22);
}

.loading-box strong {
  display: block;
  margin: 12px 0 6px;
  font-size: 18px;
}

.loading-box p {
  margin-bottom: 0;
  color: var(--muted);
}

.large-spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border: 4px solid #dce3e8;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.center {
  text-align: center;
}

@media (max-width: 860px) {
  .page-title,
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
  }

  .topbar {
    padding: 18px;
  }

  .title-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form,
  .toolbar,
  .stats-grid,
  .panel-grid,
  .sync-form {
    grid-template-columns: 1fr;
  }
}
