/* ═══════════════════════════════════════════════════
   modals.css — Profile settings + Admin panel modals
═══════════════════════════════════════════════════ */

/* ── Overlay ─────────────────────────────────────── */
.modal-overlay {
  /* Hidden by default — opened by JS via .is-open class.
     Using class rather than [hidden] attribute avoids the UA-stylesheet
     specificity trap where display:flex from author CSS beats display:none
     from the UA [hidden] rule (which lacks !important in Chrome). */
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.is-open {
  display: flex;
  animation: modal-overlay-in 180ms ease both;
}

@keyframes modal-overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Dialog ──────────────────────────────────────── */
.modal {
  position: relative;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 32px 96px rgba(0,0,0,0.65), 0 0 0 1px rgba(232,0,13,0.06);
  animation: modal-in 280ms cubic-bezier(0.34, 1.45, 0.64, 1) both;
}

.modal--wide {
  max-width: 720px;
}

/* ── Fullscreen variant (admin panel) ────────────── */
.modal-overlay--fullscreen {
  padding: 0;
}

.modal--fullscreen {
  width: 100%;
  height: 100dvh;
  max-width: 100%;
  max-height: 100dvh;
  border-radius: 0;
  animation: none; /* skip the scale-in bounce — instant open feels better at full screen */
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Header ──────────────────────────────────────── */
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}

.modal__title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-primary);
  margin: 0;
}

.modal__title::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 14px;
  background: var(--red);
  border-radius: 2px;
  margin-right: 10px;
  vertical-align: middle;
}

.modal__close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
  line-height: 1;
}

.modal__close:hover {
  color: var(--text-primary);
  border-color: var(--border-mid);
  background: var(--bg-surface-2);
}

/* ── Body ────────────────────────────────────────── */
.modal__body {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Section ─────────────────────────────────────── */
.modal__section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal__section-title {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin: 0;
}

/* ── Fields ──────────────────────────────────────── */
.modal__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal__label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.modal__input {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-input);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: border-color var(--t-base), box-shadow var(--t-base);
  box-sizing: border-box;
}

.modal__input:focus {
  border-color: rgba(232, 0, 13, 0.55);
  box-shadow: 0 0 0 3px rgba(232, 0, 13, 0.1);
}

.modal__select {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-input);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239A9AA8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Error message ───────────────────────────────── */
.modal__error {
  font-size: 13px;
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
}

.modal__success {
  font-size: 13px;
  color: var(--sector-green);
  background: rgba(57, 255, 20, 0.08);
  border: 1px solid rgba(57, 255, 20, 0.2);
  border-radius: var(--radius-sm);
  padding: 9px 13px;
}

/* ── Buttons ─────────────────────────────────────── */
.modal__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: all var(--t-base);
  background: none;
  color: var(--text-secondary);
  align-self: flex-start;
}

.modal__btn:hover:not(:disabled) {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

.modal__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.modal__btn--primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  box-shadow: 0 2px 12px rgba(232, 0, 13, 0.25);
}

.modal__btn--primary:hover:not(:disabled) {
  background: var(--red);
  opacity: 0.9;
  box-shadow: var(--red-glow-sm);
}

.modal__btn--danger {
  border-color: var(--border-accent);
  color: var(--red);
}

.modal__btn--danger:hover:not(:disabled) {
  background: var(--red-dim);
  border-color: var(--red);
}

/* ── Inline form (admin create user) ─────────────── */
.modal__inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.modal__input--inline {
  flex: 1;
  min-width: 120px;
}

.modal__select--inline {
  width: auto;
  flex: 0 0 auto;
}

/* ── Admin user table ────────────────────────────── */
.admin-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.admin-table th {
  padding: 10px 14px;
  text-align: left;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border-subtle);
}

.admin-table td {
  padding: 10px 14px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

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

.admin-table tbody tr:hover td {
  background: var(--session-hover-bg);
}

.admin-table__username {
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--text-primary);
}

/* Role badges */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.role-badge--admin {
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid var(--border-accent);
}

.role-badge--user {
  background: var(--purple-dim);
  color: var(--sector-purple);
  border: 1px solid var(--purple-border);
}

/* Table action buttons */
.admin-table__actions {
  display: flex;
  gap: 6px;
}

.admin-action-btn {
  padding: 4px 10px;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}

.admin-action-btn:hover {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
}

.admin-action-btn--kick:hover {
  border-color: var(--sector-yellow);
  color: var(--sector-yellow);
  background: rgba(255, 215, 0, 0.07);
}

.admin-action-btn--delete:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-dim);
}

/* ── Sidebar user section ────────────────────────── */
.sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  margin: 4px 0;
}

.sidebar__user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--red-dim);
  border: 1px solid var(--border-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0;
}

.sidebar__user-info {
  flex: 1;
  min-width: 0;
}

.sidebar__user-name {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__user-role {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.sidebar__user-role--admin {
  color: var(--red);
}

.sidebar__user-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.sidebar__user-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast);
}

.sidebar__user-btn:hover {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border-color: var(--border-mid);
}

.sidebar__user-btn--admin:hover {
  color: var(--sector-purple);
  border-color: var(--purple-border);
  background: var(--purple-dim);
}

.sidebar__user-btn--logout:hover {
  color: var(--red);
  border-color: var(--border-accent);
  background: var(--red-dim);
}

.sidebar__user-btn.is-hidden {
  display: none;
}

/* ── Divider label ───────────────────────────────── */
.modal__divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

/* ── Plan badges (APEX / FREE) ───────────────────── */
.role-badge--apex {
  background: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(232,0,13,0.1));
  color: #a78bfa;
  border: 1px solid rgba(139,92,246,0.3);
}

.role-badge--free {
  background: var(--bg-surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

/* ── Limit-reached card in the chat stream ───────── */
.limit-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-accent);
  border-left: 3px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 12px 0;
  animation: modal-in 280ms cubic-bezier(0.34, 1.45, 0.64, 1) both;
}

.limit-card__icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.limit-card__body {
  flex: 1;
}

.limit-card__title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--red);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.limit-card__sub {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.limit-card__reset {
  color: #f59e0b;
  font-weight: 500;
}

.limit-card__upgrade-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 8px 16px;
  background: linear-gradient(135deg, #7c3aed, #E8000D);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: opacity var(--t-fast), box-shadow var(--t-fast);
  box-shadow: 0 2px 12px rgba(124, 58, 237, 0.35);
}

.limit-card__upgrade-btn:hover {
  opacity: 0.9;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.5);
}
