/* ── Trellis Framework Styles ─────────────────────────────────────────────── */

:root {
  --trellis-primary: #667eea;
  --trellis-accent: #764ba2;
  --trellis-bg: #0f0f1a;
  --trellis-surface: #1a1a2e;
  --trellis-text: #e8e8e8;
  --trellis-text-muted: #8888a0;
  --trellis-error: #ff4757;
  --trellis-success: #2ed573;
  --trellis-border: rgba(255, 255, 255, 0.08);
  --trellis-radius: 16px;
  --trellis-radius-sm: 10px;
  --trellis-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  --trellis-glow: 0 0 30px rgba(102, 126, 234, 0.15);
  /* Adaptive overlays — overridden by themeCSS() for light themes */
  --trellis-overlay-subtle: rgba(255, 255, 255, 0.02);
  --trellis-overlay-hover: rgba(255, 255, 255, 0.05);
  --trellis-overlay-input: rgba(255, 255, 255, 0.04);
  --trellis-overlay-border-hover: rgba(255, 255, 255, 0.15);
  --trellis-card-bg: rgba(26, 26, 46, 0.85);
  --trellis-placeholder: rgba(255, 255, 255, 0.2);
  --trellis-footer-color: rgba(255, 255, 255, 0.15);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.trellis-page {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--trellis-bg);
  color: var(--trellis-text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

body.trellis-admin-page {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--trellis-bg);
  color: var(--trellis-text);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

/* ── Animated background ─────────────────────────────────────────────────── */

.trellis-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.trellis-bg::before,
.trellis-bg::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.3;
  animation: trellis-float 20s ease-in-out infinite;
}

.trellis-bg::before {
  width: 600px;
  height: 600px;
  background: var(--trellis-primary);
  top: -200px;
  right: -100px;
}

.trellis-bg::after {
  width: 500px;
  height: 500px;
  background: var(--trellis-accent);
  bottom: -150px;
  left: -100px;
  animation-delay: -10s;
  animation-direction: reverse;
}

@keyframes trellis-float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -40px) scale(1.05); }
  50% { transform: translate(-20px, 20px) scale(0.95); }
  75% { transform: translate(40px, 30px) scale(1.02); }
}

/* ── Auth card ───────────────────────────────────────────────────────────── */

.trellis-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  margin: 24px;
  padding: 40px 36px;
  background: var(--trellis-card-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--trellis-border);
  border-radius: var(--trellis-radius);
  box-shadow: var(--trellis-shadow), var(--trellis-glow);
}

.trellis-logo {
  text-align: center;
  margin-bottom: 8px;
  font-size: 48px;
  line-height: 1;
}

.trellis-title {
  text-align: center;
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--trellis-primary), var(--trellis-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.trellis-subtitle {
  text-align: center;
  font-size: 14px;
  color: var(--trellis-text-muted);
  margin-bottom: 32px;
}

/* ── Form elements ───────────────────────────────────────────────────────── */

.trellis-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.trellis-field {
  position: relative;
}

.trellis-field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--trellis-text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.trellis-field input {
  width: 100%;
  padding: 12px 16px;
  background: var(--trellis-overlay-input);
  border: 1px solid var(--trellis-border);
  border-radius: var(--trellis-radius-sm);
  color: var(--trellis-text);
  font-size: 15px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.trellis-field input:focus {
  border-color: var(--trellis-primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.trellis-field input::placeholder {
  color: var(--trellis-placeholder);
}

/* Password field with eye toggle */
.trellis-field-password input {
  padding-right: 46px;
}

.trellis-eye {
  position: absolute;
  right: 8px;
  bottom: 6px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--trellis-text-muted);
  cursor: pointer;
  padding: 0;
  transition: color 0.15s, background 0.15s;
}

.trellis-eye:hover,
.trellis-eye:focus-visible {
  color: var(--trellis-text);
  background: var(--trellis-overlay-hover);
  outline: none;
}

.trellis-eye svg {
  width: 18px;
  height: 18px;
}

/* Default: show closed eye, hide open eye */
.trellis-eye .trellis-eye-open  { display: none; }
.trellis-eye .trellis-eye-closed { display: block; }

/* When visible: show open eye, hide closed eye */
.trellis-pw-visible .trellis-eye .trellis-eye-open  { display: block; }
.trellis-pw-visible .trellis-eye .trellis-eye-closed { display: none; }

.trellis-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  background: linear-gradient(135deg, var(--trellis-primary), var(--trellis-accent));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--trellis-radius-sm);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  letter-spacing: 0.02em;
  margin-top: 6px;
}

.trellis-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.35);
}

