/* Meridian Core UI */
:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --crit: #ef4444;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.layout-shell { min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.brand {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--text);
  text-decoration: none;
}
.brand:hover {
  color: var(--accent);
  text-decoration: none;
}
.brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: .25rem; }
.nav a {
  display: block;
  padding: .55rem .75rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}
.nav a:hover, .nav a.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: .55rem .75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.nav-group-toggle:hover,
.nav-group.has-active > .nav-group-toggle {
  background: var(--surface2);
  color: var(--text);
}
.nav-group-chevron {
  width: .55rem;
  height: .55rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s ease;
  margin-left: .5rem;
  flex-shrink: 0;
}
.nav-group.expanded .nav-group-chevron {
  transform: rotate(45deg);
}
.nav-group-children {
  display: none;
  flex-direction: column;
  gap: .15rem;
  padding-left: .65rem;
  border-left: 1px solid var(--border);
  margin-left: .75rem;
}
.nav-group.expanded .nav-group-children {
  display: flex;
}
.nav-group-children a {
  display: block;
  padding: .45rem .65rem;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: .92rem;
}
.nav-group-children a:hover,
.nav-group-children a.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

.sidebar-footer { margin-top: auto; font-size: .85rem; color: var(--muted); }

.sidebar-search {
  margin: -.25rem 0 .15rem;
}
.sidebar .global-search {
  min-width: 0;
  width: 100%;
}
.sidebar .global-search-input {
  width: 100%;
  font-size: .9rem;
}
.sidebar .global-search-panel {
  left: 0;
  right: auto;
  width: min(320px, calc(100vw - 2.5rem));
}

.main { padding: 1.5rem 2rem; }
.main-frame {
  padding: 0;
  overflow: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.content-frame {
  flex: 1;
  width: 100%;
  min-height: 100vh;
  border: 0;
  background: var(--bg);
}
body.embed {
  background: var(--bg);
}
.main-embed {
  min-height: 100vh;
}
.sidebar-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: .5rem;
  font-size: .9rem;
}
.sidebar-footer-links a {
  color: var(--muted);
}
.sidebar-footer-links a:hover {
  color: var(--accent);
}

.sidebar-footer-links a:hover {
  color: var(--accent);
}

.locale-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin: .65rem 0;
  align-items: center;
}
.locale-switcher-compact {
  margin: .5rem 0 .65rem;
}
.locale-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface2);
  color: var(--muted);
  font: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s, transform .1s;
}
.locale-switch-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: rgba(59, 130, 246, .4);
}
.locale-switch-btn.is-active {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(59, 130, 246, .16);
}
.locale-switch-btn:disabled {
  opacity: .7;
  cursor: wait;
}
.locale-switcher.is-loading .locale-switch-btn:not(.is-active) {
  opacity: .45;
}
.locale-switch-label {
  font-weight: 500;
}
.locale-switch-status {
  font-size: .75rem;
  color: var(--muted);
  margin-left: .25rem;
}

html.is-locale-switching,
html.is-locale-switching body {
  transition: opacity .12s ease;
}
html.is-locale-switching body {
  opacity: .55;
  pointer-events: none;
}

.locale-toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%) translateY(12px);
  padding: .55rem 1rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: .88rem;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 1000;
  pointer-events: none;
}
.locale-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.account-section {
  margin-bottom: 1.5rem;
}
.account-section:last-child {
  margin-bottom: 0;
}
.account-section-title {
  margin: 0 0 .35rem;
  font-size: 1rem;
}
.account-section-hint {
  margin: 0 0 .75rem;
}
.account-field-status {
  display: block;
  min-height: 1.1rem;
  margin-top: .25rem;
  font-size: .8rem;
  color: var(--muted);
}
.account-field-status.is-loading {
  color: var(--muted);
}
.account-field-status.is-ok {
  color: var(--ok);
}
.account-field-status.is-error {
  color: var(--crit);
}

.account-card {
  max-width: 32rem;
}
.account-form input[disabled] {
  opacity: .65;
  cursor: not-allowed;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 1.6rem; }
