/* ── Google Fonts ──────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ── Design tokens: dark (default) ────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg:           #0D1411;
  --surface:      #141E1A;
  --surface-hi:   #1C2820;
  --border:       #243020;
  --border-hi:    #324438;

  --text:         #E0EDE6;
  --muted:        #6B8C7B;
  --dim:          #3D5448;

  --accent:       #2F8F61;
  --accent-hi:    #38A872;
  --accent-dim:   rgba(47, 143, 97, 0.13);
  --accent-glow:  rgba(47, 143, 97, 0.22);

  --danger:       #E05252;
  --danger-dim:   rgba(224, 82, 82, 0.10);

  --success:      #2F8F61;
  --success-dim:  rgba(47, 143, 97, 0.10);

  --skeleton-a:   #1C2820;
  --skeleton-b:   #253428;

  --shadow:       0 4px 16px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

/* ── Design tokens: light ──────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #F4FAF6;
  --surface:      #FFFFFF;
  --surface-hi:   #EEF7F1;
  --border:       #D0E8D8;
  --border-hi:    #B0D4BE;

  --text:         #1A2920;
  --muted:        #527A62;
  --dim:          #9BBDAB;

  --accent:       #2F8F61;
  --accent-hi:    #267A52;
  --accent-dim:   rgba(47, 143, 97, 0.10);
  --accent-glow:  rgba(47, 143, 97, 0.18);

  --danger:       #D94444;
  --danger-dim:   rgba(217, 68, 68, 0.08);

  --success:      #2F8F61;
  --success-dim:  rgba(47, 143, 97, 0.08);

  --skeleton-a:   #E8F3EC;
  --skeleton-b:   #D8EDE0;

  --shadow:       0 4px 16px rgba(0, 0, 0, 0.08);

  color-scheme: light;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }

/* ── Auth page ─────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px 32px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.logo-mark { color: var(--accent); font-size: 20px; line-height: 1; }
.logo-text  { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }

.auth-subtitle {
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  margin-bottom: 28px;
}

.auth-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 14px;
  text-align: center;
  line-height: 1.5;
}

.btn-back { margin-top: 10px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.otp-input {
  font-family: 'JetBrains Mono', monospace !important;
  font-size: 22px !important;
  letter-spacing: 0.2em;
  text-align: center;
}

/* magic link sent state */
.sent-icon  { font-size: 36px; text-align: center; margin-bottom: 14px; }
.sent-title { font-size: 16px; font-weight: 600; text-align: center; margin-bottom: 8px; }
.sent-desc  { font-size: 13px; color: var(--muted); text-align: center; line-height: 1.6; margin-bottom: 20px; }
.sent-desc strong { color: var(--text); }

/* ── Form fields ───────────────────────────────────────────────── */
.form-field { margin-bottom: 16px; }

.form-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-field input,
.form-field textarea,
.form-field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-field input::placeholder,
.form-field textarea::placeholder { color: var(--dim); }

.form-field textarea { resize: vertical; min-height: 72px; }

.form-field.mono input {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.form-field .field-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.4;
}

/* value field with show/hide toggle */
.value-wrap { position: relative; }
.value-wrap input { padding-right: 72px; }
.value-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
  padding: 3px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  transition: color 0.12s, border-color 0.12s;
}
.value-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, opacity 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hi); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hi);
  color: var(--text);
  border-color: var(--border-hi);
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(224, 82, 82, 0.25);
}
.btn-danger:hover:not(:disabled) { background: rgba(224, 82, 82, 0.16); }

.btn-full { width: 100%; }

.btn-icon {
  padding: 6px;
  border-radius: 6px;
  color: var(--muted);
  line-height: 0;
  transition: color 0.12s, background 0.12s;
}
.btn-icon:hover               { color: var(--text);    background: var(--surface-hi); }
.btn-icon.danger:hover        { color: var(--danger);  background: var(--danger-dim); }
.btn-icon.accent:hover        { color: var(--accent);  background: var(--accent-dim); }

/* spinner */
.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
[data-theme="light"] .btn-spinner {
  border-color: rgba(255,255,255,0.4);
  border-top-color: #fff;
}

/* ── Error / info ──────────────────────────────────────────────── */
.error-message {
  background: var(--danger-dim);
  border: 1px solid rgba(224, 82, 82, 0.22);
  border-radius: 6px;
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

/* ── App shell ─────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.18s;
}
.app.ready { opacity: 1; }

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-top {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo { display: flex; align-items: center; gap: 9px; margin-bottom: 2px; }
.sidebar-logo .logo-mark { font-size: 18px; }
.sidebar-logo .logo-text  { font-size: 15px; }

.sidebar-tagline {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-left: 27px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  width: 100%;
  text-align: left;
}
.nav-item:hover:not(:disabled) { background: var(--surface-hi); color: var(--text); }
.nav-item.active               { background: var(--accent-dim); color: var(--accent); }
.nav-item:disabled             { cursor: not-allowed; opacity: 0.35; }

.nav-item-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border-hi);
  flex-shrink: 0;
}
.nav-item.active .nav-item-dot { background: var(--accent); }

.nav-item-badge {
  margin-left: auto;
  font-size: 9px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--dim);
  background: var(--surface-hi);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  font-size: 11px;
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  padding: 6px 0;
  margin-bottom: 8px;
  cursor: pointer;
  width: 100%;
  background: none;
  border: none;
  transition: color 0.12s;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle-icon { font-size: 14px; }

/* ── Main panel ────────────────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.main > section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.main-header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.main-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.main-title span { color: var(--muted); font-weight: 400; }

.main-body { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 28px; }

/* ── Search bar ────────────────────────────────────────────────── */
.search-bar { position: relative; margin-bottom: 20px; }

.search-bar input {
  width: 100%; max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px 8px 34px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.search-bar input::placeholder { color: var(--dim); }

.search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--dim); pointer-events: none;
}

