:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f3f4f6;
  --border: #e6e8ec;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #6366f1;
  --accent-2: #8b5cf6;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.10);
  --shadow-lg: 0 10px 30px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #eef1f6 0%, var(--bg) 240px);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); }

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.logo span { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); font-size: 13px; }

nav { margin-left: auto; display: flex; gap: 6px; }
nav button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
nav button:hover { color: var(--text); background: var(--panel-2); }
nav button.active { color: var(--accent); background: #eef0ff; border-color: #dfe1ff; }

main { max-width: 1100px; margin: 0 auto; padding: 28px; }
.view { display: none; }
.view.active { display: block; }

h2 { margin: 0 0 4px; font-size: 20px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.provider-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.provider-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff;
}
.provider-icon.openai { background: #10a37f; }
.provider-icon.anthropic { background: #d97757; }
.provider-icon.gemini { background: linear-gradient(135deg, #4285f4, #9b72cb); }
.provider-icon.grok { background: #1a1a1a; }
.provider-title { font-size: 16px; font-weight: 700; }
.provider-title small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; text-transform: uppercase; letter-spacing: .4px; }
.badge.on { background: rgba(16, 185, 129, .12); color: #059669; }
.badge.off { background: rgba(107, 114, 128, .12); color: var(--muted); }

.field { margin-bottom: 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.keylink { float: right; font-size: 12px; font-weight: 600; text-decoration: none; }
.keylink:hover { text-decoration: underline; }
input[type=text], input[type=password], input[type=email], input[type=date], input[type=number], select {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
textarea {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }

.pg-response {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  min-height: 220px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.55;
}
.pg-response.error { border-color: rgba(239, 68, 68, .5); color: var(--red); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row .field { flex: 1; margin-bottom: 0; }

.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .10);
}
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: #fff; border: 1px solid var(--border); color: var(--text); box-shadow: none; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); box-shadow: none; }
.btn.danger { background: #fff; border: 1px solid rgba(239, 68, 68, .4); color: var(--red); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.test-result { font-size: 13px; margin-left: auto; }
.test-result.ok { color: #059669; }
.test-result.err { color: var(--red); }
.test-result.pending { color: #b45309; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { display: none; }
.slider { position: absolute; inset: 0; background: #e5e7eb; border: 1px solid var(--border); border-radius: 24px; transition: .2s; cursor: pointer; }
.slider:before { content: ''; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); background: #fff; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: var(--panel-2); }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border); }
.status-ok { color: #059669; }
.status-error { color: var(--red); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 20px; }
.filters .field { margin-bottom: 0; }
.filters input, .filters select { width: auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.keybox { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; background: var(--panel-2); border: 1px dashed var(--accent); border-radius: 8px; padding: 12px; word-break: break-all; font-size: 13px; margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; }
.warn { background: #fffaeb; border: 1px solid #fce4a6; color: #92600c; padding: 12px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 18px; }

pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; font-size: 13px; line-height: 1.5; }
code { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; }

.toast { position: fixed; bottom: 24px; right: 24px; background: #fff; border: 1px solid var(--border); border-left: 3px solid var(--green); padding: 12px 18px; border-radius: 8px; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px); transition: .25s; z-index: 50; color: var(--text); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { border-left-color: var(--red); }

.app-version { position: fixed; bottom: 8px; right: 12px; font-size: 11px; color: var(--muted); z-index: 40; }
.app-version a { color: var(--muted); text-decoration: none; }
.app-version a:hover { color: var(--accent); text-decoration: underline; }

/* Profile avatar + dropdown */
.profile-menu { position: relative; margin-left: 10px; }
.avatar-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--accent); color: #fff;
  font-weight: 700; font-size: 14px; cursor: pointer;
  display: grid; place-items: center; padding: 0;
  background-size: cover; background-position: center;
}
.avatar-btn:hover { box-shadow: 0 0 0 3px rgba(99, 102, 241, .18); }
.avatar-lg {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 18px;
  display: grid; place-items: center; flex: none;
  background-size: cover; background-position: center;
}
.dropdown {
  position: absolute; right: 0; top: 46px; width: 250px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 8px; z-index: 60;
}
.dropdown-head { display: flex; gap: 12px; align-items: center; padding: 8px 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-item {
  display: block; width: 100%; text-align: left; box-sizing: border-box;
  background: transparent; border: none; padding: 9px 10px; border-radius: 8px;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; text-decoration: none;
}
.dropdown-item:hover { background: var(--panel-2); }
.dropdown-item.danger { color: var(--red); }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }

.err-link { cursor: pointer; text-decoration: underline dotted; }
.err-link:hover { filter: brightness(1.2); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(17, 24, 39, 0.45);
  display: none; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 680px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.err-detail {
  background: var(--panel-2);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 8px;
  padding: 14px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--red);
  font-size: 13px;
  max-height: 50vh;
  overflow: auto;
}
