:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #fff;
  --line: #dfe4ea;
  --nav: #101827;
  --nav-text: #cfd6e3;
  --text: #111827;
  --muted: #64748b;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}

* { box-sizing: border-box; }

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 188px;
  background: var(--nav);
  padding: 22px 14px;
  color: var(--nav-text);
}

.sidebar h1 {
  margin: 0 0 24px;
  color: #fff;
  font-size: 18px;
}

.sidebar a {
  display: block;
  padding: 12px 14px;
  border-radius: 7px;
  color: var(--nav-text);
  text-decoration: none;
  font-weight: 800;
}

.sidebar a.active,
.sidebar a:hover {
  background: #26344d;
  color: #fff;
}

.sidebar .agent-link {
  padding: 8px 14px 8px 24px;
  color: #ef4444;
  font-size: 13px;
}

.sidebar .agent-link.active {
  background: #26344d;
  color: #ff6b6b;
}

.main {
  min-height: 100vh;
  margin-left: 188px;
  padding: 24px;
}

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

h2 {
  margin: 0;
  font-size: 24px;
}

h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.cards div,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}

.cards div {
  padding: 20px;
}

.cards strong {
  display: block;
  font-size: 30px;
  line-height: 1;
  margin-bottom: 8px;
}

.cards span,
.muted {
  color: var(--muted);
  font-weight: 800;
}

.panel {
  padding: 18px;
  margin-bottom: 18px;
  overflow-x: auto;
}

.panel.narrow {
  max-width: 760px;
}

.panel-title,
.toolbar,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.panel-title h3 { margin: 0; }
.toolbar { margin-bottom: 16px; }

input,
select,
button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  font-weight: 800;
  font: inherit;
}

input,
select {
  background: #fff;
  color: var(--text);
}

button,
.button-link {
  display: inline-grid;
  place-items: center;
  min-width: 64px;
  height: 36px;
  border: 0;
  background: var(--blue);
  color: #fff;
  border-radius: 7px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 900;
}

.button-link.small,
button.small {
  min-width: 48px;
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.button-link.secondary {
  background: #eef2f7;
  color: var(--text);
  border: 1px solid var(--line);
}

button.secondary {
  background: #eef2f7;
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: pointer;
}

button:disabled {
  background: #eef2f7;
  color: var(--muted);
  border: 1px solid var(--line);
  cursor: not-allowed;
}

button.danger {
  background: var(--red);
}

.create {
  display: grid;
  grid-template-columns: 1.3fr .45fr .45fr 1.2fr 1fr auto;
  gap: 10px;
}

.search-row {
  display: flex;
  gap: 10px;
  flex: 1;
  min-width: min(620px, 100%);
}

.search-row input {
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
}

code {
  display: inline-block;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  background: #eef2f7;
  border-radius: 4px;
  padding: 3px 6px;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 900;
}

.badge.ok {
  background: #dcfce7;
  color: var(--green);
}

.badge.bad {
  background: #fee2e2;
  color: var(--red);
}

.badge.warn {
  background: #fef3c7;
  color: var(--amber);
}

td form {
  margin: 0;
}

.inline-edit {
  display: grid;
  grid-template-columns: 72px 180px minmax(160px, 1fr) auto;
  gap: 8px;
}

.proxy-create {
  grid-template-columns: 1fr 2fr .6fr 1.2fr auto;
}

.proxy-edit {
  display: grid;
  grid-template-columns: 1fr 2fr .6fr 1.2fr 140px auto auto;
  gap: 8px;
  align-items: center;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: -4px 0 14px;
}

.tabs a,
.filter-tabs a {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-weight: 900;
}

.tabs a.active,
.filter-tabs a.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.filter-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.agent-create,
.agent-edit,
.agent-code-create,
.agent-account-create {
  display: grid;
  gap: 10px;
  align-items: end;
}

.agent-create {
  grid-template-columns: 1fr 1fr 1.2fr 3fr auto;
}

.agent-edit {
  grid-template-columns: 1fr 1fr .8fr 2fr 2fr auto;
}

.agent-code-create {
  grid-template-columns: .6fr 1fr 1fr 4fr auto;
}

.agent-account-panel {
  max-width: 760px;
}

.agent-account-create {
  grid-template-columns: 1fr;
}

.agent-account-create button {
  width: 100%;
}

.agent-create label,
.agent-edit label,
.agent-code-create label,
.agent-account-create label,
.settings-form label,
.version-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.agent-create input,
.agent-edit input,
.agent-edit select,
.agent-code-create input,
.agent-account-create input {
  width: 100%;
}

.agent-account-table input {
  min-width: 150px;
}

.search-row.short {
  flex: 0 1 460px;
  min-width: 320px;
}

td input,
td select {
  max-width: 260px;
  width: 100%;
}

.proxy-edit + form {
  display: none;
}

.actions {
  justify-content: flex-start;
}

.settings-form,
.version-form {
  display: grid;
  gap: 12px;
}

.policy-form,
.log-filter-form {
  display: grid;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
}

.version-policy-form {
  grid-template-columns: repeat(4, minmax(110px, .55fr)) minmax(110px, .5fr) minmax(220px, 1.5fr) auto;
}

.policy-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.policy-form .policy-check,
.table-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  white-space: nowrap;
  font-weight: 900;
}

