/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/* ── Design tokens (AVI-SPL brand) ─────────────────────────────────────────── */
:root {
  --ink:     #0A1D5F;
  --ink-mid: #112574;
  --blue:    #0972CE;
  --teal:    #37C1CE;
  --snow:    #f7f8fb;
  --cloud:   #eef0f6;
  --mist:    #e2e4ef;
  --surface: #ffffff;
  --text:    #1a1a2e;
  --muted:   #5a6278;
  --silver:  #abafc4;
  --danger:  #d13438;
  --warn:    #f7a800;
  --rad:     10px;
}

/* ── Base ───────────────────────────────────────────────────────────────────── */
html, body {
  height: 100%;
  font-family: 'IBM Plex Sans', system-ui, Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--snow);
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }

/* ── Full-page centred layouts (sign-in, loading, blocked) ──────────────────── */
#signin-screen,
#loading-screen,
#blocked-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--snow);
}

/* ── Sign-in / blocked card ─────────────────────────────────────────────────── */
.signin-card {
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: 16px;
  padding: 48px 44px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 24px rgba(10, 29, 95, .08);
}

.signin-logo {
  height: 32px;
  display: block;
  margin: 0 auto 28px;
}

.signin-card h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 10px;
}

.signin-card h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
}

.signin-card p {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.65;
  margin-bottom: 28px;
}

/* ── Microsoft sign-in button ───────────────────────────────────────────────── */
.btn-ms {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 13px 24px;
  cursor: pointer;
  transition: background .15s ease;
}

.btn-ms:hover { background: var(--blue); }

/* ── Spinner ────────────────────────────────────────────────────────────────── */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--mist);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  margin-bottom: 16px;
}

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

#loading-screen p {
  font-size: 14px;
  color: var(--muted);
}

/* ── Top bar ────────────────────────────────────────────────────────────────── */
#topbar {
  height: 56px;
  background: var(--ink);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}

.tb-logo {
  height: 22px;
  filter: brightness(0) invert(1);
  display: block;
  flex-shrink: 0;
}

.tb-divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,.2);
  flex-shrink: 0;
}

.tb-title {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,.9);
  flex: 1;
}

.tb-meta {
  font-size: 13px;
  color: rgba(255,255,255,.5);
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.8);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  text-decoration: none;
  transition: background .15s ease;
  flex-shrink: 0;
  white-space: nowrap;
}

.btn-back:hover { background: rgba(255,255,255,.2); color: #fff; }

.btn-signout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.1);
  color: rgba(255,255,255,.8);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  cursor: pointer;
  transition: background .15s ease;
  flex-shrink: 0;
}

.btn-signout:hover { background: rgba(255,255,255,.2); color: #fff; }

/* ── Admin body ─────────────────────────────────────────────────────────────── */
#admin-body {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* ── PAT banner ─────────────────────────────────────────────────────────────── */
.pat-banner {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-left: 4px solid var(--warn);
  border-radius: 8px;
  margin-bottom: 24px;
}

.pat-banner-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 20px;
}

.pat-banner-inner > svg {
  color: var(--warn);
  flex-shrink: 0;
}

.pat-banner-inner > span {
  font-size: 14px;
  font-weight: 500;
  color: #5f4400;
}

.pat-input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pat-input-row input {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid #e0c060;
  border-radius: 5px;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 13px;
  background: #fffdf0;
  color: var(--text);
  outline: none;
}

.pat-input-row input:focus { border-color: var(--warn); box-shadow: 0 0 0 3px rgba(247,168,0,.15); }

.pat-input-row button {
  padding: 9px 16px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}

.pat-input-row button:hover { background: var(--blue); }

.pat-hint {
  font-size: 12px;
  color: #7a6030;
  line-height: 1.6;
}

.pat-hint strong { font-weight: 600; }
.pat-hint em { font-style: italic; }

/* ── Panel ──────────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--mist);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 3px solid var(--teal);
  gap: 12px;
}

.panel-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

.btn-add-tenant {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  transition: background .15s;
  flex-shrink: 0;
}

.btn-add-tenant:hover { background: var(--ink); }

/* ── Add form ───────────────────────────────────────────────────────────────── */
.add-form {
  border-bottom: 1px solid var(--mist);
  background: var(--cloud);
}

.add-form-inner {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 600px;
}

