:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --surface: #ffffff;
  --text: #1f2937;
  --ink: var(--text);
  --muted: #6b7280;
  --border: #e5e7eb;
  --line: var(--border);
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: var(--primary);
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --bad: var(--danger);
  --available: #16a34a;
  --ok: var(--available);
  --surface-muted: #f3f4f6;
  --control-hover-bg: #f8fafc;
  --control-hover-border: #94a3b8;
  --shadow: rgba(15, 23, 42, 0.08);
  --input-bg: #fff;
  --input-text: var(--text);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151a17;
  --card: #1e2621;
  --surface: #1e2621;
  --text: #f0f3f1;
  --ink: var(--text);
  --muted: #c5cec7;
  --border: #4a554e;
  --line: var(--border);
  --primary: #a3b9a1;
  --primary-dark: #8da28b;
  --accent: var(--primary);
  --danger: #f08a8a;
  --bad: var(--danger);
  --available: #7ec489;
  --ok: var(--available);
  --surface-muted: #2a332e;
  --control-hover-bg: #313b35;
  --control-hover-border: #6f8174;
  --shadow: rgba(0, 0, 0, 0.45);
  --input-bg: #151a17;
  --input-text: #f0f3f1;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2 { margin: 0 0 0.5rem; color: var(--text); }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.05rem; }
p { margin: 0 0 0.75rem; color: var(--muted); }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

.topbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
  padding: 1.5rem 2rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar-title-row h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  flex-flow: row wrap;
  gap: 0.65rem 1rem;
  align-items: center;
  justify-content: flex-end;
}

.topbar-actions > .link-muted {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.35rem 0.15rem;
  color: var(--muted);
  line-height: 1.25;
}

.link-muted { color: var(--muted); }
.link-muted:hover,
.link-muted:focus-visible,
.link-muted.is-current { color: var(--primary); }
.link-muted.is-current { font-weight: 650; }

html[data-theme="dark"] .topbar-actions > .link-muted { color: var(--text); }
html[data-theme="dark"] .topbar-actions > .link-muted:hover,
html[data-theme="dark"] .topbar-actions > .link-muted.is-current { color: var(--primary); }

.topbar-nav-end {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-shrink: 0;
  margin-left: auto;
}

.logout-form { margin: 0; }
.logout-form button {
  display: inline;
  margin: 0;
  padding: 0.35rem 0.15rem;
  border: 0;
  background: none;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  min-height: 2.25rem;
}
.logout-form button:hover { background: none; color: var(--primary); }

button.lang-dropdown-toggle,
.lang-dropdown-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  line-height: 1.2;
}
button.lang-dropdown-toggle:hover,
.lang-dropdown.is-open .lang-dropdown-toggle {
  border-color: var(--control-hover-border);
  background: var(--control-hover-bg);
  color: var(--text);
}

.lang-dropdown { position: relative; display: inline-flex; align-items: center; }
.lang-flag { display: inline-flex; line-height: 0; }
.lang-flag img {
  display: block;
  width: 22px;
  height: auto;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.1);
  aspect-ratio: 3 / 2;
  object-fit: cover;
}
.lang-label { font-weight: 600; font-size: 0.875rem; }
.lang-chevron {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
}
.lang-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 50;
  min-width: 10rem;
  margin: 0;
  padding: 0.35rem;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px var(--shadow);
}
.lang-dropdown-menu[hidden] { display: none; }
.lang-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-radius: 0.35rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}
.lang-dropdown-item:hover,
.lang-dropdown-item.is-active { background: var(--surface-muted); color: var(--text); }
.lang-dropdown-item.is-active { font-weight: 600; }

