:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #657181;
  --line: #d9dee6;
  --accent: #16745c;
  --accent-dark: #0f5d49;
  --danger: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #ffffff;
  border-right: 1px solid var(--line);
}
.sidebar-brand {
  display: block;
  margin: 0 10px 28px;
}
.side-nav {
  display: grid;
  gap: 6px;
}
.side-link, .side-group-label {
  min-height: 38px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font-weight: 700;
}
.side-link:hover {
  background: #edf3f0;
  text-decoration: none;
}
.side-link.active {
  background: #e0f0ea;
  color: var(--accent-dark);
}
.side-group {
  display: grid;
  gap: 4px;
  margin-top: 2px;
}
.side-group-label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.side-link.sub {
  margin-left: 12px;
  padding-left: 18px;
  font-weight: 650;
}
.content-shell {
  min-width: 0;
}
.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.auth-topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; color: var(--ink); }
.user-menu {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}
.credit-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 4px 14px;
  border-radius: 999px;
  background: #e8f4ef;
  border: 1px solid #b8ded0;
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
}
.credit-chip:hover { background: #d6eee4; text-decoration: none; }
.avatar-button {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #b8ded0;
  background: #e8f4ef;
  color: var(--accent-dark);
  font-weight: 800;
}
.avatar-button:hover, .avatar-button:focus {
  background: #d6eee4;
  outline: 2px solid transparent;
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: 48px;
  min-width: 190px;
  display: none;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(23, 32, 42, .14);
}
.user-menu:focus-within .user-dropdown {
  display: grid;
  gap: 4px;
}
.user-dropdown a, .dropdown-button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 650;
  text-align: left;
}
.user-dropdown a:hover, .dropdown-button:hover {
  background: #edf3f0;
  color: var(--accent-dark);
  text-decoration: none;
}
.page { max-width: 1180px; margin: 0 auto; padding: 32px 20px 56px; }
.auth-page { max-width: 1180px; }
h1 { font-size: 30px; margin: 0 0 22px; }
h2 { font-size: 20px; margin: 28px 0 14px; }
.auth-panel, .narrow {
  max-width: 520px;
  margin: 48px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}
