@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,600;9..144,700&display=swap");

:root {
  --ink: #172033;
  --ink-soft: #3d4a63;
  --muted: #6b7890;
  --line: #e4e8f0;
  --line-strong: #cfd6e4;
  --bg: #f3f1ec;
  --bg-panel: #ffffff;
  --sidebar: #faf9f6;
  --accent: #0b6e4f;
  --accent-hover: #095a41;
  --accent-soft: #e6f4ee;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #067647;
  --radius: 8px;
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  --shadow: 0 1px 2px rgba(23, 32, 51, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(23, 32, 51, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 32, 51, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  background-position: -1px -1px;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 1.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 0.25rem 0.65rem 0.75rem;
  border-bottom: 1px solid var(--line);
}
.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.brand span {
  display: block;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}
.nav-list a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.nav-list a:hover {
  background: #f0eee8;
  color: var(--ink);
}
.nav-list a.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  padding: 1.35rem 1.75rem 1rem;
  background: transparent;
}

.topbar h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.topbar .muted {
  font-size: 0.88rem;
  padding-bottom: 0.2rem;
}

.content {
  padding: 0 1.75rem 2rem;
}

.page-lead {
  margin: -0.35rem 0 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 42rem;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem;
}

.toolbar {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  align-items: center;
}

.toolbar-config {
  align-items: flex-end;
  flex-wrap: nowrap;
}

.toolbar-field {
  flex: 1;
  min-width: 0;
}

.toolbar-config .btn {
  flex-shrink: 0;
  height: 42px;
  align-self: flex-end;
  white-space: nowrap;
}

.modo-switch-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.35rem 0;
}

.modo-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  transition: color 0.15s ease;
}
.modo-label.active {
  color: var(--ink);
}

.modo-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
  cursor: pointer;
}
.modo-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.modo-slider {
  position: absolute;
  inset: 0;
  background: #c5cddb;
  border-radius: 999px;
  transition: background 0.2s ease;
}
.modo-slider::before {
  content: "";
  position: absolute;
  height: 24px;
  width: 24px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(23, 32, 51, 0.2);
  transition: transform 0.2s ease;
}
.modo-switch input:checked + .modo-slider {
  background: var(--accent);
}
.modo-switch input:checked + .modo-slider::before {
  transform: translateX(22px);
}
.modo-switch input:focus-visible + .modo-slider {
  box-shadow: 0 0 0 3px rgba(11, 110, 79, 0.2);
}

#modo-badge.ok {
  background: #e8f6ef;
  color: var(--ok);
}
#modo-badge.warn {
  background: #fff7ed;
  color: var(--warn);
}

.btn {
  border: 0;
  border-radius: 7px;
  padding: 0.62rem 1rem;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease, transform 0.12s ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: translateY(1px); }
.btn.secondary {
  background: #fff;
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
}
.btn.secondary:hover {
  background: #f7f6f2;
  color: var(--ink);
}
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 7px;
  padding: 0.65rem 0.8rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 110, 79, 0.12);
}
.input::placeholder { color: #9aa3b5; }

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.85rem 0.55rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  vertical-align: middle;
}
table.data th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.data tbody tr {
  transition: background 0.12s ease;
}
table.data tbody tr:hover {
  background: #fafaf7;
}
table.data td strong {
  font-weight: 600;
  color: var(--ink);
}
table.data code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: #f3f1ec;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}

.badge {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.ok {
  background: #e8f6ef;
  color: var(--ok);
}
.badge.off {
  background: #fdecea;
  color: var(--danger);
}

.api-key-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.api-key-cell code {
  font-size: 0.75rem;
}
.api-key-cell .btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
}

.row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.row-actions .btn {
  padding: 0.4rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 32, 51, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  width: min(640px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(23, 32, 51, 0.12);
  padding: 1.35rem 1.4rem;
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.modal h2 {
  margin: 0 0 1rem;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.form-grid .full { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 1.1rem;
}
.label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  padding: 0.85rem 1rem;
  border-radius: 8px;
  display: none;
  z-index: 80;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.1);
  font-size: 0.9rem;
}
.toast.show { display: block; animation: modalIn 0.15s ease; }
.toast.error { border-left: 3px solid var(--danger); }
.toast.ok { border-left: 3px solid var(--ok); }

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}
.login-visual {
  position: relative;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  color: #fff;
  background:
    linear-gradient(160deg, rgba(11, 110, 79, 0.92), rgba(23, 32, 51, 0.88)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.06'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.login-visual h1 {
  margin: 0 0 0.5rem;
  font-family: var(--display);
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: -0.03em;
  max-width: 12ch;
}
.login-visual p {
  margin: 0;
  max-width: 28ch;
  opacity: 0.9;
  font-size: 1.05rem;
  line-height: 1.45;
}
.login-form-wrap {
  display: grid;
  place-items: center;
  padding: 2rem 1.25rem;
  background: #fff;
}
.login-card {
  width: min(400px, 100%);
}
.login-card .eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}
.login-card h2 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}
.login-card > p {
  margin: 0 0 1.4rem;
  color: var(--muted);
}
.login-card .field { margin-bottom: 0.9rem; }
.login-card .btn { width: 100%; margin-top: 0.35rem; padding: 0.8rem 1rem; }

.muted { color: var(--muted); }
.stack { display: grid; gap: 1rem; }

.cert-status {
  background: #fafaf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
}
.cert-status code {
  font-size: 0.72rem;
  word-break: break-all;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar-config {
    flex-wrap: wrap;
  }
  .toolbar-config .btn {
    width: 100%;
  }
  .login-page { grid-template-columns: 1fr; }
  .login-visual { min-height: 220px; padding: 1.75rem; }
}