button.night-mode-toggle,
.night-mode-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  max-width: 2.25rem;
  min-height: 2.25rem;
  max-height: 2.25rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--surface-muted);
  color: var(--text);
  cursor: pointer;
  flex: 0 0 2.25rem;
  line-height: 0;
}
button.night-mode-toggle:hover,
.night-mode-toggle:hover { background: var(--control-hover-bg); border-color: var(--control-hover-border); color: var(--text); }
.night-mode-icon { display: none; }
.night-mode-toggle .night-mode-icon--moon { display: inline-flex; }
.night-mode-toggle[aria-pressed="true"] .night-mode-icon--moon,
html[data-theme="dark"] .night-mode-toggle .night-mode-icon--moon { display: none; }
.night-mode-toggle[aria-pressed="true"] .night-mode-icon--sun,
html[data-theme="dark"] .night-mode-toggle .night-mode-icon--sun { display: inline-flex; }
.night-mode-icon svg { display: block; }

.auth-card {
  width: min(100%, 420px);
  margin: 2rem auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 2px var(--shadow);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}
body.admin-wide-page .container { max-width: min(100%, 1680px); }

form.deposit-form fieldset { margin: 0.9rem 0; }
.deposit-form .pair,
.deposit-form .checks { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; align-items: start; }
.deposit-form .modes { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; align-items: start; }
#wa-qr { min-height: 0; margin-top: 0.5rem; }
#wa-qr img, #wa-qr canvas { display: block; }
.deposit-form .limits { display: grid; grid-template-columns: repeat(3, minmax(8rem, 12rem)); gap: 0 1.25rem; }
.deposit-form .dates { display: grid; grid-template-columns: repeat(2, minmax(8rem, 12rem)); gap: 0 1.25rem; }
.deposit-form .span-all { grid-column: 1 / -1; }
@media (max-width: 760px) {
  .deposit-form .pair,
  .deposit-form .checks,
  .deposit-form .modes,
  .deposit-form .limits { grid-template-columns: 1fr; }
}
form.deposit-form .hint { display: block; margin-top: 0.25rem; font-weight: 450; }
form.deposit-form .hint[hidden],
form.deposit-form label[hidden] { display: none; }
.deposit-form .algo-note { min-height: 1.35rem; margin: 0; }
label.file .picker { display: flex; align-items: center; gap: 0.65rem; min-height: 2.5rem; }
label.file input[type="file"] { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.picker-btn { display: inline-flex; align-items: center; padding: 0.35rem 0.75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--input-bg); cursor: pointer; font-weight: 450; }
.picker-status { font-weight: 450; color: var(--muted, inherit); }
.measure { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.35rem 0.65rem; align-items: start; }
.measure > label.check { margin-top: 0.65rem; margin-bottom: 0.65rem; }
button.explain { margin: 0.7rem 0 0; white-space: nowrap; }
.secret-row { display: flex; gap: 0.4rem; align-items: center; }
.secret-row input { flex: 1; min-width: 0; }
button.tiny { padding: 0.45rem 0.7rem; font-size: 0.85rem; }
.guide-dialog {
  width: min(52rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem 1.25rem 1.25rem;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 16px 40px var(--shadow);
}
.guide-dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.guide-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.guide-head h2 { margin: 0; font-size: 1.15rem; }
#guide-body { overflow: auto; max-height: calc(100vh - 8rem); }
#share-extra { white-space: pre-wrap; }
.explain-table { margin: 0.35rem 0 0.8rem; }
.explain-table caption { caption-side: top; text-align: left; font-weight: 650; padding-bottom: 0.35rem; color: var(--text); }
label.check { display: flex; flex-direction: row; align-items: flex-start; gap: 0.55rem; font-weight: 450; }
label.check input { width: auto; margin-top: 0.2rem; }
label.check .check-title { display: block; }
label.check .hint { margin-top: 0.15rem; }

.card, .hero, .panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin: 0 0 1.25rem;
  box-shadow: 0 1px 2px var(--shadow);
}
.hero p { max-width: 42rem; }

.stack, .settings-form { display: flex; flex-direction: column; gap: 0.15rem; }
label { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.65rem 0; font-size: 0.95rem; color: var(--text); }
label.inline { flex-direction: row; align-items: center; font-weight: 450; }

