/* ═══════════════════════════════════════════════════════════════════════════
   panels.css  –  Accounts Slide-over Panel (Outlook-style)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Panel shell ───────────────────────────────────────────────────────────── */

.panel-left,
.panel-right {
  position: fixed;
  top: 0;
  width: 380px;
  height: 100vh;
  background: var(--surface, #fff);
  color: var(--text, #1b1b1f);
  box-shadow: -4px 0 24px rgba(0,0,0,.12);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform .2s ease;
}
.panel-left  { left: 0;  border-right: 1px solid var(--border, #e5e7eb); }
.panel-right { right: 0; border-left:  1px solid var(--border, #e5e7eb); }

/* ── Header & toolbar ──────────────────────────────────────────────────────── */

.panel-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #fff);
}
.panel-header h3   { font-size: .95rem; font-weight: 600; margin: 0; }
.panel-header .spacer { flex: 1; }

.panel-toolbar {
  display: flex;
  gap: .5rem;
  padding: .5rem 1rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  align-items: center;
  background: var(--surface, #fff);
}
.panel-toolbar input[type="search"] {
  flex: 1;
  min-width: 0;
  background: var(--surface, #fff);
  color: var(--text, #1b1b1f);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  padding: .45rem .6rem;
  outline: none;
  font-size: .875rem;
  height: 32px;
}
.panel-toolbar input[type="search"]:focus {
  border-color: var(--brand, #0078d4);
  box-shadow: 0 0 0 2px rgba(0,120,212,.15);
}

.panel-body.scroll {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
}
#accounts-list { padding: 0; }

/* ── Summary bar ───────────────────────────────────────────────────────────── */

.ap-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .45rem .75rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  background: var(--surface-raised, #fafafa);
  gap: .5rem;
  flex-wrap: wrap;
}
.ap-summary-left,
.ap-summary-right {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.ap-stat {
  font-size: .78rem;
  color: var(--muted, #6b7280);
  font-weight: 500;
}
.ap-stat-warn { color: #d13438; }
.ap-stat-info { color: #0078d4; }

.ap-sort-select {
  font-size: .78rem;
  padding: 2px 6px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  background: var(--surface, #fff);
  color: var(--text, #1b1b1f);
  cursor: pointer;
  outline: none;
}
.ap-sort-select:focus { border-color: var(--brand, #0078d4); }

.ap-btn-link {
  font-size: .75rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--brand, #0078d4);
}
.ap-btn-link:hover { text-decoration: underline; }
.ap-btn-link-danger { color: #d13438; }
.ap-btn-link-danger:hover { background: rgba(209,52,56,.08); }

/* ── Tag filter bar ────────────────────────────────────────────────────────── */

.ap-tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: .4rem .75rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.ap-tag-pill {
  font-size: .72rem;
  padding: 2px 8px;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 12px;
  background: var(--surface, #fff);
  color: var(--muted, #6b7280);
  cursor: pointer;
  transition: all .12s ease;
  line-height: 1.4;
}
.ap-tag-pill:hover { border-color: var(--tc, var(--brand, #0078d4)); color: var(--tc, var(--brand)); }
.ap-tag-pill.active {
  background: var(--tc, var(--brand, #0078d4));
  color: #fff;
  border-color: var(--tc, var(--brand, #0078d4));
}

/* ── Account cards ─────────────────────────────────────────────────────────── */

.ap-card {
  display: flex;
  align-items: flex-start;
  gap: .65rem;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border, #e5e7eb);
  cursor: pointer;
  transition: background .1s ease;
  position: relative;
}
.ap-card:hover { background: var(--hover, #f3f4f6); }
.ap-card:focus-visible { outline: 2px solid var(--brand, #0078d4); outline-offset: -2px; }

.ap-card-active {
  background: var(--brand-bg, #eff6ff);
  border-left: 3px solid var(--brand, #0078d4);
  padding-left: calc(.75rem - 3px);
}
.ap-card-active:hover { background: var(--brand-bg, #eff6ff); }

.ap-card-expired { opacity: .75; }

/* Avatar */
.ap-card-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  position: relative;
  letter-spacing: .02em;
}

/* Status dot (bottom-right of avatar) */
.ap-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--surface, #fff);
}
.ap-dot-active        { background: #107c10; }
.ap-dot-token_stale   { background: #ff8c00; }
.ap-dot-needs_reauth  { background: #d13438; }

/* Body */
.ap-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ap-card-row1 {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ap-card-name {
  font-weight: 600;
  font-size: .875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.ap-card-email {
  font-size: .78rem;
  color: var(--muted, #6b7280);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Status / active pills */
.ap-pill-active {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--brand, #0078d4);
  color: #fff;
  line-height: 1.5;
}
.ap-pill-status {
  font-size: .65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  line-height: 1.5;
}
.ap-pill-active-status { background: #dff6dd; color: #107c10; }
.ap-pill-token_stale   { background: #fff4ce; color: #a16207; }
.ap-pill-needs_reauth  { background: #fde7e9; color: #d13438; }

/* Tags */
.ap-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 1px;
}
.ap-minitag {
  font-size: .65rem;
  padding: 0 5px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--tc, #605e5c) 12%, transparent);
  color: var(--tc, #605e5c);
  font-weight: 500;
  line-height: 1.6;
}

/* Meta line */
.ap-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: .7rem;
  color: var(--muted, #9ca3af);
  margin-top: 1px;
}
.ap-sep { opacity: .5; }
.ap-meta-warn { color: #d13438; }
.ap-meta-info { color: #0078d4; font-style: italic; }

/* Feature badges */
.ap-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.ap-feat {
  font-size: .65rem;
  padding: 0 5px;
  border-radius: 3px;
  background: #f3f4f6;
  color: #6b7280;
  line-height: 1.6;
}
.ap-feat-ok   { color: #107c10; background: #dff6dd; }
.ap-feat-warn { color: #a16207; background: #fff4ce; }

/* Action buttons */
.ap-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-self: center;
}
.ap-icon-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted, #6b7280);
  transition: background .1s, color .1s;
}
.ap-icon-btn:hover { background: var(--hover, #f3f4f6); color: var(--text, #1b1b1f); }
.ap-icon-btn-danger:hover { background: #fde7e9; color: #d13438; }

/* Mirror start button — more prominent than icon-only buttons */
.ap-mirror-start-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--brand, #0078d4);
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--brand, #0078d4);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.ap-mirror-start-btn:hover {
  background: var(--brand, #0078d4);
  color: #fff;
}

/* Mirror button loading state */
.ap-mirror-loading {
  pointer-events: none;
  opacity: 0.7;
  position: relative;
}
.ap-mirror-loading .ap-mirror-label {
  visibility: hidden;
}
.ap-mirror-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ── Empty state ───────────────────────────────────────────────────────────── */

.ap-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  gap: .75rem;
  text-align: center;
}
.ap-empty-icon { opacity: .5; }
.ap-empty-title { font-size: 1rem; font-weight: 600; color: var(--text, #1b1b1f); }
.ap-empty-hint  { font-size: .85rem; color: var(--muted, #6b7280); }

/* ── Confirm / Tags dialog ─────────────────────────────────────────────────── */

.ap-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ap-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.35);
}
.ap-dialog {
  position: relative;
  background: var(--surface, #fff);
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  min-width: 320px;
  max-width: 420px;
  padding: 1.25rem;
  color: var(--text, #1b1b1f);
  animation: ap-slide-up .15s ease;
}
.ap-dialog-wide { min-width: 360px; }
@keyframes ap-slide-up { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.ap-dialog-title { font-size: 1rem; font-weight: 600; margin-bottom: .5rem; }
.ap-dialog-sub-title { font-size: .85rem; color: var(--muted, #6b7280); margin-bottom: .75rem; }
.ap-dialog-body { margin-bottom: 1rem; font-size: .875rem; line-height: 1.5; }
.ap-dialog-sub { font-size: .8rem; color: var(--muted, #6b7280); }

.ap-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* Dialog buttons */
.ap-dbtn {
  padding: .4rem .85rem;
  font-size: .85rem;
  border-radius: 4px;
  border: 1px solid var(--border, #e5e7eb);
  cursor: pointer;
  font-weight: 500;
  transition: all .1s;
  background: var(--surface, #fff);
  color: var(--text, #1b1b1f);
}
.ap-dbtn:hover { background: var(--hover, #f3f4f6); }
.ap-dbtn-primary { background: var(--brand, #0078d4); color: #fff; border-color: var(--brand, #0078d4); }
.ap-dbtn-primary:hover { background: #106ebe; }
.ap-dbtn-danger { background: #d13438; color: #fff; border-color: #d13438; }
.ap-dbtn-danger:hover { background: #b72b2f; }
.ap-dbtn-cancel { background: var(--surface, #fff); }
.ap-dbtn-sm { padding: .3rem .6rem; font-size: .8rem; }

/* Tag editor pieces */
.ap-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: .75rem;
  min-height: 28px;
}
.ap-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .78rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--tc, #605e5c) 12%, transparent);
  color: var(--tc, #605e5c);
  font-weight: 500;
}
.ap-chip-x {
  border: none;
  background: none;
  cursor: pointer;
  font-size: .85rem;
  color: inherit;
  opacity: .65;
  padding: 0;
  line-height: 1;
}
.ap-chip-x:hover { opacity: 1; }
.ap-tags-none { font-size: .82rem; color: var(--muted, #9ca3af); font-style: italic; }

.ap-tag-add-row {
  display: flex;
  gap: .35rem;
  margin-bottom: .6rem;
}
.ap-tag-input {
  flex: 1;
  padding: .35rem .5rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  font-size: .85rem;
  outline: none;
  background: var(--surface, #fff);
  color: var(--text, #1b1b1f);
}
.ap-tag-input:focus { border-color: var(--brand, #0078d4); }

.ap-tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ap-tag-sug {
  font-size: .72rem;
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border, #e5e7eb);
  background: var(--surface, #fff);
  color: var(--muted, #6b7280);
  cursor: pointer;
}
.ap-tag-sug:hover {
  border-color: var(--brand, #0078d4);
  color: var(--brand, #0078d4);
}

/* ── Add-account form ──────────────────────────────────────────────────────── */

.ap-add-form {
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
}
.ap-add-tabs {
  display: flex;
  gap: .35rem;
  margin-bottom: .25rem;
}
.ap-add-tab {
  padding: .3rem .65rem;
  font-size: .82rem;
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  background: var(--surface, #fff);
  cursor: pointer;
  color: var(--text, #1b1b1f);
}
.ap-add-tab.active {
  border-color: var(--brand, #0078d4);
  color: var(--brand, #0078d4);
  font-weight: 600;
}

.ap-add-fields { display: flex; flex-direction: column; gap: .5rem; }

.ap-field {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: var(--text, #1b1b1f);
}
.ap-field input,
.ap-field textarea {
  width: 100%;
  background: var(--surface, #fff);
  color: var(--text, #1b1b1f);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 4px;
  padding: .4rem .5rem;
  outline: none;
  font-size: .82rem;
}
.ap-field input:focus,
.ap-field textarea:focus {
  border-color: var(--brand, #0078d4);
  box-shadow: 0 0 0 2px rgba(0,120,212,.12);
}

.ap-add-btns {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: .25rem;
}

.ap-add-error {
  color: #d13438;
  font-size: .82rem;
  margin-top: .25rem;
}

/* ── Toolbar "Add account" button ──────────────────────────────────────────── */

.panel-toolbar .btn.btn-primary {
  background: var(--brand, #0078d4);
  color: #fff;
  border: 1px solid var(--brand, #0078d4);
  border-radius: 4px;
  padding: .4rem .65rem;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .1s;
}
.panel-toolbar .btn.btn-primary:hover { background: #106ebe; }

/* ── Dark theme ────────────────────────────────────────────────────────────── */

body.theme-dark .panel-left,
body.theme-dark .panel-right,
body.theme-dark #accounts-panel {
  background: var(--surface, #1a1a1a) !important;
  color: var(--text, #f3f3f3) !important;
  border-color: var(--border, #2a2a2a) !important;
}
body.theme-dark .panel-header,
body.theme-dark .panel-toolbar {
  background: var(--surface, #1a1a1a) !important;
  border-color: var(--border, #2a2a2a) !important;
}
body.theme-dark .ap-summary {
  background: var(--surface, #1a1a1a) !important;
  border-color: var(--border, #2a2a2a) !important;
}
body.theme-dark .ap-card {
  border-color: var(--border, #2a2a2a) !important;
}
body.theme-dark .ap-card:hover {
  background: var(--hover, #2a2a2a) !important;
}
body.theme-dark .ap-card-active {
  background: rgba(0,120,212,.12) !important;
}
body.theme-dark .ap-dot {
  border-color: var(--surface, #1a1a1a) !important;
}
body.theme-dark .ap-dialog {
  background: var(--surface, #1a1a1a) !important;
  color: var(--text, #f3f3f3) !important;
}
body.theme-dark .ap-feat {
  background: #2a2a2a;
  color: #9ca3af;
}
body.theme-dark .ap-feat-ok {
  background: rgba(16,124,16,.15);
  color: #5bb65b;
}
body.theme-dark .ap-feat-warn {
  background: rgba(255,140,0,.12);
  color: #ffa94d;
}
body.theme-dark .ap-pill-active-status {
  background: rgba(16,124,16,.18);
  color: #5bb65b;
}
body.theme-dark .ap-pill-expiring_soon,
body.theme-dark .ap-pill-token_stale {
  background: rgba(255,140,0,.15);
  color: #ffa94d;
}
body.theme-dark .ap-pill-expired,
body.theme-dark .ap-pill-needs_reauth {
  background: rgba(209,52,56,.15);
  color: #f87171;
}
body.theme-dark .ap-tag-pill {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #9ca3af;
}
body.theme-dark .ap-tag-pill.active {
  background: var(--tc, var(--brand, #0078d4));
  color: #fff;
  border-color: var(--tc, var(--brand, #0078d4));
}
body.theme-dark .ap-tag-bar {
  border-color: var(--border, #2a2a2a) !important;
}
body.theme-dark .ap-icon-btn {
  color: #9ca3af;
}
body.theme-dark .ap-icon-btn:hover {
  background: #2a2a2a;
  color: #f3f3f3;
}
body.theme-dark .ap-icon-btn-danger:hover {
  background: rgba(209,52,56,.15);
  color: #f87171;
}
body.theme-dark .ap-mirror-start-btn {
  border-color: #60a5fa;
  color: #60a5fa;
}
body.theme-dark .ap-mirror-start-btn:hover {
  background: #60a5fa;
  color: #1a1a1a;
}
body.theme-dark .ap-mirror-loading {
  opacity: 0.65;
}
body.theme-dark .ap-add-tab {
  background: var(--surface, #1a1a1a);
  color: var(--text, #f3f3f3);
  border-color: var(--border, #2a2a2a);
}
body.theme-dark .ap-add-tab.active {
  border-color: var(--brand, #0078d4);
  color: var(--brand, #0078d4);
}
body.theme-dark .ap-tag-sug {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #9ca3af;
}
body.theme-dark .ap-tag-sug:hover {
  border-color: var(--brand, #0078d4);
  color: var(--brand, #0078d4);
}
body.theme-dark .ap-dbtn {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #f3f3f3;
}
body.theme-dark .ap-dbtn:hover {
  background: #3a3a3a;
}
body.theme-dark .ap-dbtn-primary {
  background: var(--brand, #0078d4);
  border-color: var(--brand, #0078d4);
  color: #fff;
}
body.theme-dark .ap-dbtn-danger {
  background: #d13438;
  border-color: #d13438;
}
