/* ============================================================================
   Admin / Settings surfaces — extends styles.css
   ============================================================================ */

.admin-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 40px 48px 80px;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(29,50,66,0.03), transparent 60%),
    var(--bg);
}
.admin-inner {
  max-width: 1120px;
  margin: 0 auto;
  animation: admin-rise 0.45s var(--ease-smooth);
}
@keyframes admin-rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.admin-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 24px; margin-bottom: 32px;
}
.admin-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  letter-spacing: -0.02em;
  color: var(--blue-900);
  margin: 6px 0 8px;
  line-height: 1.05;
}
.admin-sub {
  color: var(--fg-2);
  font-size: 14.5px;
  line-height: 1.55;
  max-width: 640px;
  margin: 0;
}

.admin-inner .eyebrow {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
}
.admin-inner .eyebrow .bar {
  width: 28px; height: 2px;
  background: var(--victory-red);
}

/* ============================================================================ */
/*  Users table                                                                */
/* ============================================================================ */
.users-table-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-premium);
  overflow: hidden;
}
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.users-table thead th {
  text-align: left;
  padding: 14px 18px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-3);
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.users-table tbody td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  color: var(--fg-1);
  vertical-align: middle;
}
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr {
  transition: background 0.12s var(--ease-standard);
}
.users-table tbody tr:hover {
  background: rgba(29, 50, 66, 0.025);
}

.u-cell { display: flex; align-items: center; gap: 12px; }
.u-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-900));
  color: #fff;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: 0.03em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.u-name {
  font-weight: 600;
  color: var(--blue-900);
  display: flex; align-items: center; gap: 8px;
}
.u-email {
  font-size: 12px;
  color: var(--fg-3);
  margin-top: 1px;
}
.u-badge {
  display: inline-flex; align-items: center;
  height: 18px; padding: 0 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--victory-red);
  background: rgba(220, 32, 21, 0.08);
  border: 1px solid rgba(220, 32, 21, 0.2);
}
.u-code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--blue-900);
  background: var(--bg-2);
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid var(--border);
}
.u-role { color: var(--fg-2); font-weight: 500; }
.u-time { color: var(--fg-3); font-size: 12px; white-space: nowrap; }

.key-set {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--green, #16794A);
  font-weight: 600;
  font-size: 12px;
}
.key-set code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-2);
  background: var(--bg-2);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.key-missing {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--fg-3);
  font-size: 12px;
  font-style: italic;
}

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  color: var(--fg-2);
  cursor: pointer;
  transition: all 0.15s var(--ease-standard);
}
.icon-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  color: var(--blue-900);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(29,50,66,0.08);
}
.icon-btn.danger:hover:not(:disabled) {
  border-color: rgba(220, 32, 21, 0.4);
  color: var(--victory-red);
  background: rgba(220, 32, 21, 0.04);
}
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ============================================================================ */
/*  Modal                                                                      */
/* ============================================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(29, 50, 66, 0.42);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: mb-fade 0.2s var(--ease-standard);
}
@keyframes mb-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-card {
  width: 100%;
  max-width: 640px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 40px 80px rgba(29,50,66,0.25), 0 8px 24px rgba(29,50,66,0.12);
  overflow: hidden;
  animation: mc-pop 0.32s var(--ease-smooth);
  border: 1px solid var(--border);
}
@keyframes mc-pop {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: var(--blue-900);
  letter-spacing: -0.01em;
}
.modal-body {
  padding: 22px 24px;
  max-height: 70vh;
  overflow-y: auto;
}
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px 22px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.f-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.f-grid .field { margin: 0; }
.field label .hint {
  color: var(--fg-3);
  font-weight: 400;
  font-size: 11.5px;
  letter-spacing: 0;
  text-transform: none;
  margin-left: 2px;
}

/* ============================================================================ */
/*  Settings cards                                                             */
/* ============================================================================ */
.settings-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px 26px;
  margin-top: 24px;
  box-shadow: var(--shadow-premium);
  position: relative;
}
.settings-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--blue-900), var(--victory-red));
  border-radius: 14px 0 0 14px;
}
.settings-card h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  color: var(--blue-900);
  letter-spacing: -0.005em;
}
.settings-desc {
  color: var(--fg-2);
  font-size: 13.5px;
  line-height: 1.55;
  margin: 0 0 16px;
}