input, select, textarea, button { font: inherit; color: var(--text); }
input[type="text"], input[type="tel"], input[type="password"], input[type="email"],
input[type="number"], input[type="date"], input[type="url"], input[type="datetime-local"],
input:not([type]), select, textarea {
  width: 100%;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--input-text);
}
textarea { resize: vertical; min-height: 4.5rem; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent);
  border-color: var(--primary);
}
label.inline input, label.inline select { width: auto; }

button, .button, .btn-primary {
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button:hover, .button:hover, .btn-primary:hover { background: var(--primary-dark); color: #fff; }
button.ghost, .button.ghost, .btn-secondary {
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
}
button.ghost:hover, .button.ghost:hover { background: var(--control-hover-bg); color: var(--text); }

.hint, .field-hint { color: var(--muted); font-size: 0.9rem; }
.flash { padding: 0.75rem 0.9rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: color-mix(in srgb, var(--available) 16%, var(--card)); color: var(--text); }
.flash.bad { background: color-mix(in srgb, var(--danger) 14%, var(--card)); color: var(--text); }
.row, .inline-form { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem; }

.tabs { display: flex; flex-wrap: wrap; gap: 0.65rem 1rem; margin: 0 0 1rem; }
.tabs a { color: var(--muted); min-height: 2.25rem; display: inline-flex; align-items: center; }
.tabs a.on, .tabs a:hover { color: var(--primary); }
.tabs a.on { font-weight: 650; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
}

.table-wrap, .admin-log-scroll-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 1.25rem;
}
.table-wrap table { min-width: 3200px; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td {
  text-align: left;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  color: var(--text);
}
th { font-size: 0.9rem; color: var(--muted); font-weight: 650; background: var(--card); }
html[data-theme="dark"] th { color: var(--muted); background: var(--card); }
html[data-theme="dark"] td { color: var(--text); }

.file-list { font-size: 0.92rem; color: var(--text); }
.code-big { font-size: 2rem; letter-spacing: 0.14em; font-weight: 700; color: var(--text); }
.viewer { width: 100%; min-height: 70vh; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.files { list-style: none; padding: 0; margin: 0; }
.files li { padding: 0.65rem 0; border-bottom: 1px solid var(--border); color: var(--text); }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 0.8rem 1rem; margin: 0.8rem 0; }
legend { padding: 0 0.35rem; color: var(--text); font-weight: 650; }

.captcha-field { margin: 0.8rem 0; }
.captcha-label { display: block; margin-bottom: 0.35rem; color: var(--text); }
.captcha-row { display: flex; gap: 0.65rem; align-items: center; margin-bottom: 0.45rem; }
button.captcha-refresh {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #e5e7eb;
  color: #1f2937;
  padding: 0.55rem 0.75rem;
  font: inherit;
  line-height: 1;
  cursor: pointer;
}
button.captcha-refresh:hover {
  background: #d1d5db;
  color: #111827;
}
html[data-theme="dark"] button.captcha-refresh {
  background: #e5e7eb;
  color: #1f2937;
  border-color: #9ca3af;
}
html[data-theme="dark"] button.captcha-refresh:hover {
  background: #d1d5db;
  color: #111827;
}
.captcha-image {
  display: block;
  height: 52px;
  width: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
}

@media (max-width: 720px) {
  .topbar { padding: 1rem; }
  .container { padding: 1rem; }
  .topbar-nav-end { margin-left: 0; }
}

.admin-technical-sections-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 1rem;
}

.admin-advanced-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px var(--shadow);
  scroll-margin-top: 1.25rem;
}

.admin-advanced-summary {
  list-style: none;
  cursor: pointer;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  user-select: none;
}

.admin-advanced-summary::-webkit-details-marker { display: none; }
.admin-advanced-summary::marker { content: ""; }

.admin-advanced-summary > *,
.admin-advanced-section > summary > * { pointer-events: none; }

.admin-advanced-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 650;
  color: var(--text);
}