.panel, .metric, .qr-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.stack { display: grid; gap: 10px; }
label { font-weight: 650; font-size: 14px; }
input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--accent-dark); text-decoration: none; }
.small { min-height: 34px; padding: 6px 10px; font-size: 14px; }
.secondary, .ghost { background: #fff; color: var(--accent-dark); }
.ghost { border-color: var(--line); color: var(--muted); }
.danger { background: var(--danger); border-color: var(--danger); }
.inline-form { display: flex; gap: 10px; align-items: end; margin: 12px 0; }
.inline-form input { max-width: 260px; }
.danger-form { margin-top: 8px; }
.grid { display: grid; gap: 16px; }
.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr); gap: 20px; margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.metric span { display: block; color: var(--muted); font-size: 14px; }
.metric strong { display: block; font-size: 30px; margin: 6px 0 12px; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; background: #fbfcfd; }
tr:last-child td { border-bottom: 0; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  border-radius: 999px;
  background: #e8f4ef;
  color: #0f5d49;
  font-size: 13px;
  font-weight: 700;
}
.notice, .error {
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.notice { background: #e8f4ef; border: 1px solid #b8ded0; }
.error { background: #fff0ed; border: 1px solid #ffd0c8; color: var(--danger); }
.error-text { color: var(--danger); }
.qr-panel { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: center; margin-top: 20px; }
.qr-panel img { width: 220px; height: 220px; object-fit: contain; border: 1px solid var(--line); }
.details {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.details dt, .details dd { margin: 0; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.details dt { color: var(--muted); background: #fbfcfd; font-weight: 700; }
.details dd { background: var(--surface); }
pre {
  white-space: pre-wrap;
  overflow-x: auto;
  padding: 16px;
  background: #111827;
  color: #eef2ff;
  border-radius: 8px;
  font-size: 13px;
}
.guide-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
}
.guide-main {
  min-width: 0;
}
.download-panel {
  position: sticky;
  top: 88px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}
.download-panel h2 {
  margin-top: 0;
}
.download-panel p {
  color: var(--muted);
  margin-bottom: 18px;
}
.download-panel .button {
  width: 100%;
}
.markdown-body {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px 38px;
  color: #1f2933;
}
.markdown-body h1 {
  font-size: 34px;
  margin: 0 0 26px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.markdown-body h2 {
  font-size: 24px;
  margin: 34px 0 16px;
}
.markdown-body h3 {
  font-size: 18px;
  margin: 26px 0 10px;
}
.markdown-body h4 {
  font-size: 16px;
  margin: 22px 0 8px;
}
.markdown-body p {
  margin: 0 0 15px;
  color: #344052;
}
.markdown-body ul {
  margin: 0 0 18px 22px;
  padding: 0;
}
.markdown-body li {
  margin: 7px 0;
}
.markdown-body code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef3f0;
  color: #0f5d49;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
}
.markdown-body pre {
  margin: 16px 0 22px;
  white-space: pre;
}
.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: 13px;
}
.console-box {
  min-height: 460px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #d6f5ea;
  padding: 18px;
}
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: auto; }
@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px 20px;
  }
  .sidebar-brand { margin: 0 0 12px; }
  .side-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .side-group {
    display: contents;
  }
  .side-group-label {
    display: none;
  }
  .side-link, .side-link.sub {
    margin-left: 0;
    padding: 7px 10px;
  }
  .topbar { padding: 12px 20px; }
  .two, .three, .split, .qr-panel, .guide-layout { grid-template-columns: 1fr; }
  .download-panel { position: static; order: -1; }
  .markdown-body { padding: 24px 20px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form input { max-width: none; }
  table { display: block; overflow-x: auto; }
}

/* ---- Service detail ---- */
.svc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.svc-head h1 { margin: 0; }
.svc-sub { color: var(--muted); font-size: 14px; margin-top: 6px; }
.svc-banner {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px; border-radius: 10px; margin-bottom: 24px;
  border: 1px solid var(--line); background: var(--surface);
}
.svc-banner .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--muted); }
.svc-banner.is-provisioning { background: #fff8ec; border-color: #f0d79b; }
.svc-banner.is-provisioning .dot { background: #c98a00; animation: svc-pulse 1.3s ease-in-out infinite; }
.svc-banner.is-active { background: #e8f4ef; border-color: #b8ded0; }
.svc-banner.is-active .dot { background: var(--accent); }
.svc-banner.is-bad { background: #fff0ed; border-color: #ffd0c8; }
.svc-banner.is-bad .dot { background: var(--danger); }
.svc-banner.is-warn { background: #fff8ec; border-color: #f0d79b; }
.svc-banner.is-warn .dot { background: #c98a00; }

/* Kebab action menu (row-level) */
.kebab { position: relative; display: inline-block; }
.kebab-btn {
  min-height: 32px; width: 36px; padding: 0;
  border-radius: 6px; border: 1px solid var(--line);
  background: #fff; color: var(--ink);
  font-size: 20px; line-height: 1; letter-spacing: 2px;
}
.kebab-btn:hover { background: #f3f5f8; }
.kebab-menu {
  display: none;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(23, 32, 42, .14);
  padding: 6px;
  z-index: 30;
}
.kebab-menu form { margin: 0; }
.kebab-menu form button {
  width: 100%;
  justify-content: flex-start;
  background: transparent; color: var(--ink);
  border: 0;
  min-height: 36px;
  padding: 6px 10px;
  font-weight: 650;
}
.kebab-menu form button:hover { background: #edf3f0; color: var(--accent-dark); }
.kebab-menu form button.danger { color: var(--danger); }
.kebab-menu form button.danger:hover { background: #fef2f0; color: var(--danger); }

/* Error popup (flash_error) — fixed top-center toast */
.flash-popup {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  min-width: 320px;
  max-width: 560px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--danger);
  border-left: 4px solid var(--danger);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(180, 35, 24, 0.22);
  color: var(--ink);
  animation: flash-popup-in 0.22s ease-out;
}
.flash-popup-body { flex: 1; min-width: 0; }
.flash-popup-body strong { display: block; color: var(--danger); margin-bottom: 4px; font-size: 14px; }
.flash-popup-body p { margin: 0; font-size: 14px; }
.flash-popup-close {
  background: transparent; color: var(--muted);
  border: 0; padding: 0 4px;
  font-size: 22px; line-height: 1;
  cursor: pointer; min-height: auto;
}
.flash-popup-close:hover { color: var(--ink); background: transparent; }
@keyframes flash-popup-in {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Native <dialog> modal styled to match our cards */
.modal-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 64px rgba(23, 32, 42, .22);
  animation: modal-in 0.16s ease-out;
}
.modal-dialog::backdrop {
  background: rgba(15, 23, 32, .42);
  animation: modal-fade 0.16s ease-out;
}
.modal-dialog h2 { font-size: 17px; margin: 0 0 4px; padding-right: 28px; }
.modal-dialog .hint { font-size: 12.5px; line-height: 1.45; margin: 0 0 14px; color: var(--muted); }
.modal-dialog form.stack { gap: 8px; }
.modal-dialog label { font-size: 12.5px; margin-top: 4px; }
.modal-dialog input { min-height: 36px; font-size: 14px; padding: 7px 10px; }
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.modal-actions .btn-cancel,
.modal-actions .btn-apply {
  flex: 1;
  min-height: 38px;
  padding: 8px 12px;
  font-size: 14px;
}
.modal-actions .btn-cancel {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.modal-actions .btn-cancel:hover { background: #f3f5f8; }
button.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 6px;
  font-size: 22px;
  line-height: 1;
  font-weight: 500;
  cursor: pointer;
}
button.modal-close:hover { background: #f0f2f5; color: var(--ink); }
@keyframes modal-in {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes modal-fade {
  from { opacity: 0; } to { opacity: 1; }
}
.svc-banner strong { display: block; font-size: 15px; }
.svc-banner small { color: var(--muted); font-size: 13px; }
@keyframes svc-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .3; transform: scale(.65); } }

.svc-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.svc-stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.svc-stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.svc-stat .v { font-size: 18px; font-weight: 700; margin-top: 6px; word-break: break-all; }

.svc-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; margin-top: 22px; }
.svc-card h2 { margin: 0 0 4px; }
.svc-card .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.svc-card table { margin: 0; }

.svc-cred { display: grid; gap: 14px; }
.svc-field { display: grid; gap: 6px; }
.svc-field .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.svc-value {
  display: flex; align-items: center; gap: 8px;
  background: #0e1726; color: #e8f0ff; border-radius: 8px; padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
}
.svc-value code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; }
.svc-value.wrap, .svc-value.block { align-items: flex-start; }
.svc-value.wrap code {
  white-space: pre-wrap; word-break: break-all; overflow-wrap: anywhere; overflow-x: visible;
}
.svc-value.block code {
  white-space: pre-wrap; word-break: break-all; overflow-wrap: anywhere;
  max-height: 220px; overflow: auto;
}
.svc-mini {
  min-height: 30px; padding: 4px 10px; font-size: 12px; font-weight: 700; flex: none;
  border-radius: 6px; border: 1px solid #2b3a52; background: #1b2740; color: #cfe3ff;
}
.svc-mini:hover { background: #27374f; }
.svc-mini.copied { background: var(--accent); border-color: var(--accent); color: #fff; }
details.svc-disclose { margin-top: 2px; }
details.svc-disclose > summary {
  cursor: pointer; color: var(--accent-dark); font-weight: 700; font-size: 13px; list-style: none; margin-bottom: 8px;
}
details.svc-disclose > summary::-webkit-details-marker { display: none; }
details.svc-disclose > summary::before { content: "\25B8  "; }
details.svc-disclose[open] > summary::before { content: "\25BE  "; }

.svc-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 26px; }
.svc-actions form { margin: 0; }
.svc-actions .spacer { flex: 1; }

@media (max-width: 820px) {
  .svc-head { flex-direction: column; }
  .svc-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .svc-actions .spacer { display: none; }
}
