:root {
  --bg: #0f1419;
  --card: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --ok: #22c55e;
  --err: #ef4444;
  --font: system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 1.25rem 2rem 0;
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 1.5rem; }
header p { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }
.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.user-bar { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; flex-wrap: wrap; justify-content: flex-end; }
.env-badge { font-size: 0.75rem; background: rgba(59, 130, 246, 0.15); border: 1px solid var(--border); padding: 0.2rem 0.5rem; border-radius: 4px; color: var(--muted); }

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  margin-top: 1rem;
}
.app-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.55rem 0.9rem;
  border-bottom: 2px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
}
.app-nav a:hover { color: var(--text); }
.app-nav a.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.page { margin: 0; }
.page.hidden { display: none !important; }
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(59, 130, 246, 0.12), transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(34, 197, 94, 0.08), transparent 45%),
    var(--bg);
}
.login-card { width: 100%; max-width: 360px; }
.login-card-google {
  background: #fff;
  color: #202124;
  border: 1px solid #dadce0;
  border-radius: 12px;
  padding: 1.5rem 1.35rem 1.25rem;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.15);
}
.login-card-google h2 { margin: 0 0 0.35rem; color: #202124; }
.login-card-google .muted,
.login-card-google .login-google-hint { color: #5f6368; font-size: 0.9rem; margin: 0 0 1.1rem; line-height: 1.45; }
.login-card-google .login-google-hint strong { color: #202124; }
.login-card-google .login-error { color: #d93025; }
.google-btn-wrap {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin-bottom: 0.75rem;
}
.password-fallback {
  margin-top: 0.75rem;
  border-top: 1px solid #e8eaed;
  padding-top: 0.65rem;
  color: #5f6368;
  font-size: 0.8rem;
}
.password-fallback summary { cursor: pointer; user-select: none; }
.password-login-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.75rem;
}
.password-login-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: #5f6368;
}
.password-login-form input {
  background: #fff;
  border: 1px solid #dadce0;
  color: #202124;
  border-radius: 6px;
  padding: 0.45rem 0.55rem;
}
.password-login-form button {
  background: #1a73e8;
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}
.login-error { color: var(--err); font-size: 0.85rem; min-height: 1.2em; }

.mapping-hint { margin: 0 0 0.75rem; font-size: 0.85rem; }
.mapping-user {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
}
.mapping-user-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
.mapping-list {
  margin: 0.5rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.permissions-client-list {
  max-height: 50vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0 1rem;
}
.perm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
}
.perm-client { display: flex; flex-direction: column; gap: 0.15rem; }
.perm-checks { display: flex; gap: 0.75rem; flex-shrink: 0; }

a.dl-link { color: var(--accent); cursor: pointer; text-decoration: underline; background: none; border: none; font: inherit; padding: 0; }

.badge { font-size: 0.7rem; background: var(--border); padding: 0.15rem 0.4rem; border-radius: 3px; vertical-align: middle; }
.subheading { margin: 0 0 0.5rem; font-size: 0.95rem; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.row-actions { margin-top: 0.5rem; }
.deploy-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(4.25rem, auto));
  gap: 0.35rem;
  justify-content: end;
  align-items: center;
}
.deploy-actions .action-btn {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: rgba(59, 130, 246, 0.2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.deploy-actions .action-btn:hover { background: rgba(59, 130, 246, 0.35); }
.deploy-actions .action-btn.danger { background: rgba(239, 68, 68, 0.15); }
.deploy-actions .action-btn.danger:hover { background: rgba(239, 68, 68, 0.28); }
.deploy-actions .action-placeholder {
  display: block;
  min-height: 1.6rem;
  visibility: hidden;
}
.actions-col { width: 18rem; text-align: right; }
.instances-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}
#instances-dialog {
  max-width: min(96vw, 80rem);
  width: min(96vw, 80rem);
}
.instances-dialog-body { min-width: 0; width: 100%; }
.table-wrap { overflow-x: auto; margin: 0.75rem 0; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.user-item { padding: 0.5rem 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.user-item.inactive { opacity: 0.55; }
.user-meta { color: var(--muted); font-size: 0.8rem; }
.user-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }
.user-actions button { padding: 0.35rem 0.5rem; font-size: 0.75rem; }
.role-tag { text-transform: uppercase; font-size: 0.65rem; letter-spacing: 0.03em; }

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; gap: 0.75rem; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.panel-head-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filter-input {
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-width: 11rem;
  max-width: 100%;
}
.filter-input.client-filter { width: 100%; margin-bottom: 0.75rem; }
.filter-input::placeholder { color: var(--muted); }
.filter-empty { color: var(--muted); font-style: italic; }
.small-btn { padding: 0.35rem 0.6rem; font-size: 0.8rem; }

.client-details { font-size: 0.85rem; min-width: 0; }
.client-details .detail-title { margin: 0 0 0.25rem; font-size: 1rem; }
.client-details .detail-id { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.75rem; }
.client-details dl {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(5.5rem, auto) minmax(0, 1fr);
  gap: 0.35rem 0.75rem;
  align-items: start;
}
.client-details dt { color: var(--muted); margin: 0; }
.client-details dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
}
.client-details code { white-space: normal; overflow-wrap: anywhere; }
.client-details .detail-block { margin-top: 0.85rem; padding-top: 0.85rem; border-top: 1px solid var(--border); }
.client-details .detail-block h4 { margin: 0 0 0.5rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.client-details .notes { margin-top: 0.75rem; padding: 0.5rem 0.6rem; background: var(--bg); border-radius: 4px; color: var(--muted); font-size: 0.8rem; }
.client-details .effective { margin-top: 0.85rem; padding: 0.6rem; background: rgba(59, 130, 246, 0.1); border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; }
.client-details .tag { display: inline-block; background: var(--border); padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.75rem; }

.field-hint { display: block; min-height: 1.1em; font-size: 0.75rem; margin-top: 0.2rem; }
.field-hint.ok { color: var(--ok); }
.field-hint.err { color: var(--err); }
.field-hint.pending { color: var(--muted); }
input.branch-invalid { border-color: var(--err); }
input.branch-valid { border-color: var(--ok); }

.branch-row {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) auto;
  gap: 0.4rem;
  align-items: center;
}
.branch-select { min-width: 0; }
.branch-refresh {
  padding: 0.45rem 0.55rem;
  font-size: 0.95rem;
  line-height: 1;
}
@media (max-width: 640px) {
  .branch-row { grid-template-columns: 1fr; }
  .branch-refresh { width: 100%; }
}

.progress-wrap { margin-top: 1rem; }
.progress-wrap.hidden { display: none; }
.progress-header { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.progress-track { height: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: var(--accent); border-radius: 3px; transition: width 0.35s ease; }
.progress-bar.failed { background: var(--err); }
.progress-bar.done { background: var(--ok); }
.progress-wrap.is-running .progress-bar { background: linear-gradient(90deg, var(--accent) 0%, #60a5fa 50%, var(--accent) 100%); background-size: 200% 100%; animation: progress-shimmer 1.2s linear infinite; }
@keyframes progress-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

.storage-summary { font-size: 0.85rem; line-height: 1.5; margin: 0 0 0.75rem; }
.storage-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.storage-hint { font-size: 0.75rem; margin: 0; }
.danger-btn { border-color: var(--err); color: #fca5a5; }
.danger-btn:hover { background: rgba(239, 68, 68, 0.15); }
.btn-link.danger { color: #fca5a5; }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  padding: 1.5rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}
.full { grid-column: 1 / -1; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  min-width: 0;
}
.card h2 { margin: 0 0 1rem; font-size: 1.1rem; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
label input, label select, label textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.checkbox { display: flex; align-items: center; gap: 0.5rem; color: var(--text); }
.checkbox input { width: auto; margin: 0; }

button {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  cursor: pointer;
}
button.secondary { background: var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.log-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.log-actions.hidden { display: none; }

.log {
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.45;
  max-height: 280px;
  overflow: auto;
  white-space: pre;
  word-break: normal;
  tab-size: 4;
}

.table-scroll { overflow-x: auto; }
.stats-table { font-size: 0.82rem; }
.stats-table td, .stats-table th { white-space: nowrap; }
.stats-table td.wrap { white-space: normal; min-width: 10rem; }
.stats-hint { font-size: 0.8rem; margin: 0 0 0.75rem; }
.stats-never { color: var(--muted); font-style: italic; }
.stats-version { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
.status-ok { color: var(--ok); }
.status-fail { color: var(--err); }
.status-run { color: var(--accent); }

.client-item {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.client-item small { color: var(--muted); }
.client-item-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }

.snapshot-preview-body { min-width: min(420px, 85vw); }
.snapshot-preview-dl {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.35rem 0.75rem;
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
}
.snapshot-preview-dl dt { color: var(--muted); margin: 0; }
.snapshot-preview-dl dd { margin: 0; overflow-wrap: anywhere; }
.snapshot-warning {
  margin: 0.5rem 0;
  padding: 0.55rem 0.7rem;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 0.8rem;
}
.snapshot-warning.ok {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.35);
  color: #86efac;
}
.snapshot-warning ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }
.snapshot-cleanup-opt { margin-top: 0.85rem; display: flex; align-items: flex-start; gap: 0.45rem; font-size: 0.82rem; }
.snapshot-cleanup-opt input { margin-top: 0.2rem; }
#snapshot-cleanup-leftovers { margin-top: 0.65rem; }
.snapshot-cleanup-msg { margin: 0.35rem 0 0; font-size: 0.8rem; min-height: 1.1em; }

dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  padding: 1.25rem;
  max-width: 480px;
  width: 90%;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
fieldset {
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
}
legend { font-size: 0.8rem; color: var(--muted); }
.dialog-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr; }
}
