/* ================================================================
   DATABASE SCHEMA EXPLORER — "Architectural Ether" Design System
   Matches: code.html reference design
   ================================================================ */

/* ── OVERLAY ─────────────────────────────────────────────────── */
.schema-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(25, 28, 30, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.schema-modal.active {
  display: flex;
  animation: schemaFadeIn 0.2s ease;
}

@keyframes schemaFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── CONTAINER ───────────────────────────────────────────────── */
.schema-modal-container {
  background: #ffffff;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  /* ether-shadow */
  box-shadow: 0px 12px 32px rgba(25, 28, 30, 0.06), 0 4px 16px rgba(25, 28, 30, 0.08);
  /* ghost border */
  border: 1px solid rgba(255, 255, 255, 0.4);
  animation: schemaSlideUp 0.26s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes schemaSlideUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── HEADER — glassmorphism ──────────────────────────────────── */
.schema-modal-header {
  /* glass-panel */
  background: rgba(248, 249, 252, 0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(228, 190, 185, 0.15);
}

.schema-modal-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Red accent bar */
.schema-header-accent {
  width: 6px;
  height: 24px;
  background: #b7131a;
  border-radius: 9999px;
  flex-shrink: 0;
}

.schema-header-text {
  font-size: 18px;
  font-weight: 700;
  color: #191c1e;
  letter-spacing: -0.01em;
}

.schema-modal-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.schema-refresh-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #5b403d;
  transition: background 0.15s;
}

.schema-refresh-btn:hover {
  background: #f2f3f6;
}

.schema-refresh-btn .material-symbols-outlined {
  font-size: 18px;
}

.schema-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #b7131a;
  transition: background 0.15s;
}

.schema-close-btn:hover {
  background: rgba(186, 26, 26, 0.08);
}

.schema-close-btn .material-symbols-outlined {
  font-size: 20px;
  font-variation-settings: 'wght' 600;
}

/* ── BODY ────────────────────────────────────────────────────── */
.schema-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: #e7e8eb transparent;
}

.schema-modal-body::-webkit-scrollbar { width: 4px; }
.schema-modal-body::-webkit-scrollbar-thumb { background: #e7e8eb; border-radius: 4px; }

/* ── TABLE LIST ──────────────────────────────────────────────── */
.schema-table-list {
  display: grid;
  gap: 6px;
  padding: 12px;
}

/* Individual table item */
.schema-table-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  gap: 12px;
}

.schema-table-item:hover {
  background: #f2f3f6;
  border-color: rgba(228, 190, 185, 0.25);
}

.schema-table-item:hover .schema-table-icon {
  background: #db322f;
  color: #ffffff;
}

.schema-table-item:hover .schema-table-chevron {
  color: #b7131a;
}

.schema-table-item--selected {
  background: #f2f3f6;
  border-color: rgba(228, 190, 185, 0.35);
}

.schema-table-item--selected .schema-table-icon {
  background: #db322f;
  color: #ffffff;
}

.schema-table-item--selected .schema-table-chevron {
  color: #b7131a;
}

/* Left section */
.schema-table-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  flex: 1;
}

/* Table icon */
.schema-table-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #e7e8eb;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #5b403d;
  transition: background 0.15s, color 0.15s;
}

.schema-table-icon .material-symbols-outlined {
  font-size: 20px;
}

/* Table name & meta */
.schema-table-info {
  min-width: 0;
}

.schema-table-name {
  font-size: 13px;
  font-weight: 600;
  color: #191c1e;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schema-table-updated {
  font-size: 11px;
  color: rgba(91, 64, 61, 0.6);
  margin-top: 2px;
}

/* Right section */
.schema-table-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Column badge — secondary-fixed purple */
.schema-col-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 9999px;
  background: #e0e0ff;
  color: #000767;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Chevron */
.schema-table-chevron {
  font-size: 20px;
  color: rgba(91, 64, 61, 0.4);
  transition: color 0.15s;
}

/* ── FOOTER ──────────────────────────────────────────────────── */
.schema-modal-footer {
  padding: 16px 24px;
  background: rgba(242, 243, 246, 0.4);
  border-top: 1px solid rgba(228, 190, 185, 0.12);
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.schema-cancel-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #5b403d;
  transition: background 0.15s;
}

.schema-cancel-btn:hover {
  background: #e7e8eb;
}

.schema-select-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: #191c1e;
  color: #ffffff;
  transition: opacity 0.15s;
}

.schema-select-btn:hover {
  opacity: 0.85;
}

.schema-select-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Force container to be tall when detail is open */
.schema-modal-container.schema-detail-open {
  min-height: 78vh;
}

/* ── DETAIL OVERLAY ──────────────────────────────────────────── */
.schema-detail-overlay {
  position: absolute;
  inset: 0;
  background: #ffffff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  animation: detailSlideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes detailSlideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* Detail header */
.schema-detail-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(228, 190, 185, 0.12);
}

.schema-detail-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.schema-detail-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: #edeef1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.schema-detail-icon .material-symbols-outlined {
  font-size: 28px;
  color: #b7131a;
  font-variation-settings: 'FILL' 1;
}

.schema-detail-title {
  font-size: 18px;
  font-weight: 700;
  color: #191c1e;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.schema-detail-subtitle {
  font-size: 10px;
  font-weight: 700;
  color: rgba(91, 64, 61, 0.6);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: 3px;
}

