:root {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-press: #1e3a8a;
  --header: #1e40af;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --field: #ffffff;
  --field-ro: #f9fafb;
  --btn: #ffffff;
  --btn-hover: #f1f5f9;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --focus: #93c5fd;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-press: #1d4ed8;
    --header: #172554;
    --bg: #0b1120;
    --card: #111827;
    --border: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --field: #0f172a;
    --field-ro: #0b1324;
    --btn: #1e293b;
    --btn-hover: #273449;
    --ok: #4ade80;
    --ok-bg: #14532d;
    --err: #f87171;
    --err-bg: #450a0a;
    --focus: #1d4ed8;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- header / tabs ---------- */
.app-header {
  background: var(--header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
}
.brand { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; min-width: 0; }
.brand h1 { font-size: 19px; margin: 0; white-space: nowrap; }
.subtitle { color: #dbeafe; font-size: 13px; }
.badge-local { font-size: 11px; font-weight: 700; color: #1e3a8a; background: #bfdbfe; border-radius: 999px; padding: 2px 9px; }
.lang-toggle {
  background: rgba(255,255,255,.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: 999px;
  padding: 5px 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.lang-toggle:hover { background: rgba(255,255,255,.22); }

.tabs {
  display: flex;
  gap: 2px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 0;
  z-index: 5;
}
.tabs button {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  padding: 11px 14px 9px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

main { flex: 1; width: 100%; max-width: 1280px; margin: 0 auto; padding: 16px; }
.panel { display: none; }
.panel.active { display: block; }

/* ---------- layout ---------- */
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-tight { display: flex; flex-direction: column; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-gen { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row.wrap { margin-top: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.card-head h2 { font-size: 14px; margin: 0; color: var(--accent); }

/* ---------- controls ---------- */
textarea, input[type=text], input:not([type]), input[type=email], input[type=password],
input[type=datetime-local], select {
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  min-width: 0;
}
textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 12.5px;
  resize: vertical;
  line-height: 1.4;
  word-break: break-all;
}
textarea[readonly] { background: var(--field-ro); }
select { padding-right: 28px; cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
textarea:focus, input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--focus); }

.btn {
  font: inherit;
  background: var(--btn);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent-press);
  color: #fff;
  font-weight: 600;
  padding: 9px 28px;
  min-width: 200px;
}
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.primary:active:not(:disabled) { background: var(--accent-press); }
.btn.busy::after {
  content: "";
  display: inline-block;
  width: 12px; height: 12px;
  margin-left: 8px;
  vertical-align: -2px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.action-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.action-row.two { display: grid; grid-template-columns: 1fr 1fr; }
.action-row.two .btn { width: 100%; }

.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.check input { margin: 0; accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; min-width: 0; }
.field > span:first-child { color: var(--text); }
.field input:not([type=checkbox]), .field select { font-weight: 400; width: 100%; }
.field .check { font-weight: 400; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field.inline input { flex: 1; }
.field.checks { justify-content: flex-end; gap: 6px; font-weight: 400; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }

.pass-field { display: flex; flex-direction: column; gap: 8px; }
.pass-field.inline { flex-direction: row; align-items: center; gap: 12px; flex-wrap: wrap; }
.pass-field.inline > input { flex: 0 1 320px; }
.pass-field .label { font-weight: 600; color: var(--accent); }

.file-drop {
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  padding: 18px;
  background: var(--field-ro);
}
.file-drop.dragover { border-color: var(--accent); }
.file-row { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; align-items: end; }
.file-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
input[type=file] { font: inherit; color: var(--text); max-width: 100%; }

table.subkeys { width: 100%; border-collapse: collapse; font-size: 13px; }
table.subkeys th, table.subkeys td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.subkeys th { color: var(--muted); font-weight: 600; }
table.subkeys td:last-child { text-align: right; width: 1%; }
table.subkeys .remove { padding: 1px 8px; }
table.subkeys .empty td { color: var(--muted); text-align: center; }

.badge { font-weight: 700; font-size: 12px; padding: 3px 10px; border-radius: 999px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.fail { background: var(--err-bg); color: var(--err); }

.status { margin: 0; min-height: 1.4em; color: var(--muted); white-space: pre-line; }
.status.ok { color: var(--ok); }
.status.error { color: var(--err); }
.hint { margin: 0; color: var(--muted); font-size: 13px; }

.app-footer { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 16px 14px; }

[hidden] { display: none !important; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-gen, .file-row { grid-template-columns: 1fr; }
  .subtitle { display: none; }
}
@media (max-width: 560px) {
  main { padding: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .btn.primary { width: 100%; min-width: 0; }
  .action-row.two { grid-template-columns: 1fr; }
  .app-header { padding: 8px 12px; }
}
