:root {
  --color-bg: #fafaf9;
  --color-surface: #ffffff;
  --color-surface-2: #f2f2f0;
  --color-border: #e2e2df;
  --color-text: #1c1c1b;
  --color-text-muted: #6b6b68;
  --color-accent: #1052BA;
  --color-accent-contrast: #ffffff;
  --color-accent-text: #1052BA;
  --color-danger: #a02f27;
  --color-success: #1a7f4e;
  --color-warning: #8a6200;
  --radius: 10px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121212;
    --color-surface: #1a1a1a;
    --color-surface-2: #202020;
    --color-border: #2e2e2c;
    --color-text: #ededec;
    --color-text-muted: #a3a3a0;
    --color-accent: #1052BA;
    --color-accent-contrast: #ffffff;
    --color-accent-text: #ffffff;
    --color-danger: #ff6b60;
    --color-success: #4ade80;
    --color-warning: #facc15;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

.lang-switch {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 4px;
  font-size: 12px;
  z-index: 10;
}

.lang-switch a {
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 4px 7px;
  border-radius: 6px;
}

.lang-switch a:hover {
  color: var(--color-text);
}

.lang-switch a.active {
  color: var(--color-text);
  background: var(--color-surface-2);
  font-weight: 600;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* Login */

.login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 32px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
}

.login-card .subtitle {
  color: var(--color-text-muted);
  font-size: 13px;
  margin: 0 0 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
}

.field input {
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 10px 12px;
}

.field input:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.field .helper {
  font-size: 12px;
  color: var(--color-text-muted);
}

.field .error {
  font-size: 12px;
  color: var(--color-danger);
}

.form-error {
  background: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface));
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

button.primary {
  width: 100%;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  border: none;
  border-radius: 7px;
  padding: 9px 14px;
  cursor: pointer;
}

button.primary:hover {
  filter: brightness(1.05);
}

button.primary:active {
  transform: scale(0.98);
}

.login-note {
  margin-top: 20px;
  font-size: 12px;
  color: var(--color-text-muted);
}

/* App shell (sidebar + content) */

.app-shell {
  display: flex;
  min-height: 100dvh;
}

.app-nav {
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100dvh;
  overflow-y: auto;
  width: 200px;
  flex: 0 0 200px;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 20px 12px;
}

.app-nav-brand {
  font-size: 14px;
  font-weight: 700;
  padding: 0 10px 16px;
}

.app-nav nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-nav nav a {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  color: var(--color-text-muted);
  text-decoration: none;
}

.app-nav nav a:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.app-nav nav a.active {
  color: var(--color-text);
  background: var(--color-surface-2);
  font-weight: 600;
}

.app-main {
  flex: 1;
  min-width: 0;
}

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }
  .app-nav {
    position: static;
    height: auto;
    overflow-y: visible;
    width: auto;
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: 12px;
  }
  .app-nav nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  th.actions,
  td.row-actions {
    position: static;
    box-shadow: none;
    border-left: none;
  }
  .dashboard {
    padding: 16px;
  }
  td.cell-stack span,
  td.cell-stack small {
    max-width: 150px;
  }
}

/* Dashboard */

.dashboard {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  min-width: 0;
}

.dashboard-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.dashboard-header h1 {
  font-size: 18px;
  margin: 0;
}

.dashboard-header .tenant-url {
  color: var(--color-text-muted);
  font-size: 13px;
}

.logout-form button {
  font: inherit;
  font-size: 13px;
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: 5px 11px;
  cursor: pointer;
}

