:root {
  --bg: #f1f4f7;
  --bg-card: #ffffff;
  --line: #d6dde5;
  --text: #18202b;
  --muted: #58697d;
  --primary: #0f5c86;
  --primary-2: #134867;
  --danger: #8b2f2f;
  --ok: #1f6b45;
  --shadow: 0 14px 28px rgba(18, 36, 53, 0.1);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: radial-gradient(1400px 700px at 7% -8%, #cde3f0 0%, transparent 60%),
              radial-gradient(1000px 500px at 100% 0%, #d8ead9 0%, transparent 55%),
              var(--bg);
}

h1, h2, h3 {
  margin: 0;
  line-height: 1.2;
}

h1, h2 {
  font-family: "Merriweather", serif;
}

p { margin: 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input, textarea, select, button {
  font: inherit;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 10px;
}

textarea {
  resize: vertical;
  min-height: 72px;
}

button {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.hidden { display: none !important; }
.full { width: 100%; }

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

.error {
  min-height: 18px;
  color: #b02121;
  font-size: 13px;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  pointer-events: none;
  opacity: 0.45;
}

.bg-shape-a {
  width: 460px;
  height: 460px;
  right: -130px;
  top: -120px;
  background: linear-gradient(140deg, #aacde0, #e2efe5);
  filter: blur(4px);
}

.bg-shape-b {
  width: 320px;
  height: 320px;
  left: -90px;
  bottom: -130px;
  background: linear-gradient(140deg, #b9d6c5, #d8e6f3);
}

.app-shell {
  position: relative;
  z-index: 2;
  max-width: 1600px;
  margin: 20px auto;
  padding: 12px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card {
  max-width: 520px;
  margin: 60px auto;
  padding: 24px;
  display: grid;
  gap: 16px;
  animation: fadeInUp 0.35s ease-out;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab {
  border: 1px solid var(--line);
  background: #f8fbfd;
}

.tab.is-active {
  background: #d7e8f2;
  border-color: #b8d1e2;
  color: #153a53;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.workspace {
  display: grid;
  gap: 12px;
}

.topbar {
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.layout-grid {
  display: grid;
  grid-template-columns: 330px minmax(280px, 1fr) minmax(360px, 1.2fr);
  gap: 12px;
}

.sidebar, .tree-panel, .editor-panel {
  padding: 14px;
  min-height: 580px;
}

.sidebar {
  overflow: auto;
  max-height: calc(100vh - 180px);
}

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

.editor-panel {
  overflow: auto;
  max-height: calc(100vh - 180px);
  display: grid;
  gap: 10px;
  align-content: start;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.sidebar-menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.sidebar-menu .btn {
  font-size: 12px;
  padding: 8px 8px;
}

.sidebar-menu .btn.is-active {
  background: #d7e8f2;
  border-color: #8fb6ce;
  color: #123b54;
}

.sidebar-menu .btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.crud-list {
  list-style: none;
  margin: 8px 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.crud-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #f9fcff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.crud-item.compact {
  padding: 6px 8px;
}

.crud-item .btn.is-active {
  background: #d7e8f2;
  border-color: #8fb6ce;
  color: #123b54;
}

.crud-meta {
  font-size: 12px;
  line-height: 1.4;
}

.crud-meta strong {
  font-size: 13px;
  color: #153a53;
}

.btn {
  background: #edf4f8;
  border-color: #c9d8e2;
  color: #193244;
}

.btn:hover {
  background: #ddeaf2;
}

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

.btn.primary:hover {
  background: var(--primary-2);
}

.btn.danger {
  background: #f7eaea;
  border-color: #e6c8c8;
  color: var(--danger);
}

.btn.mini {
  padding: 7px 10px;
  font-size: 12px;
}

.tree {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree ul {
  list-style: none;
  margin: 4px 0 4px 16px;
  padding: 0 0 0 8px;
  border-left: 1px dashed #d1dce4;
}

.tree-item {
  margin: 3px 0;
}

.tree-button {
  width: 100%;
  text-align: left;
  border: 1px solid #d7e0e8;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfdff;
  color: var(--text);
}

.tree-button:hover {
  background: #f0f6fb;
}

.tree-button.active {
  border-color: #6ea8cc;
  background: #d9edf9;
  color: #12394f;
}

.tree-item.drop-before > .tree-button {
  box-shadow: inset 0 3px 0 #2f7ca7;
}

.tree-item.drop-after > .tree-button {
  box-shadow: inset 0 -3px 0 #2f7ca7;
}

.tree-item.drop-child > .tree-button {
  outline: 2px dashed #1d7b58;
  background: #e6f5ee;
}

.stock-list {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.stock-list button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  font-size: 12px;
}

.image-preview-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #f8fbfd;
}

.image-preview-wrap img {
  margin-top: 8px;
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid #d6dde4;
  background: #fff;
}

.statusbar {
  padding: 12px;
  font-size: 13px;
  color: var(--muted);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1280px) {
  .layout-grid {
    grid-template-columns: 300px 1fr;
    grid-template-areas:
      "sidebar editor"
      "tree editor";
  }
  .sidebar { grid-area: sidebar; }
  .tree-panel { grid-area: tree; }
  .editor-panel { grid-area: editor; }
}

@media (max-width: 900px) {
  .app-shell {
    padding: 8px;
    margin: 12px auto;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .layout-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "sidebar"
      "tree"
      "editor";
  }

  .sidebar, .tree-panel, .editor-panel {
    max-height: none;
    min-height: auto;
  }
}