.add-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.add-input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.add-input-row input {
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid var(--mist);
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.add-input-row input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(9,114,206,.12);
}

.add-input-row button,
#btn-lookup {
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}

.add-input-row button:hover,
#btn-lookup:hover { background: var(--blue); }

.add-input-row button:disabled,
#btn-lookup:disabled { opacity: .6; cursor: not-allowed; }

/* ── Lookup result ──────────────────────────────────────────────────────────── */
.lookup-result {
  background: #e8f4ec;
  border: 1px solid #a3d7ae;
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lookup-org {
  font-size: 15px;
  font-weight: 700;
  color: #1a4a24;
}

.lookup-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 13px;
  color: #2d6b38;
}

.lookup-tid {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 12px;
  color: #3b7a47;
}

.lookup-expiry-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.expiry-date-input {
  background: #fff;
  border: 1px solid #a3d7ae;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  width: 180px;
  transition: border-color .15s;
}
.expiry-date-input:focus { border-color: #2e7d32; box-shadow: 0 0 0 3px rgba(46,125,50,.1); }

.expiry-optional { font-size: 11px; font-weight: 400; color: #3b7a47; }

/* Expiry table cell */
.td-expiry { white-space: nowrap; }
.expiry-never { font-size: 12px; color: var(--muted); }
.expiry-date  { font-size: 12px; color: var(--text); }

.btn-edit-expiry {
  margin-left: 6px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--mist);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  vertical-align: middle;
}
.btn-edit-expiry:hover { background: var(--cloud); color: var(--text); }

.expiry-inline-input {
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--mist);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  vertical-align: middle;
}
.expiry-inline-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(0,188,188,.15); }

