:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef7f5;
  --text: #1f2933;
  --muted: #697586;
  --border: #d8dee7;
  --brand: #0b3d91;
  --accent: #168273;
  --accent-dark: #0f675c;
  --danger: #b42318;
  --warning: #b7791f;
  --shadow: 0 8px 24px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  text-decoration: none;
  min-width: 190px;
}

.brand-mark {
  color: var(--brand);
  font-size: 24px;
  line-height: 1;
}

.brand-logo {
  display: block;
  width: auto;
  height: 30px;
}

.navlinks {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.navlinks a {
  color: var(--muted);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 6px;
}

.navlinks a.active,
.navlinks a:hover {
  color: var(--text);
  background: #edf1f7;
}

.logout-form,
.toolbar,
.actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.main {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto 48px;
}

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

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.muted {
  color: var(--muted);
  margin: 8px 0 0;
}

.small {
  font-size: 12px;
}

.panel,
.auth-panel,
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
  overflow-x: auto;
}

.panel.narrow,
.auth-panel {
  max-width: 540px;
}

.auth-panel {
  margin: 72px auto;
  padding: 28px;
}

.auth-panel.wide {
  max-width: 720px;
}

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

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric strong {
  font-size: 28px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.upload-guidance {
  display: grid;
  gap: 10px;
}

.upload-guidance .muted {
  margin: 0;
}

.upload-guidance ul {
  margin: 0;
  padding-left: 20px;
}

.upload-guidance li {
  margin: 4px 0;
}

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

label span {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--border);
  background: #ffffff;
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px;
  font: inherit;
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.checkbox-label span {
  margin-bottom: 0;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 17px,
    calc(100% - 13px) 17px;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

input:focus,
select:focus {
  outline: 2px solid rgba(22, 130, 115, 0.24);
  border-color: var(--accent);
}

button,
.primary-button,
.secondary-button,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button img,
.primary-button img,
.secondary-button img,
.icon-button img {
  width: 16px;
  height: 16px;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

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

.secondary-button,
.icon-button {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text);
}

.icon-button.ghost {
  background: transparent;
}

.icon-button.danger {
  color: var(--danger);
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

table.spaced {
  margin-top: 18px;
}

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

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

.empty {
  text-align: center;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.status.sent {
  color: #0f675c;
  background: #dff3ee;
}

.status.draft {
  color: #7a4b05;
  background: #fff1d6;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  border-radius: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: #ffffff;
}

.flash.success {
  border-color: #9bd7c8;
  background: #e7f7f3;
}

.flash.error {
  border-color: #f3b3ac;
  background: #fff0ee;
}

.totp-layout {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 20px;
  align-items: center;
  margin-top: 18px;
}

.qr {
  width: 180px;
  height: 180px;
  border: 1px solid var(--border);
}

.secret-box {
  background: var(--surface-2);
  border: 1px solid #bfdfd8;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 8px;
}

.secret-box code {
  overflow-wrap: anywhere;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 18px 0;
}

@media (max-width: 820px) {
  .topbar,
  .page-header,
  .toolbar,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    position: static;
  }

  .navlinks {
    flex-wrap: wrap;
  }

  .metric-grid,
  .form-grid.compact,
  .totp-layout {
    grid-template-columns: 1fr;
  }

  .main {
    width: min(100vw - 20px, 1180px);
    margin-top: 18px;
  }
}