.admin-advanced-title::before {
  content: "▸";
  display: inline-block;
  font-size: 0.9rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.admin-advanced-section[open] .admin-advanced-title::before { transform: rotate(90deg); }

.admin-advanced-hint {
  font-size: 0.95rem;
  color: var(--muted);
  line-height: 1.4;
  padding-left: 1.4rem;
}

.admin-advanced-content { padding: 0 1.25rem 1.25rem; }

.admin-advanced-content .settings-form {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  gap: 0.75rem;
}

.connect-host-row { display: flex; gap: 0.5rem; align-items: center; }
.connect-host-row input { flex: 1; min-width: 0; }
.connect-host-row button { flex: none; }
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  align-items: start;
}

.settings-grid > label,
.admin-advanced-content label { margin: 0; }

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.35rem;
}

.settings-actions > button[type="submit"]:last-child { margin-left: auto; }

.checkbox-label,
.radio-label {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.55rem;
  font-weight: 500;
  margin: 0.45rem 0;
}

.checkbox-label input,
.radio-label input {
  width: 1.1rem;
  height: 1.1rem;
  min-width: 1.1rem;
  margin: 0.15rem 0 0;
}

.radio-label .field-hint { display: block; }

.admin-advanced-content .field-hint { font-weight: 400; }

.admin-advanced-content code {
  font-size: 0.9rem;
  color: var(--text);
}

#webdav-auth-fields[hidden] { display: none; }

.level-preset-current-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.2;
}

.level-preset-current-badge--secure { background: #ecfdf5; color: #166534; border-color: #bbf7d0; }
.level-preset-current-badge--normal { background: #f8fafc; color: #334155; border-color: #cbd5e1; }
.level-preset-current-badge--weak { background: #fff1f2; color: #9f1239; border-color: #fecdd3; }

html[data-theme="dark"] .level-preset-current-badge--secure { background: rgba(22, 101, 52, 0.22); color: #86efac; border-color: rgba(134, 239, 172, 0.35); }
html[data-theme="dark"] .level-preset-current-badge--normal { background: rgba(51, 65, 85, 0.35); color: #cbd5e1; border-color: rgba(148, 163, 184, 0.35); }
html[data-theme="dark"] .level-preset-current-badge--weak { background: rgba(159, 18, 57, 0.22); color: #fda4af; border-color: rgba(253, 164, 175, 0.35); }

.security-level-fieldset .radio-label { align-items: flex-start; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.settings-subheading {
  margin: 0.25rem 0 0.65rem;
  font-size: 1.15rem;
  font-weight: 650;
  color: var(--text);
}

.settings-grid-wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.security-level-panel { padding: 1.35rem 1.4rem 1.2rem; }

.security-level-option {
  width: 100%;
  margin: 0;
  padding: 0.95rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
}

.security-level-option__label { display: flex; flex-direction: column; gap: 0.2rem; }
.security-level-summary { margin-top: 0.85rem; }
.security-level-summary summary { cursor: pointer; font-weight: 650; color: var(--text); }
.security-level-summary ul,
ul.security-level-summary { margin: 0.6rem 0 0; padding-left: 1.2rem; color: var(--text); }
.security-level-summary li { margin: 0.35rem 0; }

.level-warning {
  margin: 0 0 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: #fff1f2;
  color: #9f1239;
  border: 1px solid #fecdd3;
}

html[data-theme="dark"] .level-warning {
  background: rgba(159, 18, 57, 0.22);
  color: #fda4af;
  border-color: rgba(253, 164, 175, 0.35);
}

.rate-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem 1.1rem;
  background: var(--surface-muted);
}

.rate-block label { margin-top: 0.45rem; }

.journal-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.journal-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 5.5rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.journal-stat strong { font-size: 1.45rem; color: var(--text); line-height: 1.2; }

.log-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  align-items: end;
}

.log-filter-label { font-weight: 650; color: var(--text); }
.log-filter-span { grid-column: 1 / -1; }
.settings-input-wide { max-width: 28rem; }

.admin-advanced-content > .panel { margin-bottom: 0; }

ul.plain { list-style: none; padding: 0; margin: 0 0 1rem; }
ul.plain li { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }

@media (max-width: 480px) {
  .settings-actions > button[type="submit"]:last-child { margin-left: 0; }
}
