:root {
  --bg:#04040f;
  --bg-card:#0d0d1f;
  --bg-hover:#131328;
  --accent:#00d4ff;
  --accent-dim:#00a8cc;
  --active:#1a5fb4;
  --border:#1e1e3f;
  --text:#e8e8f0;
  --muted:#6b7280;
  --success:#00e676;
  --warning:#ff9800;
  --error:#ff4655;
  --surface:rgba(13,13,31,0.92);
  --surface-soft:rgba(7,10,22,0.72);
  --radius:8px;
  --radius-lg:12px;
  --shadow:0 18px 46px rgba(0,0,0,0.28);
  --focus:0 0 0 3px rgba(0,212,255,0.22);
}

* { box-sizing:border-box; }
html { min-height:100%; }
body {
  margin:0;
  min-height:100vh;
  font-family:"Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  color:var(--text);
  background:
    radial-gradient(circle at 82% 0%, rgba(0,212,255,0.10), transparent 27rem),
    linear-gradient(180deg, rgba(4,4,15,0.98), rgba(6,8,20,1));
  font-size:clamp(14px, 0.82vw, 16px);
  line-height:1.5;
}

a { color:inherit; text-decoration:none; }
a:hover { color:var(--accent); }
:focus-visible { outline:0; box-shadow:var(--focus); }