.trellis-btn:active {
  transform: translateY(0);
}

.trellis-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.trellis-link {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--trellis-text-muted);
}

.trellis-link a {
  color: var(--trellis-primary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.trellis-link a:hover {
  color: var(--trellis-accent);
}

/* ── Messages ────────────────────────────────────────────────────────────── */

.trellis-error {
  padding: 10px 14px;
  background: rgba(255, 71, 87, 0.12);
  border: 1px solid rgba(255, 71, 87, 0.25);
  border-radius: var(--trellis-radius-sm);
  color: var(--trellis-error);
  font-size: 14px;
  animation: trellis-shake 0.4s ease;
}

.trellis-success {
  padding: 10px 14px;
  background: rgba(46, 213, 115, 0.12);
  border: 1px solid rgba(46, 213, 115, 0.25);
  border-radius: var(--trellis-radius-sm);
  color: var(--trellis-success);
  font-size: 14px;
}

@keyframes trellis-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ── Admin Panel ─────────────────────────────────────────────────────────── */

.trellis-admin {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px;
  overflow: hidden;
  box-sizing: border-box;
}

.trellis-admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.trellis-admin-header h1 {
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--trellis-primary), var(--trellis-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.trellis-admin-nav {
  display: flex;
  gap: 12px;
  align-items: center;
}

.trellis-admin-nav a {
  color: var(--trellis-text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: color 0.2s;
}

.trellis-admin-nav a:hover {
  color: var(--trellis-text);
}

.trellis-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.trellis-stat {
  background: var(--trellis-surface);
  border: 1px solid var(--trellis-border);
  border-radius: var(--trellis-radius-sm);
  padding: 20px;
}

.trellis-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--trellis-primary);
}

.trellis-stat-label {
  font-size: 13px;
  color: var(--trellis-text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trellis-section {
  background: var(--trellis-surface);
  border: 1px solid var(--trellis-border);
  border-radius: var(--trellis-radius);
  margin-bottom: 24px;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  width: 100%;
}

.trellis-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--trellis-border);
}

.trellis-section-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.trellis-admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  background: var(--trellis-surface);
  border: 1px solid var(--trellis-border);
  border-radius: var(--trellis-radius);
}

.trellis-admin-tab {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--trellis-text-muted);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms, color 120ms, border-color 120ms;
  font-family: inherit;
}

.trellis-admin-tab:hover {
  background: var(--trellis-overlay-subtle);
  color: var(--trellis-text);
}

.trellis-admin-tab.active {
  background: var(--trellis-primary);
  color: var(--trellis-primary-text, #ffffff);
  border-color: var(--trellis-primary);
}

.trellis-admin-tab.active:hover {
  background: var(--trellis-primary);
  color: var(--trellis-primary-text, #ffffff);
}

/* When a section is inside a tab layout its margin is unnecessary. */
.trellis-admin-tabs + .trellis-section,
.trellis-admin-tabs ~ .trellis-section {
  margin-bottom: 16px;
}

.trellis-table {
  width: 100%;
  border-collapse: collapse;
}

.trellis-table th {
  text-align: left;
  padding: 12px 22px;
  font-size: 12px;
  font-weight: 600;
  color: var(--trellis-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--trellis-border);
}

.trellis-table td {
  padding: 14px 22px;
  font-size: 14px;
  border-bottom: 1px solid var(--trellis-border);
  vertical-align: middle;
}

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

.trellis-table tr:hover td {
  background: var(--trellis-overlay-subtle);
}

.trellis-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--trellis-primary), var(--trellis-accent));
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  margin-right: 10px;
  vertical-align: middle;
  flex-shrink: 0;
}