.policy-check input,
.table-check input {
  width: 17px;
  height: 17px;
  margin: 0;
}

.policy-table input[type="text"],
.policy-table input:not([type]) {
  min-width: 110px;
}

.policy-table td:nth-child(6) input {
  min-width: 220px;
}

.log-filter-form {
  grid-template-columns: repeat(3, minmax(150px, 1fr)) repeat(3, minmax(120px, .7fr)) auto auto;
}

.authorization-log-table code {
  max-width: 220px;
}

.translation-settings-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, .6fr)) auto;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
}

.translation-settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.translation-settings-form .dictionary-path-field {
  grid-column: 1 / -1;
}

.dictionary-location {
  margin: 14px 0 0;
  font-weight: 900;
}

.ok-text { color: var(--green); }
.warning-text { color: var(--amber); }

.dictionary-diagnostics {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 1px;
  margin: 16px 0;
  background: var(--line);
  border: 1px solid var(--line);
}

.dictionary-diagnostics div {
  min-width: 0;
  padding: 12px;
  background: #fff;
}

.dictionary-diagnostics dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.dictionary-diagnostics dd {
  margin: 0;
  font-weight: 800;
}

.dictionary-actions,
.dictionary-actions form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-form label,
.version-form label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-weight: 900;
}

.notice,
.error {
  padding: 12px;
  border-radius: 8px;
  font-weight: 900;
  margin-bottom: 18px;
}

.notice {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
}

.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--red);
}

.empty {
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login-card {
  width: 380px;
  display: grid;
  gap: 12px;
  background: #fff;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .16);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 36px;
}

.login-card p {
  margin: 0;
  color: var(--red);
  font-weight: 900;
}

.install {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px;
}

.install-card {
  width: min(720px, 100%);
  margin: 0;
  background: #fff;
  border-radius: 14px;
  padding: 34px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .14);
}

.install-card h1 {
  margin: 0 0 10px;
  font-size: 30px;
}

.install-card h2 {
  margin: 22px 0 10px;
  font-size: 17px;
}

.install-form {
  display: grid;
  gap: 10px;
}

.install-form label {
  display: grid;
  gap: 6px;
  color: #475569;
  font-weight: 900;
}

.install-form input {
  width: 100%;
}

.install-form button {
  margin-top: 12px;
  height: 42px;
}

textarea {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.announcement-form {
  display: grid;
  gap: 12px;
  max-width: 980px;
}

.announcement-form > label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.announcement-form > label input,
.announcement-form > label select {
  width: 100%;
}

.rich-editor-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.rich-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--line);
}

.rich-editor-toolbar button,
.rich-editor-toolbar select {
  min-width: 42px;
  height: 32px;
  padding: 0 8px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  cursor: pointer;
}

.rich-editor-toolbar input[type="color"] {
  width: 34px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.rich-editor {
  min-height: 300px;
  padding: 16px;
  color: var(--text);
  line-height: 1.7;
  outline: none;
  box-sizing: border-box;
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: #94a3b8;
  pointer-events: none;
}

.rich-editor img,
.rich-editor video {
  display: block;
  max-width: 100%;
  margin: 10px 0;
}

.announcement-editor-panel {
  overflow: visible;
}

@media (max-width: 900px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .version-policy-form,
  .log-filter-form,
  .translation-settings-form {
    grid-template-columns: 1fr;
  }

  .dictionary-diagnostics {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .main {
    margin-left: 0;
  }

  .cards {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .create,
  .inline-edit,
  .proxy-create,
  .proxy-edit,
  .agent-create,
  .agent-edit,
  .agent-code-create,
  .agent-account-create {
    grid-template-columns: 1fr;
  }
}
