:root {
  --bg: #f4efe6;
  --paper: #fbf8f1;
  --ink: #1c1a18;
  --muted: #6f655d;
  --line: rgba(28, 26, 24, 0.12);
  --line-strong: rgba(28, 26, 24, 0.2);
  --accent: #af3e2d;
  --accent-deep: #7f2619;
  --accent-soft: rgba(175, 62, 45, 0.08);
  --olive: #44543d;
  --shadow: 0 18px 60px rgba(71, 49, 28, 0.12);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }
html, body { 
  margin: 0; 
  padding: 0;
  min-height: 100%; 
  height: 100%; 
  border: 0; 
  overflow-x: hidden;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(175, 62, 45, 0.16), transparent 28%),
    radial-gradient(circle at 90% 15%, rgba(68, 84, 61, 0.18), transparent 30%),
    linear-gradient(180deg, #f1eadf 0%, #f7f3eb 100%);
  background-attachment: fixed;
}

/* --- Layout Structure --- */

.shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.stage {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  background: transparent;
  display: flex;
  flex-direction: column;
}

.workspace-view {
  display: none;
  flex-direction: column;
  min-height: 100%;
  width: 100%;
  animation: fadeIn 0.4s ease;
}

.workspace-view.active {
  display: flex;
}

.workspace-header {
  width: 100%;
  height: 64px;
  padding: 0 40px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.02);
}

.workspace-content {
  flex: 1;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 24px 40px;
}

/* --- Login Screen --- */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: min(100%, 420px);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(251, 248, 241, 0.88);
  backdrop-filter: blur(24px);
  box-shadow: 0 40px 120px rgba(28, 26, 24, 0.15);
  animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- Components --- */

.panel {
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(251, 248, 241, 0.84);
  box-shadow: var(--shadow);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: #fff8f0;
  font-family: "Cormorant Garamond", serif;
  font-size: 26px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #df8762);
  box-shadow: 0 10px 28px rgba(175, 62, 45, 0.28);
}

.brand-mark.mini {
  width: 32px;
  height: 32px;
  font-size: 14px;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(175, 62, 45, 0.2);
}

.store-tabs-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  overflow: hidden;
  margin: 0 20px;
}

.store-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px;
}

.store-tab {
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.2s;
}

.store-tab:hover { background: var(--bg); }
.store-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(175, 62, 45, 0.2);
}

.add-tab-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-weight: 700;
  transition: all 0.2s;
}

.add-tab-btn:hover { background: var(--accent); color: #fff; }
.add-tab-btn small { display: none; } /* Hide the text on desktop for a cleaner look */

.user-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  font-size: 13px;
}

.user-meta span {
  font-weight: 700;
  color: var(--accent-deep);
}

.tabbar {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  background: rgba(28, 26, 24, 0.03);
  border-radius: 999px;
  margin-bottom: 24px;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.tab.active {
  background: var(--accent);
  color: #fff9f5;
  box-shadow: 0 4px 12px rgba(175, 62, 45, 0.2);
}

.tab-panel { display: none; width: 100%; }
.tab-panel.active { display: block; }

.knowledge-layout {
  display: grid;
  grid-template-columns: minmax(340px, 0.92fr) minmax(480px, 1.08fr);
  gap: 24px;
}

.member-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.member-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-radius: var(--radius-md);
  background: #fff;
  border: 1px solid var(--line);
  transition: all 0.2s;
}

.member-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.05); }

.tenant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.tenant-main-card {
  padding: 32px;
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tenant-main-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 48px rgba(0,0,0,0.06);
  border-color: var(--accent);
}

.tenant-main-card h4 {
  margin: 0;
  font-size: 22px;
  font-family: "Cormorant Garamond", serif;
  font-weight: 700;
}