.page-header-tools {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.lang-switch { font-size: .9rem; color: var(--muted); }
.lang-switch a { margin: 0 .25rem; }
.lang-switch a[aria-current="true"] { color: var(--text); font-weight: 600; }

.global-search {
  position: relative;
  min-width: min(320px, 100%);
}
.global-search-input {
  width: min(320px, 100%);
  padding: .5rem .75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}
.global-search-input:focus {
  outline: 2px solid rgba(59,130,246,.35);
  border-color: var(--accent);
}
.global-search-panel {
  position: absolute;
  top: calc(100% + .35rem);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 360px;
  overflow: auto;
}
.global-search-list {
  list-style: none;
  margin: 0;
  padding: .35rem 0;
}
.global-search-item a,
.global-search-item {
  display: block;
  padding: .55rem .75rem;
  color: var(--text);
  text-decoration: none;
}
.global-search-item a:hover {
  background: var(--surface2);
  text-decoration: none;
}
.global-search-title { display: block; font-weight: 600; }
.global-search-subtitle {
  display: block;
  font-size: .82rem;
  color: var(--muted);
  margin-top: .15rem;
}
.global-search-empty,
.global-search-loading {
  padding: .75rem;
  color: var(--muted);
  font-size: .9rem;
}
.global-search-more {
  display: block;
  padding: .55rem .75rem;
  border-top: 1px solid var(--border);
  font-size: .85rem;
}

.search-page-form {
  display: flex;
  gap: .75rem;
  align-items: end;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-page-field { margin: 0; flex: 1; min-width: 220px; }
.search-page-field input {
  width: 100%;
  max-width: none;
}
.search-hint,
.search-empty,
.search-summary {
  color: var(--muted);
  margin-bottom: 1rem;
}
.search-group { margin-bottom: 1rem; }
.search-results-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.search-result-item {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .75rem;
  align-items: baseline;
  padding: .55rem 0;
  border-bottom: 1px solid var(--border);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-subtitle,
.search-result-provider {
  font-size: .85rem;
  color: var(--muted);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.card h2, .card h3 { margin: 0 0 .75rem; font-size: 1rem; }
.card .meta { color: var(--muted); font-size: .85rem; }

.metric-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .5rem; }
.metric {
  flex: 1;
  min-width: 80px;
  background: var(--surface2);
  border-radius: 8px;
  padding: .6rem .75rem;
}
.metric .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.metric .value { font-size: 1.35rem; font-weight: 700; }

.status {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-online { background: rgba(34,197,94,.2); color: var(--ok); }
.status-offline { background: rgba(239,68,68,.2); color: var(--crit); }
.status-pending { background: rgba(245,158,11,.2); color: var(--warn); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--border);
}
.table th { color: var(--muted); font-size: .8rem; text-transform: uppercase; }

.status-summary .status {
  font-size: 1rem;
  padding: .45rem .85rem;
}
.status-table td:last-child {
  word-break: break-word;
  max-width: 28rem;
}
.status-table .status {
  white-space: nowrap;
}

.migrations-actions {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  align-items: flex-start;
}
.migrations-table code {
  font-size: .85rem;
}

.form label { display: block; margin-bottom: 1rem; }
.form input, .form select, .form textarea {
  width: 100%;
  max-width: 420px;
  margin-top: .35rem;
  padding: .55rem .7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}
.btn {
  display: inline-block;
  padding: .55rem 1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

.flash {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.flash-ok { background: rgba(34,197,94,.15); border: 1px solid var(--ok); }
.flash-err { background: rgba(239,68,68,.15); border: 1px solid var(--crit); }

.chart { height: 120px; display: flex; align-items: flex-end; gap: 3px; margin-top: .75rem; }
.chart-bar {
  flex: 1;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 4px;
  opacity: .85;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-providers {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-bottom: 1rem;
}
.auth-provider-btn {
  width: 100%;
  text-align: center;
  text-decoration: none;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: var(--muted);
  font-size: .85rem;
  margin: 1rem 0;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.auth-divider span {
  white-space: nowrap;
}

.update-step-list {
  margin: 0 0 1rem;
  padding-left: 1.25rem;
  color: var(--muted);
}
.update-step-list li {
  margin-bottom: .35rem;
}
.update-actions {
  margin-top: .5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.users-form .checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  margin: 0 1rem .75rem 0;
}
.role-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem 1rem;
  margin: .5rem 0 1rem;
}
.permission-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-top: .35rem;
}
.permission-chips-compact .permission-chip {
  font-size: .72rem;
  padding: .1rem .4rem;
}
.permission-chip {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: .78rem;
  color: var(--muted);
}
.permission-group-title {
  margin: 1rem 0 .5rem;
  font-size: .95rem;
  color: var(--muted);
}
.permission-table {
  margin-bottom: 1rem;
}

/* Access management (users & roles) */
.access-subnav {
  display: flex;
  gap: .35rem;
  margin: -0.5rem 0 1.25rem;
  padding: .35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.access-subnav-link {
  flex: 1;
  text-align: center;
  padding: .55rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.access-subnav-link:hover {
  color: var(--text);
  background: var(--surface2);
  text-decoration: none;
}
.access-subnav-link.active {
  color: var(--text);
  background: var(--surface2);
  box-shadow: inset 0 0 0 1px var(--border);
}

.access-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}
.access-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.access-stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
}
.access-stat-label {
  display: block;
  margin-top: .25rem;
  font-size: .85rem;
  color: var(--muted);
}

.card-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.card-toolbar h2 {
  margin: 0;
}

.user-create-panel summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-weight: 600;
  font-size: 1.05rem;
}
.user-create-panel summary::-webkit-details-marker {
  display: none;
}
.user-create-chevron::after {
  content: '▾';
  color: var(--muted);
  transition: transform .15s;
}
.user-create-panel[open] .user-create-chevron::after {
  transform: rotate(180deg);
}
.user-create-panel > form {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.user-cell-name {
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.user-cell-email {
  font-size: .82rem;
}
.users-table tr.is-editing {
  background: rgba(59, 130, 246, .08);
}
.table-wrap {
  overflow-x: auto;
}
.table-actions {
  white-space: nowrap;
}
.btn-sm {
  padding: .35rem .65rem;
  font-size: .82rem;
}

.role-badges {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.role-badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: .78rem;
  color: var(--text);
}
.role-badge-admin {
  border-color: rgba(59, 130, 246, .45);
  color: #93c5fd;
}

.perm-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--border);
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.form-section h3 {
  margin: 0 0 .5rem;
  font-size: .95rem;
}
.form-switches {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  margin-bottom: 1rem;
}
.switch-pill {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .4rem .75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  font-size: .88rem;
}
.switch-pill:has(input:checked) {
  border-color: rgba(59, 130, 246, .5);
  background: rgba(59, 130, 246, .12);
}
.switch-pill input {
  accent-color: var(--accent);
}

.role-picker {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.role-pill,
.permission-pill {
  display: inline-flex;
  flex-direction: column;
  gap: .15rem;
  padding: .45rem .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.role-pill:hover,
.permission-pill:hover {
  border-color: rgba(59, 130, 246, .35);
}
.role-pill.is-active,
.permission-pill.is-active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, .14);
}
.role-pill span,
.permission-pill-key {
  font-size: .88rem;
  font-weight: 500;
}
.permission-pill-desc {
  font-size: .75rem;
  color: var(--muted);
}

.permission-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: .5rem;
}
.permission-picker-group + .permission-picker-group {
  margin-top: 1rem;
}

.access-tabs {
  margin-top: .25rem;
}
.access-tablist {
  display: flex;
  gap: .35rem;
  margin-bottom: 1rem;
  padding: .35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.access-tab {
  flex: 1;
  padding: .55rem 1rem;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.access-tab:hover {
  color: var(--text);
  background: var(--surface2);
}
.access-tab.active {
  color: var(--text);
  background: var(--surface2);
  box-shadow: inset 0 0 0 1px var(--border);
}
.access-tabpanel {
  display: none;
}
.access-tabpanel.active {
  display: block;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.role-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
}
.role-card-title {
  margin: 0 0 .25rem;
  font-size: 1.1rem;
}
.role-card-key {
  font-size: .78rem;
  color: var(--muted);
}
.role-system-badge {
  flex-shrink: 0;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: rgba(245, 158, 11, .15);
  border: 1px solid rgba(245, 158, 11, .35);
  color: #fbbf24;
}
.role-card-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: .75rem;
  font-size: .85rem;
  color: var(--muted);
}
.role-card-actions {
  margin-top: 1rem;
}
.role-card-editing {
  grid-column: 1 / -1;
}
.role-permissions-form .form-actions {
  margin-top: 1rem;
}
.permission-matrix code {
  font-size: .82rem;
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar .global-search-panel {
    width: 100%;
  }
  .content-frame {
    min-height: 70vh;
  }
}