.layout { display:flex; min-height:100vh; }
.sidebar {
  position:fixed;
  inset:0 auto 0 0;
  z-index:120;
  width:244px;
  padding:22px 18px;
  background:rgba(8,8,20,0.96);
  border-right:1px solid var(--border);
  backdrop-filter:blur(16px);
  display:flex;
  flex-direction:column;
  gap:24px;
}
.brand { margin:0; }
.mobile-brand img { display:block; height:30px; max-width:180px; }
.brand img { display:block; height:52px; max-width:200px; }
.nav { display:grid; gap:6px; }
.nav a {
  min-height:44px;
  display:flex;
  align-items:center;
  padding:10px 12px;
  border:1px solid transparent;
  border-radius:var(--radius);
  color:var(--muted);
  font-weight:600;
  font-size:0.94rem;
  transition:background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.nav a:hover { background:var(--bg-hover); color:var(--text); border-color:var(--border); }
.nav a.active {
  background:rgba(26,95,180,0.24);
  color:var(--accent);
  border-color:rgba(0,212,255,0.30);
}
.sidebar-footer {
  margin-top:auto;
  display:grid;
  gap:9px;
}
.sidebar-user {
  color:var(--muted);
  font-size:0.78rem;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.logout-link {
  display:flex;
  align-items:center;
  justify-content:center;
  min-height:40px;
  padding:9px 12px;
  border-radius:var(--radius);
  border:1px solid var(--border);
  color:var(--muted);
  font-size:0.88rem;
  font-weight:600;
  transition:background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.logout-link:hover { background:rgba(255,70,85,0.08); color:var(--error); border-color:rgba(255,70,85,0.34); }

.mobile-header { display:none; }
.nav-toggle {
  position:absolute;
  width:1px;
  height:1px;
  opacity:0;
}
.nav-toggle:focus-visible + .mobile-header .nav-toggle-label { box-shadow:var(--focus); }
.nav-backdrop { display:none; }

.content {
  flex:1;
  min-width:0;
  margin-left:244px;
  padding:28px;
}
.page {
  width:100%;
  max-width:1680px;
  margin:0 auto;
  display:grid;
  gap:24px;
}
.hero { display:grid; gap:6px; max-width:860px; }
h1, h2, h3, p { margin-top:0; }
h1 { font-size:clamp(1.55rem, 1.7vw, 2.2rem); line-height:1.15; margin-bottom:0; }
.hero h1, .panel h2, .panel h3 { margin:0; }
.panel h2 { font-size:clamp(1.05rem, 1vw, 1.28rem); line-height:1.25; }
.panel h3 { font-size:1rem; line-height:1.3; }
.muted { color:var(--muted); }
.is-hidden { display:none !important; }
.section-heading { margin:0 0 8px; }
.section-copy { margin:0 0 18px; color:var(--muted); max-width:760px; }
.meta-line { margin:0; padding:0 4px; color:var(--muted); font-size:0.86rem; }
.error-text { color:var(--error); }

.panel {
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  padding:22px;
  box-shadow:var(--shadow);
}
.sub-panel {
  padding:16px;
  background:rgba(7,10,22,0.64);
  box-shadow:none;
}
.panel-header {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  margin-bottom:16px;
}
.stack { display:grid; gap:16px; }
.stack-tight { display:grid; gap:12px; }
.reveal-panel { margin-bottom:16px; }
.form-stack { margin-top:12px; }
.split { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:20px; align-items:start; }
.grid-2 { display:grid; grid-template-columns:minmax(0,2fr) minmax(320px,1fr); gap:24px; }
.grid-3 { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:18px; }
.table-wrap { width:100%; overflow-x:auto; border-radius:var(--radius); }

.flash, .banner, .error-banner, .message {
  padding:13px 15px;
  border-radius:var(--radius);
  border:1px solid transparent;
  font-size:0.92rem;
}
.flash.success, .banner.success {
  color:var(--success);
  background:rgba(0,230,118,0.09);
  border-color:rgba(0,230,118,0.28);
}
.flash.error, .banner.error, .error-banner {
  color:var(--error);
  background:rgba(255,70,85,0.10);
  border-color:rgba(255,70,85,0.30);
}
.flash.info, .banner.info, .message {
  color:var(--text);
  background:rgba(0,212,255,0.08);
  border-color:rgba(0,212,255,0.24);
}

table { width:100%; border-collapse:collapse; min-width:720px; }
th, td {
  padding:13px 12px;
  border-bottom:1px solid var(--border);
  text-align:left;
  vertical-align:top;
}
th {
  color:var(--muted);
  font-size:0.78rem;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:0.04em;
}
tbody tr { transition:background 0.15s ease; }
tbody tr:hover { background:rgba(19,19,40,0.56); }
.code-pill {
  display:inline-block;
  max-width:56rem;
  padding:4px 8px;
  border-radius:6px;
  background:rgba(0,0,0,0.28);
  border:1px solid rgba(255,255,255,0.05);
  color:var(--text);
  font-family:ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size:0.9rem;
  overflow-wrap:anywhere;
}

.badge {
  display:inline-flex;
  align-items:center;
  gap:6px;
  width:max-content;
  padding:5px 9px;
  border-radius:999px;
  border:1px solid var(--border);
  font-size:0.82rem;
  font-weight:700;
  white-space:nowrap;
  background:rgba(7,10,22,0.62);
}
.badge.success { color:var(--success); border-color:rgba(0,230,118,0.32); }
.badge.warning { color:var(--warning); border-color:rgba(255,152,0,0.34); }
.badge.error { color:var(--error); border-color:rgba(255,70,85,0.34); }
.badge.active { color:var(--accent); border-color:rgba(0,212,255,0.30); }
.badge.small { font-size:0.75rem; }

form { display:grid; gap:14px; }
label { display:grid; gap:7px; color:var(--text); font-size:0.92rem; font-weight:600; }
input, select, button, .button, .btn-primary, .btn-secondary, .ms-btn {
  border-radius:var(--radius);
  font:inherit;
}
input, select {
  width:100%;
  min-height:44px;
  padding:10px 12px;
  border:1px solid var(--border);
  background:rgba(7,10,22,0.95);
  color:var(--text);
  transition:border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
input::placeholder { color:rgba(107,114,128,0.78); }
input:focus, select:focus { outline:0; border-color:rgba(0,212,255,0.55); box-shadow:var(--focus); }
input[readonly], input:disabled, select:disabled {
  color:var(--muted);
  opacity:0.78;
  cursor:not-allowed;
}

button, .button, .btn-primary, .btn-secondary, .ms-btn {
  min-height:44px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:9px;
  width:auto;
  padding:10px 16px;
  border:1px solid transparent;
  background:linear-gradient(135deg, var(--active), var(--accent-dim));
  color:var(--text);
  font-weight:700;
  cursor:pointer;
  text-decoration:none;
  transition:background 0.15s ease, border-color 0.15s ease, color 0.15s ease, filter 0.15s ease, opacity 0.15s ease;
}
button:hover, .button:hover, .btn-primary:hover { filter:brightness(1.08); color:var(--text); }
button.secondary, .button.secondary, .btn-secondary {
  background:transparent;
  border-color:var(--border);
  color:var(--text);
}
button.secondary:hover, .button.secondary:hover, .btn-secondary:hover {
  background:rgba(0,212,255,0.07);
  border-color:rgba(0,212,255,0.32);
  color:var(--accent);
  filter:none;
}
.button.ghost, button.ghost { background:transparent; border-color:transparent; color:var(--muted); }
.button.outline, button.outline { background:transparent; border-color:rgba(0,212,255,0.36); color:var(--accent); }
.button.destructive, button.destructive { background:rgba(255,70,85,0.12); border-color:rgba(255,70,85,0.34); color:var(--error); }
button:disabled, .button[aria-disabled="true"] { opacity:0.55; cursor:not-allowed; filter:none; }
.actions { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.actions a { display:inline-flex; }
.compact-button { min-height:36px; padding:7px 12px; font-size:0.86rem; }

details {
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:11px 13px;
  background:rgba(7,10,22,0.70);
}
summary { cursor:pointer; color:var(--accent); font-weight:700; }

.stat-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:18px; }
.stat-card { padding:22px; display:grid; gap:8px; align-content:start; text-align:left; min-height:150px; }
.stat-icon {
  width:42px;
  height:30px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:999px;
  border:1px solid rgba(0,212,255,0.24);
  background:rgba(0,212,255,0.07);
  color:var(--accent);
  font-size:0.72rem;
  font-weight:800;
  letter-spacing:0.04em;
}
.stat-number {
  min-height:3rem;
  display:flex;
  align-items:center;
  color:var(--accent);
  font-size:clamp(2rem, 2.8vw, 3rem);
  font-weight:800;
  line-height:1;
}
.stat-label { color:var(--muted); font-size:0.9rem; font-weight:700; }
.spinner-inline, .spinner {
  display:inline-block;
  width:20px;
  height:20px;
  border:2px solid var(--border);
  border-top-color:var(--accent);
  border-radius:50%;
  animation:spin 0.8s linear infinite;
}
.spinner-wrap { display:flex; align-items:center; gap:10px; padding:18px 4px; color:var(--muted); }
@keyframes spin { to { transform:rotate(360deg); } }

.scroll-panel {
  max-height:60vh;
  overflow:auto;
  scrollbar-width:thin;
  scrollbar-color:#163549 transparent;
}
.domain-card, .user-card, .mailbox-card {
  border:1px solid var(--border);
  border-radius:var(--radius);
  background:rgba(13,13,31,0.84);
  transition:border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.domain-card {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
  padding:14px 16px;
  margin-bottom:8px;
}
.domain-card:hover, .user-card:hover, .mailbox-card:hover { background:rgba(19,19,40,0.72); border-color:rgba(0,212,255,0.24); }
.domain-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.domain-dot.success { background:var(--success); }
.domain-dot.warning { background:var(--warning); }
.domain-name { flex:1; min-width:0; font-weight:700; overflow-wrap:anywhere; }
.domain-actions { display:flex; gap:8px; align-items:center; flex-wrap:wrap; justify-content:flex-end; }
.domain-actions form { margin:0; display:inline-flex; }
.help-box { margin-top:20px; padding-top:16px; border-top:1px solid var(--border); }
.help-box p { margin:0; color:var(--muted); font-size:0.88rem; }

.user-card {
  display:flex;
  align-items:flex-start;
  gap:14px;
  padding:14px 16px;
  margin-bottom:8px;
  cursor:pointer;
}
.user-card.selected { border-color:var(--accent); background:rgba(0,212,255,0.06); box-shadow:0 0 0 1px rgba(0,212,255,0.12); }
.avatar {
  width:40px;
  height:40px;
  border-radius:50%;
  background:rgba(26,95,180,0.86);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:800;
  color:#fff;
  flex-shrink:0;
  letter-spacing:0.03em;
}
.user-info { flex:1; min-width:0; }
.user-name { font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-upn, .user-lic, .user-badge { color:var(--muted); font-size:0.83rem; overflow:hidden; text-overflow:ellipsis; }
.user-upn { white-space:nowrap; }
.user-lic { margin-top:4px; }
.user-actions { display:flex; flex-direction:column; align-items:flex-end; gap:6px; flex-shrink:0; }
.domain-tag {
  display:inline-flex;
  padding:3px 9px;
  border-radius:999px;
  border:1px solid var(--border);
  color:var(--muted);
  background:rgba(26,95,180,0.10);
  font-size:0.76rem;
  font-weight:700;
  white-space:nowrap;
}
.btn-alias, .btn-dots {
  min-height:32px !important;
  width:auto !important;
  padding:4px 10px !important;
  border-radius:7px !important;
  background:transparent !important;
  border:1px solid var(--border) !important;
  color:var(--muted) !important;
  font-size:0.78rem !important;
  white-space:nowrap;
}
.btn-alias:hover, .btn-dots:hover { border-color:rgba(0,212,255,0.30) !important; color:var(--accent) !important; }
.btn-dots { font-size:1rem !important; line-height:1; }

.mailbox-card { padding:14px 16px; margin-bottom:8px; }
.mailbox-card.highlighted { border-color:var(--accent); background:rgba(0,212,255,0.05); }
.mailbox-header { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; margin-bottom:6px; }
.mailbox-title { font-weight:700; margin-bottom:3px; }
.mailbox-email, .mailbox-email-link { color:var(--muted); font-size:0.86rem; overflow-wrap:anywhere; }
.mailbox-email-link { color:var(--accent); }
.mailbox-users-label {
  margin-top:9px;
  margin-bottom:3px;
  color:var(--muted);
  font-size:0.74rem;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:0.04em;
}
.mailbox-users { color:var(--muted); font-size:0.82rem; overflow-wrap:anywhere; }
.inline-field { display:flex; gap:6px; align-items:center; }
.inline-field > input, .inline-field > select { flex:1; min-width:0; }
.inline-separator { color:var(--muted); font-size:1rem; }
.alias-panel {
  position:fixed;
  z-index:400;
  min-width:340px;
  max-width:min(440px, calc(100vw - 16px));
  padding:18px;
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  background:var(--bg-card);
  box-shadow:0 16px 44px rgba(0,0,0,0.52);
}
.alias-panel input, .alias-panel select { min-height:38px; padding:8px 10px; font-size:0.88rem; }
.alias-head { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:12px; }
.alias-title { font-weight:700; font-size:0.95rem; }
.alias-divider { margin-top:14px; border-top:1px solid var(--border); padding-top:12px; }
.alias-addr { display:flex; align-items:center; gap:8px; margin-bottom:6px; font:0.84rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.alias-primary { color:var(--accent); }
.alias-secondary { color:var(--muted); }
.alias-badge { color:var(--muted); font:0.72rem "Segoe UI", system-ui, sans-serif; }
.inline-form { display:grid; gap:8px; margin-top:6px; }
.inline-form label { font-size:0.88rem; }
.inline-form button { font-size:0.88rem; padding:8px 14px; }
.inline-form input, .inline-form select { padding:8px 10px; }
.inline-note { color:var(--muted); font-size:0.88rem; margin:0; }
.inline-error { color:var(--error); font-size:0.88rem; margin:0; }
.perm-form { display:none; margin-top:12px; }
.page-emails .content { display:flex; flex-direction:column; }
.page-emails .page { flex:1; min-height:0; display:flex; flex-direction:column; }
.page-emails .split { flex:1; align-items:stretch; min-height:0; }
.page-emails .split > .panel { display:flex; flex-direction:column; min-height:0; }
.page-emails #user-list { flex:1; max-height:none; }
.page-emails #mailbox-container { flex:1; min-height:0; overflow-y:auto; scrollbar-width:thin; scrollbar-color:#163549 transparent; }
.page-emails #mailbox-container .scroll-panel { max-height:none; overflow:visible; }

.qr-box {
  width:180px;
  height:180px;
  border:1px solid var(--border);
  background:#fff;
  padding:10px;
  border-radius:var(--radius);
}

.auth-page {
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
}
.auth-shell {
  width:min(100%, 920px);
  display:grid;
  grid-template-columns:minmax(280px, 0.9fr) minmax(320px, 420px);
  gap:22px;
  align-items:stretch;
}
.auth-aside {
  display:grid;
  align-content:space-between;
  min-height:430px;
  padding:32px;
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  background:rgba(7,10,22,0.56);
}
.auth-aside img { height:34px; width:max-content; max-width:210px; }
.auth-copy { align-self:end; max-width:28rem; }
.auth-copy h1 { margin:0 0 10px; font-size:clamp(1.45rem, 1.35vw, 1.85rem); }
.auth-copy p { margin:0; color:var(--muted); }
.box {
  width:100%;
  max-width:420px;
  padding:38px 34px;
  border:1px solid var(--border);
  border-radius:var(--radius-lg);
  background:var(--surface);
  box-shadow:var(--shadow);
  text-align:center;
}
.auth-shell .box { max-width:none; }
.logo { height:38px; margin:0 auto 10px; display:block; max-width:210px; }
.sub { color:var(--muted); font-size:0.92rem; margin:0 0 28px; }
.box form { gap:12px; text-align:left; }
.box .btn-primary, .box .btn-secondary, .box .ms-btn { width:100%; }
.btn-primary { background:var(--accent); color:var(--bg); }
.btn-primary:hover { color:var(--bg); }
.divider { color:var(--muted); font-size:0.82rem; margin:22px 0 12px; }
.link { color:var(--accent); font-size:0.9rem; font-weight:700; }
.links, .forgot { margin-top:16px; }
.ms-btn {
  background:#2f2f2f;
  border-color:#444;
  color:#fff;
}
.ms-btn:hover { background:#3a3a3a; color:#fff; filter:none; }
.ms-logo { width:20px; height:20px; flex-shrink:0; }
.role { color:var(--muted); font-size:0.84rem; font-weight:700; }
.tenant-list { display:grid; gap:12px; }
.tenant-list form { margin:0; }

/* <= 1024px: tablet layouts collapse dense two-column work areas. */
@media (max-width:1024px) {
  .grid-2, .grid-3, .split { grid-template-columns:1fr; }
  .stat-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .auth-shell { grid-template-columns:1fr; max-width:460px; }
  .auth-aside { display:none; }
}

/* <= 800px: mobile shell switches to top bar plus off-canvas navigation. */
@media (max-width:800px) {
  body { font-size:15px; }
  .layout { display:block; }
  .mobile-header {
    position:sticky;
    top:0;
    z-index:220;
    display:flex;
    align-items:center;
    justify-content:space-between;
    min-height:60px;
    padding:12px 16px;
    border-bottom:1px solid var(--border);
    background:rgba(8,8,20,0.96);
    backdrop-filter:blur(16px);
  }
  .nav-toggle-label {
    width:44px;
    height:44px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    border:1px solid var(--border);
    border-radius:var(--radius);
    color:var(--text);
    cursor:pointer;
  }
  .nav-toggle-label span,
  .nav-toggle-label span::before,
  .nav-toggle-label span::after {
    display:block;
    width:18px;
    height:2px;
    border-radius:2px;
    background:currentColor;
    content:"";
  }
  .nav-toggle-label span::before { transform:translateY(-6px); }
  .nav-toggle-label span::after { transform:translateY(4px); }
  .sidebar {
    width:min(82vw, 320px);
    transform:translateX(-105%);
    transition:transform 0.18s ease;
    box-shadow:20px 0 44px rgba(0,0,0,0.36);
  }
  .nav-backdrop {
    position:fixed;
    inset:0;
    z-index:110;
    background:rgba(4,4,15,0.58);
  }
  .nav-toggle:checked ~ .sidebar { transform:translateX(0); }
  .nav-toggle:checked ~ .nav-backdrop { display:block; }
  .content { margin-left:0; padding:18px 16px 28px; }
  .page { gap:18px; }
  .panel { padding:18px; }
  .panel-header { align-items:flex-start; flex-direction:column; }
  .domain-card { align-items:flex-start; flex-direction:column; }
  .domain-actions { justify-content:flex-start; }
  .page-emails .page { display:grid; }
  .page-emails .split > .panel { min-height:auto; }
}

/* <= 480px: small phones get single-column metrics and full-width actions. */
@media (max-width:480px) {
  .stat-grid { grid-template-columns:1fr; }
  .content { padding-left:12px; padding-right:12px; }
  .box { padding:30px 22px; }
  .actions { flex-direction:column; align-items:stretch; }
  .actions button, .actions .button, .actions a { width:100%; }
  .inline-field { align-items:stretch; flex-direction:column; }
  .user-card { display:grid; grid-template-columns:40px 1fr; }
  .user-actions { grid-column:2; flex-direction:row; align-items:center; justify-content:space-between; }
}

/* >= 2560px: ultrawide keeps work surfaces centered instead of stretching endlessly. */
@media (min-width:2560px) {
  .content { padding-top:40px; }
  .page { max-width:1680px; }
}