/* ── Env table ─────────────────────────────────────────────────── */
.env-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.env-table th {
  background: var(--surface);
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.env-row {
  border-left: 2px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.env-row:not(:last-child) td { border-bottom: 1px solid var(--border); }
.env-row:hover { background: var(--surface-hi); border-left-color: var(--accent); }

.env-row td { padding: 14px 16px; vertical-align: middle; }

/* key + description */
.cell-key { min-width: 220px; }
.key-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.02em;
  margin-bottom: 3px;
}
.key-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  max-width: 340px;
}

/* value */
.cell-value { min-width: 160px; }
.value-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.value-masked  { color: var(--dim);   letter-spacing: 0.06em; }
.value-suffix  { color: var(--muted); font-weight: 500; }
.value-revealed {
  color: var(--text);
  background: var(--accent-dim);
  border: 1px solid rgba(47, 143, 97, 0.2);
  border-radius: 4px;
  padding: 2px 8px;
  word-break: break-all;
  max-width: 320px;
}
.reveal-countdown {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* date */
.cell-date {
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  min-width: 90px;
}

/* actions */
.cell-actions { text-align: right; white-space: nowrap; }
.actions-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.12s;
}
.env-row:hover .actions-group { opacity: 1; }

/* unset / placeholder rows */
.env-row--unset { opacity: 0.5; }
.env-row--unset:hover { opacity: 1; }
.value-unset { font-style: italic; color: var(--dim); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Empty state ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--muted);
}
.empty-state-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }
.empty-state h3   { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-state p    { font-size: 13px; margin-bottom: 20px; }

/* ── Loading: full-page overlay ────────────────────────────────── */
.page-loading {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  transition: opacity 0.2s;
}
.page-loading.hidden { opacity: 0; pointer-events: none; }

.page-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Skeleton rows ─────────────────────────────────────────────── */
.skeleton-row td { padding: 16px; }
.skeleton {
  background: linear-gradient(90deg, var(--skeleton-a) 25%, var(--skeleton-b) 50%, var(--skeleton-a) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
  height: 14px;
}
.skeleton.wide   { width: 160px; }
.skeleton.narrow { width: 100px; }
.skeleton.short  { width: 60px;  }
.skeleton.desc   { width: 240px; height: 11px; margin-top: 5px; }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s;
}
[data-theme="light"] .modal-overlay { background: rgba(0,0,0,0.3); }
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s;
}
.modal-overlay.open .modal { transform: none; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title  { font-size: 14px; font-weight: 600; }
.modal-close  { color: var(--muted); padding: 4px; border-radius: 4px; font-size: 18px; line-height: 1; }
.modal-close:hover { color: var(--text); background: var(--surface-hi); }

.modal-body   { padding: 20px; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ── Toast ─────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: slideUp 0.2s ease-out;
  max-width: 320px;
}
.toast.success { border-color: rgba(47, 143, 97, 0.4); }
.toast.error   { border-color: rgba(224, 82, 82, 0.35); }

.toast-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.toast.success .toast-dot { background: var(--success); }
.toast.error   .toast-dot { background: var(--danger);  }

.toast-dismissing { animation: slideDown 0.2s ease-in forwards; }

/* ── Confirm dialog ────────────────────────────────────────────── */
.confirm-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  opacity: 0; pointer-events: none;
  transition: opacity 0.15s;
}
[data-theme="light"] .confirm-overlay { background: rgba(0,0,0,0.3); }
.confirm-overlay.open { opacity: 1; pointer-events: auto; }

.confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow);
}
.confirm-box h3  { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.confirm-box p   { font-size: 13px; color: var(--muted); margin-bottom: 20px; line-height: 1.5; }
.confirm-box code { font-family: 'JetBrains Mono', monospace; color: var(--accent); font-size: 12px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ── Animations ────────────────────────────────────────────────── */
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes shimmer  { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@keyframes slideUp  { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideDown{ from { transform: translateY(0); opacity: 1; } to { transform: translateY(8px); opacity: 0; } }

/* ── Focus ─────────────────────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar             { width: 6px; height: 6px; }
::-webkit-scrollbar-track       { background: transparent; }
::-webkit-scrollbar-thumb       { background: var(--border-hi); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Reduced motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sidebar    { display: none; }
  .main-body  { padding: 16px; }
}
