:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-opaque: #ffffff;
  --panel-2: #f6f8fb;
  --text: #111827;
  --muted: rgba(17, 24, 39, 0.65);
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --border: rgba(17, 24, 39, 0.12);
  --shadow: 0 10px 22px rgba(15, 23, 42, 0.08);

  --input-bg: #ffffff;
  --input-border: rgba(17, 24, 39, 0.18);
  --focus-ring: rgba(37, 99, 235, 0.18);

  --sidebar-bg: #2f343a;
  --sidebar-border: rgba(255, 255, 255, 0.10);
  --sidebar-text: rgba(255, 255, 255, 0.92);
  --sidebar-muted: rgba(255, 255, 255, 0.72);
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 255, 255, 0.14);

  --topbar-bg: rgba(255, 255, 255, 0.92);
  --topbar-border: rgba(17, 24, 39, 0.10);

  --btn-border: rgba(0,0,0,0.08);
  --btn-secondary-bg: rgba(0,0,0,0.04);
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --panel: rgba(20, 25, 35, 0.96);
  --panel-opaque: rgb(20, 25, 35);
  --panel-2: rgba(20, 25, 35, 0.72);
  --text: #e5e7eb;
  --muted: rgba(229, 231, 235, 0.72);
  --accent: #60a5fa;
  --accent-2: #3b82f6;
  --danger: #ff4d4d;
  --ok: #28d17c;
  --border: rgba(255,255,255,0.12);
  --shadow: 0 20px 60px rgba(0,0,0,0.45);

  --input-bg: rgba(0,0,0,0.20);
  --input-border: rgba(255,255,255,0.14);
  --focus-ring: rgba(96, 165, 250, 0.22);

  --sidebar-bg: #0f172a;
  --sidebar-border: rgba(255, 255, 255, 0.10);
  --sidebar-text: rgba(255, 255, 255, 0.92);
  --sidebar-muted: rgba(255, 255, 255, 0.72);
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 255, 255, 0.12);

  --topbar-bg: rgba(15, 23, 42, 0.74);
  --topbar-border: rgba(255,255,255,0.10);

  --btn-border: rgba(255,255,255,0.14);
  --btn-secondary-bg: rgba(255,255,255,0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  transition: width 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: width;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 900;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.brand-mark {
  width: auto;
  height: auto;
  border-radius: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  box-shadow: none;
  flex: 0 0 auto;
}

.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  display: block;
}

.brand-text {
  max-width: 180px;
  transition: opacity 180ms ease, transform 180ms ease, max-width 220ms ease;
  overflow: hidden;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-text);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--sidebar-hover);
}

.sidebar-nav {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 160ms ease, transform 160ms ease;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  transform: translateY(-1px);
}

.sidebar-nav a.active {
  background: var(--sidebar-active);
  border-color: rgba(255,255,255,0.10);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--sidebar-text);
}

.nav-label {
  display: inline-block;
  max-width: 220px;
  font-size: 14px;
  line-height: 1.1;
  transition: opacity 180ms ease, transform 180ms ease, max-width 220ms ease;
  overflow: hidden;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.sidebar-footer .pill {
  border-color: rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text);
}

.sidebar-action {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--sidebar-text);
  text-decoration: none;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.sidebar-action:hover {
  background: var(--sidebar-hover);
  transform: translateY(-1px);
}

body.sidebar-collapsed .sidebar-action {
  padding: 10px;
  justify-content: center;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--topbar-border);
  padding: 12px 18px;
  transition: background 240ms ease, border-color 240ms ease;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar .icon-btn {
  border-color: var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
}

.topbar .icon-btn:hover {
  background: rgba(0,0,0,0.04);
}

:root[data-theme="dark"] .topbar .icon-btn:hover {
  background: rgba(255,255,255,0.06);
}

.topbar-title {
  font-weight: 800;
  letter-spacing: 0.2px;
}

body.sidebar-collapsed .sidebar {
  width: 70px;
}

body.sidebar-collapsed .nav-label {
  opacity: 0;
  transform: translateX(-6px);
  pointer-events: none;
  max-width: 0;
}

body.sidebar-collapsed .sidebar-nav a {
  justify-content: center;
  padding: 10px;
  gap: 0;
}

body.sidebar-collapsed .sidebar-footer {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-brand {
  gap: 0;
}

body.sidebar-collapsed .brand-text {
  opacity: 0;
  transform: translateX(-6px);
  pointer-events: none;
  max-width: 0;
}

body.sidebar-collapsed .pill.nav-label {
  display: none;
}

.page-content {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

body.page-loaded .page-content {
  opacity: 1;
  transform: translateY(0);
}

body.page-leaving .page-content {
  opacity: 0;
  transform: translateY(8px);
}

@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .sidebar-nav a,
  .sidebar-action,
  .topbar,
  .brand-text,
  .nav-label,
  .page-content {
    transition: none !important;
  }
}

.container {
  max-width: none;
  margin: 0;
  padding: 18px 22px 48px;
}

.panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 26px 18px;
  overflow: auto;
  z-index: 200;
}

.modal {
  width: min(980px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.h1 {
  margin: 0 0 12px;
  font-size: 22px;
  letter-spacing: 0.4px;
}

.h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.sub {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 6px;
}

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

.field { flex: 1 1 260px; display: flex; flex-direction: column; gap: 6px; }

.filters-grid {
  display: flex;
  gap: 12px;
  flex-wrap: nowrap;
}

.filters-grid .field {
  flex: 1 1 0;
  min-width: 0;
}

.filters-grid select {
  width: 100%;
}

label { color: var(--muted); font-size: 13px; }

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

input, select, textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

button {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--btn-border);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  background: var(--btn-secondary-bg);
  border: 1px solid var(--border);
  color: var(--text);
}

.badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.03);
  font-size: 12px;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.03);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.status {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.02);
}

.status.ok { border-color: rgba(40, 209, 124, 0.4); }
.status.err { border-color: rgba(255, 77, 77, 0.4); }

.table-wrap {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: auto;
  background: rgba(0,0,0,0.01);
}

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

table.table th,
table.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.table th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(0,0,0,0.02);
}

table.table tbody tr:hover {
  background: rgba(37, 99, 235, 0.08);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.tile {
  display: block;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 14px;
  text-decoration: none;
  color: var(--text);
  transition: transform 120ms ease, border-color 120ms ease;
}

.tile:hover {
  transform: translateY(-1px);
  border-color: rgba(37, 99, 235, 0.35);
}

.tile-title {
  font-weight: 900;
  letter-spacing: 0.3px;
}

.tile-sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.id-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(0,0,0,0.02);
  padding: 12px;
  overflow: auto;
}

.id-canvas {
  width: 506px;
  height: 319px;
  position: relative;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.18);
  background: #ffffff;
  overflow: hidden;
  box-shadow: var(--shadow);
}

:root[data-theme="dark"] .id-canvas {
  border-color: rgba(255,255,255,0.16);
}

.id-el {
  position: absolute;
  user-select: none;
  cursor: move;
}

.id-el.selected {
  outline: 2px dashed rgba(37, 99, 235, 0.75);
  outline-offset: 2px;
}

.id-el-photo {
  border: 1px solid rgba(0,0,0,0.18);
  background: rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

:root[data-theme="dark"] .id-el-photo {
  border-color: rgba(255,255,255,0.16);
  background: rgba(255,255,255,0.06);
}

.id-el-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.id-palette {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.id-palette button {
  width: 100%;
}

@media (max-width: 1100px) {
  .id-editor-shell {
    grid-template-columns: 1fr;
  }

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