.empty-card {
  padding: 60px;
  text-align: center;
  color: var(--muted);
  background: rgba(28, 26, 24, 0.02);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  font-size: 14px;
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head h3 {
  margin: 6px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

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

.meta-line {
  font-size: 13px;
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-bottom: 16px;
}

.knowledge-list {
  display: grid;
  gap: 12px;
}

.knowledge-item {
  width: 100%;
  border: 1px solid rgba(28, 26, 24, 0.12);
  border-radius: 18px;
  padding: 16px 18px;
  text-align: left;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.9), rgba(247, 241, 231, 0.92));
  box-shadow: 0 8px 22px rgba(71, 49, 28, 0.08);
  cursor: pointer;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease, background 0.22s ease;
}

.knowledge-item:hover {
  transform: translateY(-2px);
  border-color: rgba(175, 62, 45, 0.28);
  box-shadow: 0 14px 28px rgba(71, 49, 28, 0.12);
}

.knowledge-item.active {
  border-color: rgba(175, 62, 45, 0.5);
  background:
    linear-gradient(180deg, rgba(255, 246, 240, 0.98), rgba(251, 235, 226, 0.95));
  box-shadow: 0 18px 34px rgba(175, 62, 45, 0.16);
}

.knowledge-item.disabled {
  opacity: 0.72;
  background:
    linear-gradient(180deg, rgba(250, 248, 244, 0.92), rgba(242, 237, 230, 0.92));
}

.knowledge-item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.knowledge-item strong {
  font-size: 16px;
  line-height: 1.3;
}

.knowledge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.knowledge-status.enabled {
  background: rgba(68, 84, 61, 0.12);
  color: var(--olive);
}

.knowledge-status.disabled {
  background: rgba(111, 101, 93, 0.12);
  color: var(--muted);
}

.knowledge-item-desc {
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  opacity: 0.8;
}

.knowledge-keywords {
  color: var(--muted);
  font-size: 12px;
}

.editor-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-radius: 18px;
  border: 1px solid rgba(68, 84, 61, 0.18);
  background: rgba(68, 84, 61, 0.08);
}

.toggle-chip.disabled {
  border-color: rgba(111, 101, 93, 0.18);
  background: rgba(111, 101, 93, 0.08);
}

.toggle-chip-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toggle-chip-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.toggle-chip-state {
  font-size: 11px;
  font-weight: 700;
  color: var(--olive);
}

.toggle-chip.disabled .toggle-chip-state {
  color: var(--muted);
}

.toggle-control {
  position: relative;
  width: 48px;
  height: 28px;
  display: inline-flex;
  align-items: center;
}

.toggle-control input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}

.toggle-slider {
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: rgba(111, 101, 93, 0.35);
  position: relative;
  transition: background 0.22s ease;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.14);
  transition: transform 0.22s ease;
}

.toggle-control input:checked + .toggle-slider {
  background: linear-gradient(135deg, var(--olive), #6f8b5d);
}

.toggle-control input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.member-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.member-badge.tenant_admin { background: rgba(175, 62, 45, 0.1); color: var(--accent); }
.member-badge.tenant_staff { background: rgba(68, 84, 61, 0.1); color: var(--olive); }

/* --- Forms & Buttons --- */

.field { display: block; margin-bottom: 16px; }
.field span { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  background: rgba(255, 251, 244, 0.9);
  color: var(--ink);
  transition: border-color 0.2s;
}
input:focus, textarea:focus { outline: 0; border-color: var(--accent); }

.primary-btn {
  background: linear-gradient(135deg, var(--accent), #cf6d4f);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.ghost-btn {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.danger-btn {
  background: rgba(175, 62, 45, 0.1);
  color: var(--accent);
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.status-badge {
  padding: 6px 16px;
  background: var(--accent-deep);
  color: #fff;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(127, 38, 25, 0.3);
}

/* --- Responsive --- */

@media (max-width: 1100px) {
  .workspace-content { padding: 16px 20px; }
  .knowledge-layout { grid-template-columns: 1fr; }
  .workspace-header { padding: 0 20px; }
  .search-row { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .workspace-header { height: auto; flex-direction: column; padding: 16px; gap: 16px; }
  .user-meta { width: 100%; justify-content: space-between; }
}
