:root {
  color-scheme: dark;
  --bg: #1a1a1a;
  --panel: #242424;
  --border: #333;
  --text: #e6e6e6;
  --muted: #9a9a9a;
  --accent: #7c5cbf;
  --accent-hover: #8f71d1;
  --danger: #c45555;
  --input: #1e1e1e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap {
  max-width: 420px;
  margin: 12vh auto 0;
  padding: 0 20px 40px;
}

.wrap.wide { max-width: 720px; margin-top: 8vh; }
.wrap.admin { max-width: 1100px; margin-top: 4vh; }

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 28px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0;
}

.brand span { color: var(--muted); font-size: 13px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 6px;
}

input, select, textarea {
  width: 100%;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-color: var(--accent);
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  min-height: 44px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; }
button.secondary, .btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover, .btn.secondary:hover { background: #2e2e2e; }

.full { width: 100%; }

.error {
  display: none;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  color: #f0c8c8;
  font-size: 13px;
}

.error.show { display: block; }

.muted { color: var(--muted); font-size: 13px; }
.footer { margin-top: 16px; text-align: center; }

.legal-links { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; font-size: 13px; }
.legal { max-width: 640px; }
.legal-body h2 {
  margin: 20px 0 8px;
  font-size: 15px;
  font-weight: 650;
}
.legal-body p, .legal-body li { color: var(--muted); margin: 0 0 10px; }
.legal-body ul { margin: 0 0 12px; padding-left: 20px; }
.legal-body .muted { margin-top: 16px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 4px 0 16px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.check input { width: auto; margin: 4px 0 0; flex-shrink: 0; }

.quota { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.account-box {
  margin-top: 36px;
  padding-top: 8px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.vaults { display: grid; gap: 10px; }
.vault {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

.vault h2 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.vault-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.copy-field { margin-bottom: 12px; }
.copy-field:last-child { margin-bottom: 0; }
.copy-field .row input { flex: 1; min-width: 0; margin: 0; }

.steps {
  margin: 20px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
}
.steps li { margin: 0 0 8px; }

@media (max-width: 640px) {
  .wrap { margin-top: 24px; }
  .wrap.wide { margin-top: 16px; }
  .top { flex-direction: column; align-items: stretch; }
  .top-actions { width: 100%; }
  .top-actions .btn, .top-actions button { flex: 1; }
  .vault { flex-direction: column; align-items: stretch; }
  .vault-actions { width: 100%; }
  .vault-actions .btn, .vault-actions button { flex: 1; }
  .invite { flex-direction: column; align-items: stretch; }
  .row { flex-direction: column; align-items: stretch; }
  .row input, .row select { width: 100%; min-width: 0; }
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .history-files button.linkish { min-height: 44px; }
}

.h2 {
  margin: 28px 0 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input, .row select { margin: 0; width: auto; flex: 1; min-width: 140px; }
select {
  width: auto;
  margin-bottom: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.invite {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 8%, var(--panel));
  margin-bottom: 8px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th { color: var(--muted); font-weight: 600; font-size: 12px; }

button.danger, .btn.danger {
  background: transparent;
  color: #e08a8a;
  border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--border));
}
button.danger:hover, .btn.danger:hover { background: color-mix(in srgb, var(--danger) 16%, transparent); }

.ok {
  display: none;
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, #4a9 18%, transparent);
  color: #c8efe0;
  font-size: 13px;
}
.ok.show { display: block; }

.audit {
  font-size: 13px;
  color: var(--muted);
}
.audit li { margin: 0 0 8px; }

.history-commit {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.history-files {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
}
.history-files button.linkish {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.history-files button.linkish:hover { text-decoration: underline; background: none; }
.history-view {
  margin-top: 20px;
  padding: 14px;
  border-radius: 10px;
  background: var(--input);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 50vh;
  overflow: auto;
  font-size: 12px;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--input);
  padding: 2px 6px;
  border-radius: 4px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.stat b { font-size: 22px; font-weight: 650; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 16px;
}
.tabs button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.table input.num {
  width: 92px;
  min-width: 92px;
  margin: 0;
  padding: 8px 10px;
  font-size: 14px;
}
.table .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.table .row-actions button { min-height: 36px; padding: 6px 10px; font-size: 13px; }

.hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }

.limits-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.limits-grid label { margin-bottom: 0; }
.limits-grid input { margin-bottom: 0; }