/* ============================================================================ */
/*  Custom Instructions module (right panel)                                    */
/* ============================================================================ */
.ci-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.ci-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--victory-red);
  margin-left: 8px;
  box-shadow: 0 0 0 3px rgba(220, 32, 21, 0.12);
  animation: ci-pulse 2.4s ease-in-out infinite;
}
@keyframes ci-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(220,32,21,0.12); }
  50%      { box-shadow: 0 0 0 5px rgba(220,32,21,0.05); }
}
.ci-edit-btn {
  height: 26px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--blue-900);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.15s var(--ease-standard);
}
.ci-edit-btn:hover {
  border-color: var(--victory-red);
  color: var(--victory-red);
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(220,32,21,0.08);
}
.ci-preview {
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--bg-2);
  cursor: pointer;
  transition: all 0.2s var(--ease-standard);
  min-height: 72px;
  max-height: 180px;
  overflow: hidden;
  position: relative;
}
.ci-preview:hover {
  border-color: var(--victory-red);
  background: #fff;
}
.ci-preview-text {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--fg-1);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-ui);
  mask-image: linear-gradient(180deg, #000 60%, transparent 100%);
  -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent 100%);
  max-height: 150px;
}
.ci-preview-empty {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--fg-3);
  font-style: italic;
}

/* ============================================================================ */
/*  Custom Instructions modal                                                   */
/* ============================================================================ */
.ci-modal-sub {
  margin: 4px 0 0;
  color: var(--fg-2);
  font-size: 12.5px;
  line-height: 1.5;
  font-weight: 400;
  max-width: 440px;
}
.ci-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--fg-1);
  transition: border-color 0.15s var(--ease-standard), box-shadow 0.15s var(--ease-standard);
}
.ci-textarea:focus {
  outline: none;
  border-color: var(--victory-red);
  box-shadow: 0 0 0 3px rgba(220,32,21,0.1);
}
.ci-textarea::placeholder {
  color: var(--fg-3);
  white-space: pre-line;
}
.ci-counter {
  text-align: right;
  font-size: 11px;
  color: var(--fg-3);
  margin-top: 6px;
  letter-spacing: 0.02em;
}
.ci-tips {
  margin-top: 18px;
  padding: 14px 16px;
  background: var(--bg-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.ci-tip-head {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 8px;
}
.ci-tips ul {
  margin: 0;
  padding-left: 18px;
  color: var(--fg-2);
  font-size: 12.5px;
  line-height: 1.6;
}
.ci-tips li + li { margin-top: 3px; }

/* ============================================================================ */
/*  History gallery                                                             */
/* ============================================================================ */
.hist-backdrop {
  position: fixed; inset: 0;
  background: rgba(29, 50, 66, 0.55);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  z-index: 120;
  display: grid; place-items: center;
  padding: 32px;
  animation: mb-fade 0.22s var(--ease-standard);
}
.hist-shell {
  width: 100%;
  max-width: 1280px;
  height: calc(100vh - 64px);
  max-height: 880px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 50px 100px rgba(29,50,66,0.3), 0 10px 30px rgba(29,50,66,0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: hist-pop 0.4s var(--ease-smooth);
  border: 1px solid var(--border);
}
@keyframes hist-pop {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.hist-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--border);
  gap: 24px;
  flex-shrink: 0;
}
.hist-head .eyebrow {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-3);
}
.hist-head .eyebrow .bar { width: 28px; height: 2px; background: var(--victory-red); }

/* "Batch" corner ribbon on history cards that came from a gpt-image-2 batch. */
.hist-card-batch-tag {
  position: absolute;
  top: 10px; left: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(29, 50, 66, 0.92);
  color: #fff;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.18);
}

/* Admin cross-user picker in the history header. Minimal, editorial — a
   sharpened <select> dressed in the firm's chrome. */
.hist-user-picker {
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 32px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%231D3242' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>")
    right 10px center no-repeat;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--knowledgeable-blue);
  cursor: pointer;
  transition: border-color 0.15s var(--ease-standard);
  max-width: 220px;
}
.hist-user-picker:hover { border-color: var(--border-strong); }
.hist-user-picker:focus { outline: 2px solid rgba(29,50,66,0.2); outline-offset: 1px; }
.hist-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  letter-spacing: -0.015em;
  color: var(--blue-900);
  margin: 6px 0 4px;
  line-height: 1.1;
}
.hist-sub {
  color: var(--fg-2);
  font-size: 13px;
  margin: 0;
}

.hist-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 32px;
}
.hist-loading {
  height: 200px;
  display: grid; place-items: center;
}

.hist-empty {
  height: 360px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  color: var(--fg-2);
  gap: 12px;
}
.hist-empty-icon {
  color: var(--fg-3);
  opacity: 0.5;
}
.hist-empty h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--blue-900);
  margin: 4px 0 0;
}
.hist-empty p {
  margin: 0;
  max-width: 380px;
  font-size: 13.5px;
  line-height: 1.55;
}

