:root {
  --accent: #4f46e5;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-hover: color-mix(in srgb, var(--accent) 88%, #000000);
  --bg: #f8fafc;
  --card: #ffffff;
  --card-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  --radius-sm: 9px;
  --font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-scale: 1;
}

[data-surface="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --card-alt: #273549;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
}

[data-surface="midnight"] {
  --bg: #070b14;
  --card: #111827;
  --card-alt: #1f2937;
  --text: #f9fafb;
  --text-muted: #9ca3af;
  --border: #263142;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.55);
}

[data-surface="warm"] {
  --bg: #faf7f2;
  --card: #ffffff;
  --card-alt: #f3ede3;
  --text: #1c1917;
  --text-muted: #78716c;
  --border: #e7e0d5;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-family);
  font-size: calc(14px * var(--font-scale));
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.boot-loader {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.boot-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 20px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
}
.boot-label { color: var(--text-muted); font-weight: 600; }

/* Auth Shell */
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 18% 12%, var(--accent-soft), transparent 45%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow-md);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.auth-brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--card-alt);
  padding: 4px;
  border-radius: 11px;
  margin-bottom: 16px;
}
.auth-tab {
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text-muted);
}
.auth-tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Main Workspace Shell */
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}
.sidebar {
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}
.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-title { font-weight: 800; font-size: 1.02rem; line-height: 1.2; }
.brand-sub { font-size: 0.75rem; color: var(--text-muted); }

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-item {
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 600;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-item:hover { background: var(--card-alt); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.nav-count {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--card-alt);
  color: var(--text-muted);
}
.nav-item.active .nav-count {
  background: var(--accent);
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.tenant-chip {
  background: var(--card-alt);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 0.78rem;
}
.tenant-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tenant-role { color: var(--text-muted); font-size: 0.72rem; }

.main-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-size: 1.15rem; font-weight: 800; margin: 0; }
.topbar-sub { font-size: 0.8rem; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.workspace {
  padding: 18px 22px 44px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
}

/* Controls & Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.14s ease, background 0.14s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); background: var(--card-alt); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.btn-danger {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.35);
}
.btn-danger:hover { background: rgba(220, 38, 38, 0.08); border-color: #dc2626; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; border-radius: 7px; }
.btn-icon { padding: 6px 8px; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { resize: vertical; min-height: 92px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field-label { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* Cards & Toolbars */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.search-box { flex: 1 1 240px; min-width: 190px; }
.segmented {
  display: inline-flex;
  background: var(--card-alt);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 5px 11px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
  color: var(--text-muted);
}
.segmented button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.chip-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Inventory-Style Table */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-sm);
}
.studio-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}
.studio-table th {
  text-align: left;
  padding: 11px 12px;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--card-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.studio-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.studio-table tbody tr:hover { background: var(--accent-soft); }
.studio-table tbody tr:last-child td { border-bottom: 0; }

.status-select {
  border: 0;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 0.78rem;
  color: #fff;
  cursor: pointer;
  outline: none;
}

.inline-select {
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--card);
  max-width: 170px;
  font-size: 0.82rem;
}

.tag-row { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-pill {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.73rem;
  font-weight: 700;
}
.source-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--card-alt);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Inventory-Style Grid */
.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 14px;
}
.grid-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.grid-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.grid-thumb {
  height: 156px;
  background: var(--card-alt);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}
.grid-thumb img { width: 100%; height: 100%; object-fit: cover; }
.grid-thumb-placeholder {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.grid-thumb-badge {
  position: absolute;
  top: 8px;
  left: 8px;
}
.grid-thumb-source {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
}
.grid-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.grid-title { font-weight: 800; font-size: 0.96rem; cursor: pointer; }
.grid-summary {
  color: var(--text-muted);
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.grid-foot {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

/* Org Map */
.org-tree {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.org-node-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.org-children {
  margin-left: 26px;
  padding-left: 16px;
  border-left: 2px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

/* Tasks Board */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 14px;
}
.kanban-col {
  background: var(--card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 800;
  font-size: 0.9rem;
}

/* Modals & Toasts */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 60;
}
.modal {
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-wide { max-width: 880px; }
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-title { margin: 0; font-size: 1.08rem; font-weight: 800; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}
.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.86rem;
  box-shadow: var(--shadow-md);
}
.toast.error { background: #b91c1c; }

.empty-state {
  text-align: center;
  padding: 46px 18px;
  color: var(--text-muted);
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.wa-drawer {
  margin-bottom: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 10px;
}
.swatch-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  background: var(--card);
  text-align: left;
}
.swatch-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 12px;
  }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
  .nav-item { width: auto; }
  .sidebar-foot { display: none; }
  .form-grid-2, .form-grid-3, .kanban { grid-template-columns: 1fr; }
}