.btn-expiry-save, .btn-expiry-cancel {
  margin-left: 5px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  vertical-align: middle;
}
.btn-expiry-save   { background: var(--teal); color: #fff; }
.btn-expiry-save:hover { background: #00a0a0; }
.btn-expiry-save:disabled { opacity: .6; cursor: default; }
.btn-expiry-cancel { background: var(--cloud); color: var(--text); }
.btn-expiry-cancel:hover { background: var(--mist); }

.expiry-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  margin-right: 6px;
  vertical-align: middle;
}
.expiry-badge.soon    { background: #fff3cd; color: #7a5800; }
.expiry-badge.expired { background: #fde8e8; color: var(--danger); }

.btn-confirm-add {
  align-self: flex-start;
  margin-top: 4px;
  padding: 9px 18px;
  background: #2e7d32;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

.btn-confirm-add:hover { background: #1b5e20; }
.btn-confirm-add:disabled { opacity: .6; cursor: not-allowed; }

/* ── Lookup error ───────────────────────────────────────────────────────────── */
.lookup-error {
  font-size: 13px;
  color: var(--danger);
  background: #fdf1f1;
  border: 1px solid #f5c2c2;
  border-radius: 6px;
  padding: 10px 14px;
}

/* ── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

#tenant-table thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--cloud);
  border-bottom: 1px solid var(--mist);
  white-space: nowrap;
}

#tenant-table tbody tr {
  border-bottom: 1px solid var(--mist);
  transition: background .1s;
}

#tenant-table tbody tr:last-child { border-bottom: none; }

#tenant-table tbody tr:hover { background: var(--snow); }

#tenant-table tbody td {
  padding: 14px 16px;
  color: var(--text);
  vertical-align: middle;
}

.td-tid.mono,
.mono {
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 12px;
  color: var(--muted);
}

.td-consent,
.td-remove {
  white-space: nowrap;
}

.empty-row {
  padding: 40px 16px !important;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ── Resolving placeholder ──────────────────────────────────────────────────── */
.resolving {
  color: var(--silver);
  font-style: italic;
  font-size: 13px;
}

/* ── Table action buttons ───────────────────────────────────────────────────── */
.btn-copy-consent {
  padding: 5px 12px;
  background: var(--cloud);
  color: var(--ink);
  border: 1px solid var(--mist);
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}

.btn-copy-consent:hover {
  background: #ddeeff;
  border-color: var(--blue);
  color: var(--blue);
}

.btn-email-consent {
  padding: 5px 12px;
  background: var(--blue);
  color: #fff;
  border: 1px solid var(--blue);
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  margin-left: 6px;
}

.btn-email-consent:hover { background: var(--ink); border-color: var(--ink); }

/* ── Email slide panel ───────────────────────────────────────────────────────── */
#email-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,29,95,.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 200;
  animation: ep-fade .2s ease;
}

@keyframes ep-fade  { from { opacity: 0; } to { opacity: 1; } }
@keyframes ep-slide { from { transform: translateX(100%); } to { transform: translateX(0); } }

#email-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 500px;
  max-width: 96vw;
  background: var(--surface);
  box-shadow: -8px 0 48px rgba(0,0,0,.18);
  z-index: 201;
  display: flex;
  flex-direction: column;
  animation: ep-slide .25s cubic-bezier(.4,0,.2,1);
}

.epanel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  background: var(--ink);
  border-bottom: 3px solid var(--teal);
  flex-shrink: 0;
}

.epanel-title { font-size: 16px; font-weight: 700; color: #fff; }

.epanel-close {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: rgba(255,255,255,.1);
  border: none; border-radius: 6px;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  transition: background .15s;
}
.epanel-close:hover { background: rgba(255,255,255,.22); color: #fff; }

.epanel-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.epanel-body::-webkit-scrollbar       { width: 5px; }
.epanel-body::-webkit-scrollbar-track { background: transparent; }
.epanel-body::-webkit-scrollbar-thumb { background: var(--mist); border-radius: 3px; }

.epanel-org-banner {
  background: var(--cloud);
  border: 1px solid var(--mist);
  border-left: 4px solid var(--blue);
  border-radius: 0 8px 8px 0;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.epanel-org-name { font-size: 15px; font-weight: 700; color: var(--ink); }
.epanel-org-tid  { font-size: 11px; font-family: 'JetBrains Mono', monospace; color: var(--muted); }

.epanel-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.epanel-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.epanel-required { color: var(--danger); margin-left: 2px; }
.epanel-optional { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--silver); }

.epanel-input, .epanel-textarea {
  background: var(--snow);
  border: 1px solid var(--mist);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.epanel-input:focus, .epanel-textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(9,114,206,.1);
}
.epanel-textarea { resize: vertical; min-height: 72px; }
select.epanel-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235a6278' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; cursor: pointer; }

.epanel-from-display {
  background: var(--cloud);
  border: 1px solid var(--mist);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
}

.epanel-hint {
  font-size: 11px;
  color: var(--silver);
  line-height: 1.5;
}

.epanel-what-info {
  background: #f0f7ff;
  border: 1px solid #cce0f7;
  border-radius: 8px;
  padding: 14px 16px;
}

.epanel-what-info p {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--blue);
  margin-bottom: 8px;
}

.epanel-what-info ul {
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.epanel-what-info li { font-size: 13px; color: var(--muted); line-height: 1.6; }

.epanel-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--mist);
  background: var(--snow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

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

.epanel-error {
  font-size: 13px;
  color: var(--danger);
  background: #fdf1f1;
  border: 1px solid #f5c2c2;
  border-radius: 6px;
  padding: 10px 14px;
  line-height: 1.5;
}

.epanel-btn-cancel {
  padding: 10px 18px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--mist);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.epanel-btn-cancel:hover { background: var(--cloud); color: var(--text); }

.epanel-btn-send {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.epanel-btn-send:hover { background: var(--ink); }
.epanel-btn-send:disabled { opacity: .6; cursor: not-allowed; }

.btn-remove {
  padding: 5px 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid #f5c2c2;
  border-radius: 5px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}

.btn-remove:hover {
  background: #fdf1f1;
  border-color: var(--danger);
}

/* ── Toast notification ──────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: #fff;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  padding: 14px 18px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  box-shadow: 0 8px 32px rgba(0,0,0,.22);
  z-index: 9999;
  max-width: 360px;
  animation: toast-in .2s ease;
}

.toast.error { border-left-color: var(--danger); }

@keyframes toast-in  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; transform: translateY(0);   } to { opacity: 0; transform: translateY(6px); } }

.toast.hiding { animation: toast-out .2s ease forwards; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #topbar { padding: 0 16px; }

  .signin-card { padding: 36px 24px; }

  #admin-body { padding: 20px 16px 60px; }

  .panel-header { padding: 16px; }

  .add-form-inner { padding: 16px; }

  #tenant-table thead th,
  #tenant-table tbody td { padding: 10px 12px; }
}
