:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #222222;
  --muted: #666666;
  --line: #cfd4dc;
  --header: #e9ecef;
  --accent: #2f5f8f;
  --accent-dark: #244a70;
  --danger: #9f1d1d;
  --success-bg: #edf7ed;
  --success-text: #245b24;
  --error-bg: #fbecec;
  --error-text: #8f1d1d;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 34px;
  border: 1px solid var(--accent-dark);
  border-radius: 3px;
  padding: 0 12px;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 6px 8px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  width: 100%;
  min-height: 430px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
  color: #9aa3ad;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.topbar h1,
.toolbar h2,
.detail-header h3 {
  margin: 0;
}

.topbar p,
.toolbar p,
.detail-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.detail-actions,
.table-toolbar,
.admin-toolbar-actions,
.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

main {
  width: min(1200px, calc(100vw - 24px));
  margin: 12px auto;
}

.workspace {
  padding: 0;
}

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.inline-form {
  min-width: 300px;
}

.inline-form input {
  min-width: 220px;
}

.inline-form button {
  flex: 0 0 auto;
  min-width: 64px;
}

.admin-toolbar-actions input {
  width: 180px;
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
  font-weight: 600;
}

.field span {
  color: #333333;
  font-size: 13px;
}

.variable-controls {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
}

.device-field {
  flex: 1 1 auto;
  margin-bottom: 0;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.table-toolbar {
  flex: 0 0 auto;
  justify-content: flex-end;
  margin-bottom: 0;
}

.editor-mode-toggle {
  display: flex;
  align-items: center;
  gap: 0;
}

.editor-mode-toggle button {
  border-color: #b8c0cc;
  border-radius: 0;
}

.editor-mode-toggle button:first-child {
  border-radius: 3px 0 0 3px;
}

.editor-mode-toggle button:last-child {
  border-left: 0;
  border-radius: 0 3px 3px 0;
}

.editor-mode-toggle button.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #ffffff;
}

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

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

th {
  background: var(--header);
  color: #333333;
  font-weight: 700;
  font-size: 13px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.dragging {
  opacity: 0.55;
  background: #eef3f8;
}

td input {
  border-color: #d7dce3;
  background: #ffffff;
}

td input:focus {
  background: #ffffff;
}

td input.input-error {
  border-color: #b42318;
  background: #fff7f7;
}

td input.duplicate-error {
  border-color: #8a5a00;
  background: var(--duplicate-color, #fff0c2);
}

td input.input-error:focus {
  outline-color: #b42318;
}

.plain-editor textarea.input-error {
  border-color: #b42318;
  background: #fff7f7;
}

.plain-editor textarea.input-error:focus {
  outline-color: #b42318;
}

.plain-error {
  min-height: 22px;
  margin-top: 6px;
  color: var(--error-text);
  font-size: 13px;
}

.row-index {
  width: 46px;
  color: var(--muted);
}

.drag-column {
  width: 42px;
  text-align: center;
}

.action-column {
  width: 58px;
}

.drag-handle-button {
  width: 30px;
  min-height: 28px;
  border-color: #b8c0cc;
  padding: 0;
  background: #f1f3f5;
  color: #444444;
  cursor: grab;
}

.drag-handle-button:hover {
  background: #e2e6ea;
}

.drag-handle-button:active {
  cursor: grabbing;
}

.remove-row-button {
  width: 34px;
  min-height: 30px;
  padding: 0;
}

.ghost-button,
.secondary-button {
  border-color: #b8c0cc;
  background: #f1f3f5;
  color: var(--text);
}

.ghost-button:hover,
.secondary-button:hover {
  background: #e2e6ea;
}

.danger-button {
  border-color: var(--danger);
  background: #ffffff;
  color: var(--danger);
}

.danger-button:hover {
  background: #fbecec;
}

.message {
  min-height: 24px;
  margin-top: 10px;
  color: var(--muted);
}

.message.success,
.message.error {
  border: 1px solid transparent;
  border-radius: 2px;
  padding: 8px 10px;
}

.message.success {
  background: var(--success-bg);
  border-color: #bfddbf;
  color: var(--success-text);
}

.message.error {
  background: var(--error-bg);
  border-color: #e9b7b7;
  color: var(--error-text);
}

.admin-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.list-panel,
.detail-panel {
  min-height: 460px;
}

.list-panel {
  border-right: 1px solid var(--line);
  padding-right: 12px;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.list-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}

.list-row.active {
  background: #eef3f8;
}

.favorite-button {
  min-height: auto;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  color: #777777;
  font-size: 18px;
}

.favorite-button:hover,
.favorite-button.active {
  background: transparent;
  color: #2f5f8f;
}

.list-item {
  width: 100%;
  min-height: auto;
  border: 0;
  border-radius: 0;
  padding: 9px 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.list-item:hover,
.list-row.active .list-item {
  border-color: var(--line);
  background: #eef3f8;
}

.list-item strong,
.list-item span {
  display: block;
}

.list-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.empty-state {
  display: grid;
  min-height: 360px;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  background: #ffffff;
}

.login-form {
  max-width: 380px;
  margin-top: 12px;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .topbar,
  .toolbar,
  .detail-header,
  .variable-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .inline-form,
  .admin-toolbar-actions,
  .detail-actions {
    width: 100%;
  }

  .inline-form {
    min-width: 0;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .table-toolbar {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .editor-mode-toggle {
    width: 100%;
  }

  .editor-mode-toggle button {
    flex: 1;
  }

  .table-toolbar button,
  .topbar-actions button,
  .detail-actions button {
    flex: 1;
  }
}