.schema-detail-close {
  width: 38px;
  height: 38px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #b7131a;
  flex-shrink: 0;
  transition: background 0.15s;
}

.schema-detail-close:hover {
  background: rgba(186, 26, 26, 0.06);
}

.schema-detail-close .material-symbols-outlined {
  font-size: 22px;
  font-variation-settings: 'wght' 600;
}

/* Sub-info strip */
.schema-detail-subinfo {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: #f2f3f6;
  padding: 14px 24px;
  flex-shrink: 0;
}

.schema-detail-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.schema-detail-stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(91, 64, 61, 0.5);
}

.schema-detail-stat-value {
  font-size: 13px;
  font-weight: 600;
  color: #191c1e;
}

.schema-detail-stat-value.is-primary {
  color: #b7131a;
  font-weight: 700;
}

/* Table area */
.schema-detail-table-wrap {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #e7e8eb transparent;
}

.schema-detail-table-wrap::-webkit-scrollbar { width: 4px; }
.schema-detail-table-wrap::-webkit-scrollbar-thumb { background: #e7e8eb; border-radius: 4px; }

.schema-detail-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.schema-detail-table thead {
  position: sticky;
  top: 0;
  background: #ffffff;
  z-index: 2;
}

.schema-detail-table th {
  padding: 11px 24px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5b403d;
  border-bottom: 1px solid rgba(228, 190, 185, 0.12);
}

.schema-detail-table td {
  padding: 12px 24px;
  border-bottom: 1px solid rgba(228, 190, 185, 0.06);
}

.schema-detail-table tbody tr {
  transition: background 0.1s;
}

.schema-detail-table tbody tr:hover {
  background: rgba(242, 243, 246, 0.5);
}

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

/* Column name cell */
.schema-col-name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.schema-col-name-cell .material-symbols-outlined {
  font-size: 16px;
  color: #b7131a;
}

.schema-col-name-text {
  font-size: 13px;
  font-weight: 700;
  color: #191c1e;
}

/* Data type badge */
.schema-dtype-badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* TEXT / VARCHAR / CHAR → purple */
.schema-dtype-badge.dtype-text {
  background: #ede9fe;
  color: #5b21b6;
}
/* INT / BIGINT / SMALLINT → blue */
.schema-dtype-badge.dtype-int {
  background: #dbeafe;
  color: #1d4ed8;
}
/* NUMERIC / FLOAT / DECIMAL → green */
.schema-dtype-badge.dtype-numeric {
  background: #dcfce7;
  color: #15803d;
}
/* TIMESTAMP / DATE / TIME → orange */
.schema-dtype-badge.dtype-datetime {
  background: #ffedd5;
  color: #c2410c;
}
/* BOOLEAN → amber */
.schema-dtype-badge.dtype-bool {
  background: #fef9c3;
  color: #854d0e;
}
/* UUID → pink */
.schema-dtype-badge.dtype-uuid {
  background: #fce7f3;
  color: #9d174d;
}
/* JSON / JSONB → teal */
.schema-dtype-badge.dtype-json {
  background: #ccfbf1;
  color: #0f766e;
}
/* Primary key override → secondary-fixed purple */
.schema-dtype-badge.is-pk {
  background: #e0e0ff;
  color: #000767;
}
/* fallback */
.schema-dtype-badge.dtype-default {
  background: #f1f5f9;
  color: #475569;
}

/* Sample value cell */
.schema-sample-value {
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: #5b403d;
}

/* ── DETAIL FOOTER ───────────────────────────────────────────── */
.schema-detail-footer {
  padding: 16px 24px;
  background: #ffffff;
  border-top: 1px solid rgba(228, 190, 185, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.schema-detail-footer-info {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(91, 64, 61, 0.55);
  font-size: 11px;
  font-weight: 500;
}

.schema-detail-footer-info .material-symbols-outlined {
  font-size: 14px;
}

.schema-detail-footer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.schema-copy-ddl-btn {
  padding: 8px 20px;
  border-radius: 8px;
  background: linear-gradient(135deg, #b7131a 0%, #db322f 100%);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(183, 19, 26, 0.2);
  transition: opacity 0.15s, box-shadow 0.15s;
  letter-spacing: -0.01em;
}

.schema-copy-ddl-btn:hover {
  opacity: 0.9;
  box-shadow: 0 4px 14px rgba(183, 19, 26, 0.28);
}

/* ── LOADING & ERROR ─────────────────────────────────────────── */
.schema-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  gap: 14px;
  color: #5b403d;
  font-size: 13px;
}

.schema-loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #f2f3f6;
  border-top-color: #b7131a;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.schema-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  gap: 10px;
  text-align: center;
}

.schema-error-icon { font-size: 36px; color: #e4beb9; }

.schema-error h3 {
  font-size: 15px;
  font-weight: 700;
  color: #191c1e;
  margin: 0;
}

.schema-error p {
  font-size: 13px;
  color: #5b403d;
  margin: 0;
}

.schema-retry-btn {
  margin-top: 6px;
  padding: 8px 20px;
  border-radius: 8px;
  background: #191c1e;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}

.schema-retry-btn:hover { opacity: 0.85; }

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  .schema-modal { padding: 12px; }
  .schema-modal-container { border-radius: 10px; max-height: 92vh; }
  .schema-detail-body { flex-direction: column; }
  .schema-sidebar { width: 100%; }
}