.logout-form button:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.stat {
  flex: 1 1 160px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.stat .value {
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat .label {
  font-size: 12px;
  color: var(--color-text-muted);
}

table.accounts {
  width: 100%;
  min-width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

table.accounts th {
  text-align: left;
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 600;
  padding: 8px 12px;
  white-space: nowrap;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

table.accounts td {
  padding: 12px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  white-space: nowrap;
  background: var(--color-bg);
}

table.accounts td.muted,
table.accounts th.wide {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.accounts tr:last-child td {
  border-bottom: none;
}

table.accounts th.num,
table.accounts td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

th.actions,
td.row-actions {
  position: sticky;
  right: 0;
  z-index: 2;
  text-align: right;
  white-space: nowrap;
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  box-shadow: -12px 0 12px -12px rgba(0, 0, 0, 0.45);
}

th.actions {
  z-index: 3;
}

td.row-actions button {
  font: inherit;
  font-size: 12px;
  line-height: 1.2;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  padding: 4px 9px;
  margin-left: 4px;
  cursor: pointer;
}

td.row-actions button.btn-icon.primary {
  width: 30px;
  padding: 0;
}

button.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
}

button.btn-icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

td.row-actions button:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

td.row-actions button.primary {
  width: auto;
  font-size: 12px;
  padding: 4px 9px;
  font-weight: 600;
  color: var(--color-accent-contrast);
  background: var(--color-accent);
  border-color: transparent;
}

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

.header-actions button.primary {
  width: auto;
  font-size: 13px;
  padding: 6px 12px;
}

.table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.table-scroll table.accounts tr:last-child td {
  border-bottom: none;
}

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

tr.voided td {
  opacity: 0.55;
  text-decoration: line-through;
}

tr.voided td.row-actions,
tr.voided .badge {
  text-decoration: none;
  opacity: 1;
}

dialog.modal {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-card);
  padding: 0;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-form {
  padding: 24px;
}

.modal-form h2 {
  font-size: 17px;
  margin: 0 0 18px;
}

.modal-account {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: -10px 0 18px;
}

.modal-warning {
  font-size: 12px;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 16px;
}

.field-row {
  display: flex;
  gap: 14px;
}

.field-row .field {
  flex: 1;
  min-width: 0;
}

.field-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: -8px 0 16px;
}

.modal-form input,
.modal-form select {
  width: 100%;
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 9px 11px;
}

.modal-form input:focus-visible,
.modal-form select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.modal-form input.is-off,
.modal-form select.is-off {
  opacity: 0.5;
  background: var(--color-surface-2);
  cursor: not-allowed;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.modal-actions button {
  font: inherit;
  font-size: 13px;
  width: auto;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: 7px 15px;
  cursor: pointer;
}

.modal-actions button:hover {
  color: var(--color-text);
}

.modal-actions button.primary {
  font-weight: 600;
  color: var(--color-accent-contrast);
  background: var(--color-accent);
  border-color: transparent;
}

.modal-actions button.danger {
  font-weight: 600;
  color: #fff;
  background: var(--color-danger);
  border-color: transparent;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.badge-active {
  background: color-mix(in srgb, var(--color-success) 16%, transparent);
  color: var(--color-success);
}

.badge-overdue {
  background: color-mix(in srgb, var(--color-danger) 16%, transparent);
  color: var(--color-danger);
}

.badge-suspended,
.badge-canceled {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

.empty-state {
  padding: 48px 12px;
  text-align: center;
  color: var(--color-text-muted);
}

.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface));
  border: 1px solid var(--color-danger);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 18px;
}

.session-banner strong {
  font-size: 14px;
  color: var(--color-danger);
}

.session-banner p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

.session-banner .reconnect {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: var(--color-danger);
  border-radius: 7px;
  padding: 7px 14px;
}

button.link {
  font: inherit;
  font-size: 13px;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-bottom: 1px dashed var(--color-border);
  padding: 2px 0;
  cursor: pointer;
}

button.link:hover {
  color: var(--color-text);
  border-bottom-color: var(--color-text-muted);
}

td.row-actions button.danger-link {
  color: var(--color-danger);
  border-color: color-mix(in srgb, var(--color-danger) 40%, transparent);
}

td.row-actions button.danger-link:hover {
  color: #fff;
  background: var(--color-danger);
  border-color: transparent;
}

.modal-total {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-accent-text);
  background: var(--color-surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  margin: -6px 0 16px;
  min-height: 20px;
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.filter-chips {
  display: flex;
  gap: 6px;
}

.filter-chips a {
  font-size: 12px;
  text-decoration: none;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 5px 12px;
}

.filter-chips a:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.filter-chips a.active {
  color: var(--color-accent-contrast);
  background: var(--color-accent);
  border-color: transparent;
  font-weight: 600;
}

.filter-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 13px;
}

.filter-form label {
  color: var(--color-text-muted);
}

.filter-form input,
.filter-form select {
  font: inherit;
  font-size: 12px;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: 5px 9px;
}

.filter-form select {
  max-width: 200px;
}

.filter-form button {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 7px;
  padding: 5px 12px;
  cursor: pointer;
}

.filter-form button:hover {
  border-color: var(--color-text-muted);
}

td.cell-stack {
  line-height: 1.35;
}

td.cell-stack span {
  display: block;
}

td.cell-stack small {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
}

td.cell-stack span,
td.cell-stack small {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

a.btn-icon.view-toggle {
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  text-decoration: none;
}

a.btn-icon.view-toggle:hover {
  color: var(--color-text);
  border-color: var(--color-text-muted);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.account-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
}

.account-card header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.account-card-name {
  min-width: 0;
}

.account-card-name strong {
  display: block;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card-name small {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin: 0 0 14px;
}

.account-card dl div {
  min-width: 0;
}

.account-card dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.account-card dd {
  margin: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card dd small {
  color: var(--color-text-muted);
  font-size: 12px;
}

.account-card footer {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  border-top: 1px solid var(--color-border);
  padding-top: 12px;
}

.account-card footer button {
  font: inherit;
  font-size: 12px;
  color: var(--color-text-muted);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  cursor: pointer;
}

.account-card footer button.primary {
  color: var(--color-accent-contrast);
  background: var(--color-accent);
  border-color: transparent;
}

button.btn-icon.danger {
  color: var(--color-danger);
  background: transparent;
  border: 1px solid var(--color-border);
}

button.btn-icon.danger:hover {
  color: #fff;
  background: var(--color-danger);
  border-color: transparent;
}

.badge-mirror {
  background: color-mix(in srgb, var(--color-text-muted) 18%, transparent);
  color: var(--color-text-muted);
  font-weight: 500;
}

a.stat.stat-link {
  color: inherit;
  text-decoration: none;
}

a.stat.stat-link:hover {
  border-color: var(--color-text-muted);
}

a.stat.stat-link .label {
  color: var(--color-accent);
}

.group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin: 22px 0 10px;
}

.group-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.group-summary {
  font-size: 12px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.form-ok {
  background: color-mix(in srgb, var(--color-success) 12%, var(--color-surface));
  border: 1px solid var(--color-success);
  color: var(--color-success);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

.settings-form {
  max-width: 640px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
}

.settings-form h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin: 22px 0 12px;
}

.settings-form h2:first-of-type {
  margin-top: 12px;
}

.settings-form .modal-actions {
  margin-top: 22px;
}

/* Email Privacy / Censoring */
body.hide-emails td.cell-stack small,
body.hide-emails .account-card-name small,
body.hide-emails .account-email,
body.hide-emails small.account-email {
  filter: blur(5px);
  user-select: none;
  transition: filter 0.2s ease-in-out;
}

body.hide-emails td.cell-stack small:hover,
body.hide-emails .account-card-name small:hover,
body.hide-emails .account-email:hover,
body.hide-emails small.account-email:hover {
  filter: blur(0);
}