.trellis-user-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

.trellis-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.trellis-badge-admin {
  background: rgba(102, 126, 234, 0.15);
  color: var(--trellis-primary);
}

.trellis-badge-user {
  background: var(--trellis-overlay-hover);
  color: var(--trellis-text-muted);
}

.trellis-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.trellis-btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--trellis-border);
  border-radius: 8px;
  background: transparent;
  color: var(--trellis-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.trellis-btn-sm:hover:not(:disabled) {
  background: var(--trellis-overlay-hover);
  color: var(--trellis-text);
  border-color: var(--trellis-overlay-border-hover);
}

.trellis-btn-sm:disabled {
  opacity: 0.3;
  cursor: default;
}

.trellis-btn-danger {
  color: var(--trellis-error);
  border-color: rgba(255, 71, 87, 0.2);
}

.trellis-btn-danger:hover {
  background: rgba(255, 71, 87, 0.1);
  border-color: rgba(255, 71, 87, 0.4);
  color: var(--trellis-error);
}

/* Toggle switch */
.trellis-toggle-form {
  display: inline-block;
}

.trellis-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.trellis-toggle input {
  display: none;
}

.trellis-toggle-track {
  width: 44px;
  height: 24px;
  background: var(--trellis-overlay-hover);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
}

.trellis-toggle input:checked + .trellis-toggle-track {
  background: var(--trellis-primary);
}

.trellis-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.trellis-toggle input:checked + .trellis-toggle-track::after {
  transform: translateX(20px);
}

.trellis-toggle-label {
  font-size: 14px;
  color: var(--trellis-text);
}

/* Confirmation dialog */
.trellis-confirm {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

.trellis-confirm.active {
  display: flex;
}

.trellis-confirm-box {
  background: var(--trellis-surface);
  border: 1px solid var(--trellis-border);
  border-radius: var(--trellis-radius);
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--trellis-shadow);
}

.trellis-confirm-box h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.trellis-confirm-box p {
  font-size: 14px;
  color: var(--trellis-text-muted);
  margin-bottom: 20px;
}

.trellis-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ── Build footer ────────────────────────────────────────────────────────── */

.trellis-build-footer {
  position: fixed;
  bottom: 8px;
  right: 12px;
  font-size: 11px;
  color: var(--trellis-footer-color);
  pointer-events: none;
  z-index: 0;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .trellis-card {
    padding: 32px 24px;
    margin: 16px;
  }

  .trellis-admin {
    padding: 20px 16px;
  }

  .trellis-table th,
  .trellis-table td {
    padding: 10px 14px;
  }

  .trellis-actions {
    flex-direction: column;
  }

  .trellis-admin-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── Log viewer ──────────────────────────────────────────────────────────── */
.trellis-log-level-btn.active {
  background: var(--trellis-primary);
  color: #fff;
  border-color: var(--trellis-primary);
}

.trellis-log-line {
  display: block;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 1px 0;
}

/* Timestamp: dim, fixed-width feel */
.trellis-log-ts {
  color: rgba(255,255,255,0.35);
}

/* Level badges */
.trellis-log-lvl {
  font-weight: 600;
  letter-spacing: 0.02em;
}
.trellis-log-lvl-info  { color: #69db7c; }
.trellis-log-lvl-warn  { color: #ffd43b; }
.trellis-log-lvl-error { color: #ff6b6b; }

/* Message text */
.trellis-log-msg { color: var(--trellis-text-muted); }

/* Unstructured / continuation lines */
.trellis-log-other { color: var(--trellis-text-muted); opacity: 0.7; }

/* Error lines get a subtle background highlight */
.trellis-log-error {
  background: rgba(255, 107, 107, 0.08);
  border-left: 2px solid #ff6b6b;
  padding-left: 6px;
  margin-left: -6px;
}
.trellis-log-error .trellis-log-msg { color: #ffa0a0; }

/* Warn lines */
.trellis-log-warn .trellis-log-msg { color: #ffe08a; }

/* Search match highlight */
.trellis-log-match {
  background: rgba(102,252,241,0.3);
  color: inherit;
  border-radius: 2px;
}