.hist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.hist-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s var(--ease-smooth);
  display: flex;
  flex-direction: column;
  position: relative;
}
.hist-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(29,50,66,0.12);
  border-color: var(--border-strong);
}
.hist-card-img {
  aspect-ratio: 4 / 3;
  background:
    repeating-conic-gradient(#f3f5f7 0 25%, #fafbfc 0 50%) 0 0 / 16px 16px,
    var(--bg-2);
  position: relative;
  overflow: hidden;
}
.hist-card-img img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.5s var(--ease-smooth);
}
.hist-card:hover .hist-card-img img { transform: scale(1.04); }
.hist-card-tag {
  position: absolute; top: 10px; left: 10px;
  padding: 4px 9px;
  background: rgba(29, 50, 66, 0.92);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 4px;
  backdrop-filter: blur(4px);
}
.hist-card-body {
  padding: 14px 16px 12px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.hist-card-name {
  font-weight: 600;
  color: var(--blue-900);
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-card-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px;
  color: var(--fg-3);
}
.dot-sep { opacity: 0.5; }
.hist-card-actions {
  display: flex; gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.hist-action {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  color: var(--fg-2);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease-standard);
  white-space: nowrap;
}
.hist-action:hover {
  border-color: var(--border-strong);
  color: var(--blue-900);
  background: var(--bg-2);
}
.hist-action.danger { padding: 0 8px; margin-left: auto; }
.hist-action.danger:hover {
  border-color: rgba(220,32,21,0.4);
  color: var(--victory-red);
  background: rgba(220,32,21,0.04);
}

/* ============================================================================ */
/*  History viewer                                                              */
/* ============================================================================ */
.hist-viewer {
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--bg-2);
}
.hist-viewer-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 32px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.hist-back {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 7px;
  color: var(--fg-2);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s var(--ease-standard);
}
.hist-back:hover {
  border-color: var(--border-strong);
  color: var(--blue-900);
  transform: translateX(-2px);
}
.hist-viewer-title { flex: 1; min-width: 0; }
.hist-viewer-title .name {
  font-weight: 600;
  color: var(--blue-900);
  font-size: 14px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.hist-viewer-title .sub {
  font-size: 11.5px;
  color: var(--fg-3);
  margin-top: 2px;
}
.hist-viewer-actions { display: flex; gap: 6px; flex-shrink: 0; }
.hist-viewer-stage {
  flex: 1;
  min-height: 0;
  padding: 24px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.hist-viewer-hint {
  padding: 12px 32px;
  text-align: center;
  font-size: 11.5px;
  color: var(--fg-3);
  background: #fff;
  border-top: 1px solid var(--border);
  letter-spacing: 0.01em;
  flex-shrink: 0;
}

/* ============================================================================ */
/*  Compare slider                                                              */
/* ============================================================================ */
.cmp-wrap {
  position: relative;
  width: 100%;
  max-width: 1100px;
  max-height: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 20px 50px rgba(29,50,66,0.2);
  cursor: ew-resize;
  user-select: none;
  -webkit-user-select: none;
}
.cmp-img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
.cmp-after { z-index: 1; }
.cmp-before-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 2;
  pointer-events: none;
}
.cmp-before {
  position: absolute;
  inset: 0;
  height: 100%;
  object-fit: contain;
  object-position: left center;
}
.cmp-divider {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: #fff;
  transform: translateX(-1px);
  z-index: 4;
  box-shadow: 0 0 0 1px rgba(29,50,66,0.2), 0 0 18px rgba(0,0,0,0.35);
  pointer-events: none;
}
.cmp-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 48px; height: 48px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff;
  color: var(--blue-900);
  display: flex; align-items: center; justify-content: center;
  gap: 1px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25), 0 0 0 1px rgba(29,50,66,0.1);
  cursor: ew-resize;
  pointer-events: auto;
  transition: transform 0.15s var(--ease-standard), box-shadow 0.15s var(--ease-standard);
  animation: handle-breathe 2.8s ease-in-out infinite;
}
@keyframes handle-breathe {
  0%, 100% { box-shadow: 0 4px 16px rgba(0,0,0,0.25), 0 0 0 0 rgba(220,32,21,0.25); }
  50%      { box-shadow: 0 4px 16px rgba(0,0,0,0.25), 0 0 0 10px rgba(220,32,21,0); }
}
.cmp-wrap:hover .cmp-handle,
.cmp-handle:focus-visible {
  transform: translate(-50%, -50%) scale(1.08);
  outline: none;
}
.cmp-label {
  position: absolute;
  top: 16px;
  padding: 5px 11px;
  background: rgba(29, 50, 66, 0.88);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-radius: 4px;
  z-index: 3;
  display: inline-flex; align-items: center; gap: 6px;
  transition: opacity 0.2s var(--ease-standard);
  pointer-events: none;
}
.cmp-label-l { left: 16px; }
.cmp-label-r { right: 16px; background: rgba(220,32,21,0.92); }
.dot-red { width: 6px; height: 6px; border-radius: 50%; background: var(--victory-red); box-shadow: 0 0 8px rgba(220,32,21,0.6); }
.dot-blue { width: 6px; height: 6px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px rgba(255,255,255,0.8); }
