:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafe;
  --primary: #0a6ed1;
  --primary-strong: #085cab;
  --primary-soft: #d9ebff;
  --accent: #00a58b;
  --warn: #d1495b;
  --text: #1f2d3d;
  --muted: #60758d;
  --border: #d6e0eb;
  --shadow: 0 8px 24px rgba(35, 73, 114, 0.12);
}

* {
  box-sizing: border-box;
  font-family: "Segoe UI", "Noto Sans", "Roboto", system-ui, sans-serif;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #edf3fa 0%, var(--bg) 100%);
  color: var(--text);
}

#app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 16px 18px;
}

.hidden {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 14px;
  background: linear-gradient(90deg, #0a6ed1 0%, #1783e1 72%, #2f95eb 100%);
  border: 1px solid #0a63c0;
  border-radius: 14px;
  box-shadow: var(--shadow);
  color: #fff;
  position: sticky;
  top: 10px;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.2px;
  font-weight: 700;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0;
}

.user-badge {
  font-size: 0.82rem;
  font-weight: 600;
  color: #edf5ff;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  padding: 6px 10px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(24, 59, 92, 0.08);
}

#loginSection {
  margin-top: 12px;
  max-width: 520px;
}

.layout {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 12px;
  min-height: calc(100vh - 118px);
}

.nav-panel {
  overflow: auto;
  max-height: calc(100vh - 130px);
}

.work-panel {
  overflow: auto;
}

label {
  display: block;
  margin: 10px 0;
  font-weight: 600;
  color: #35506c;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #c6d5e6;
  border-radius: 9px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 0.93rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid transparent;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10, 110, 209, 0.18);
}

button {
  background: var(--primary);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.2px;
  cursor: pointer;
  min-height: 36px;
  transition: background 120ms ease, transform 80ms ease, box-shadow 120ms ease;
}

button:hover:not(:disabled) {
  background: var(--primary-strong);
  box-shadow: 0 4px 14px rgba(10, 110, 209, 0.28);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

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

ul {
  list-style: none;
  padding-left: 0;
}

li {
  margin: 4px 0;
}

.menu-btn {
  width: 100%;
  text-align: left;
  background: linear-gradient(90deg, #f7fbff, #eef6ff);
  color: #17446f;
  border: 1px solid #cbddf0;
  border-radius: 9px;
  font-weight: 600;
}

.menu-btn:hover {
  background: linear-gradient(90deg, #e9f3ff, #dceeff);
  color: #103a61;
}

.muted {
  color: var(--muted);
}

pre,
code {
  background: #f4f8fe;
  border: 1px solid #d6e2ef;
  border-radius: 8px;
}

pre {
  padding: 8px;
  overflow: auto;
}

code {
  padding: 0 4px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 12px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

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

.record-workspace {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 10px;
}

.record-tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #dbe6f2;
}

.record-tab-item {
  display: inline-flex;
  align-items: center;
  border: 1px solid #bfd6ed;
  border-radius: 10px;
  background: #eef5fe;
  overflow: hidden;
}

.record-tab-btn {
  border-radius: 0;
  border: none;
  background: transparent;
  color: #1e466e;
  min-height: 30px;
  padding: 5px 10px;
  max-width: 260px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.record-tab-btn.active {
  background: #d7e9fc;
  color: #0b4f98;
}

.record-tab-close-btn {
  border: none;
  border-left: 1px solid #bfd6ed;
  background: transparent;
  color: #5e7690;
  min-height: 30px;
  min-width: 28px;
  padding: 0 8px;
  border-radius: 0;
}

.record-tab-close-btn:hover:not(:disabled) {
  background: #f7d7dc;
  color: #b13d4f;
  box-shadow: none;
}

.tab-btn {
  background: #e8f0fb;
  color: #1d446b;
  border: 1px solid #c7d9ec;
}

.tab-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.split {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 12px;
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
  border: 1px solid #d5e2ef;
  border-radius: 10px;
  overflow: hidden;
}

.grid th,
.grid td {
  border-bottom: 1px solid #e2ebf5;
  padding: 8px 7px;
  text-align: left;
}

.grid th {
  background: #f2f7fd;
  color: #34526f;
  font-weight: 700;
  position: sticky;
  top: 0;
}

.grid tr:nth-child(2n) td {
  background: #fbfdff;
}

.link-btn {
  background: transparent;
  color: var(--primary);
  border: none;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  min-height: auto;
}

.editor {
  position: sticky;
  top: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.danger {
  background: var(--warn);
}

.danger:hover:not(:disabled) {
  background: #b63d4d;
}

details {
  margin-top: 8px;
  border: 1px solid #d4e1ee;
  border-radius: 8px;
  padding: 6px 8px;
  background: #fdfefe;
}

details summary {
  cursor: pointer;
  font-weight: 600;
}

.admin-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 8px;
}

.admin-lists {
  margin-top: 10px;
}

.rule-helpers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.rule-builder {
  margin-top: 8px;
}

.builder-row {
  display: grid;
  grid-template-columns: 1fr 120px 1fr auto;
  gap: 6px;
  margin-top: 6px;
}

.builder-row:nth-child(3) {
  grid-template-columns: auto auto auto;
}

.small-btn {
  padding: 4px 8px;
  min-height: 30px;
  font-size: 0.78rem;
  background: #dbeafe;
  color: #184a7b;
  border-color: #bfd8f2;
}

.small-btn:hover:not(:disabled) {
  background: #cbe2fb;
  box-shadow: none;
}

.fk-editor {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.fk-editor select {
  grid-column: 1 / -1;
}

.fk-search-input {
  margin-top: 4px;
}

.danger-text {
  color: #c5384b;
}

.rule-preview-context {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

.snippet-box {
  margin-top: 8px;
  border: 1px dashed #9fc0df;
  border-radius: 8px;
  padding: 8px;
  background: #fafdff;
}

@media (max-width: 1150px) {
  .split {
    grid-template-columns: 1fr;
  }

  .editor {
    position: static;
  }
}

@media (max-width: 980px) {
  #app {
    padding: 10px;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .nav-panel {
    position: fixed;
    left: 0;
    top: 72px;
    bottom: 0;
    width: min(86vw, 340px);
    transform: translateX(-110%);
    transition: transform 180ms ease;
    z-index: 30;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    box-shadow: 0 10px 30px rgba(17, 58, 95, 0.3);
  }

  .layout.menu-open .nav-panel {
    transform: translateX(0);
  }

  .work-panel {
    min-width: 0;
  }

  .toolbar {
    padding: 8px 6px;
  }

  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions button {
    flex: 1 1 auto;
  }

  .grid {
    font-size: 0.83rem;
  }

  .grid th,
  .grid td {
    padding: 7px 6px;
  }
}

@media (max-width: 640px) {
  .topbar {
    border-radius: 10px;
    padding: 6px 8px;
    min-height: 50px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .user-badge {
    font-size: 0.74rem;
    padding: 4px 8px;
    max-width: 50vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .card {
    padding: 10px;
    border-radius: 10px;
  }

  .tabs {
    width: 100%;
  }

  .tab-btn {
    flex: 1 1 calc(50% - 6px);
  }

  .builder-row,
  .builder-row:nth-child(3),
  .rule-preview-context {
    grid-template-columns: 1fr;
  }
}
