:root {
  --maroon: #3d1a15;
  --maroon-2: #4a2118;
  --maroon-light: #6b3226;
  --gold: #c9973d;
  --gold-light: #e3b768;
  --terracotta: #c1652f;
  --teal: #2a7d72;
  --mustard: #d4a017;
  --bg: #faf6f0;
  --card: #ffffff;
  --border: #ede2d3;
  --text: #241210;
  --text-dim: #6b5a52;
  --text-faint: #a4938a;
  --green: #2f8f5b;
  --red: #b8443a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(61,26,21,0.05), 0 4px 16px rgba(61,26,21,0.07);
  --shadow-lg: 0 8px 30px rgba(61,26,21,0.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ============ APP SHELL ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: linear-gradient(180deg, var(--maroon-2) 0%, var(--maroon) 100%);
  color: #f4e9dc; display: flex; flex-direction: column; padding: 20px 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 20px 20px 20px; border-bottom: 1px solid rgba(244,233,220,0.12); }
.brand img { width: 38px; height: 38px; border-radius: 8px; object-fit: cover; background: #fff; }
.brand-name { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 15px; color: #fff; }
.brand-sub { font-size: 10.5px; color: var(--gold-light); letter-spacing: 0.5px; }

.nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; color: #c8a98f; font-weight: 700; margin: 16px 10px 6px 10px; }
.nav-section:first-child { margin-top: 0; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #f0e2d3;
  text-decoration: none; font-size: 13px; font-weight: 500; transition: background 0.15s;
}
.nav-link:hover { background: rgba(244,233,220,0.08); }
.nav-link.active { background: linear-gradient(135deg, var(--gold), #a97b2e); color: #2a1410; font-weight: 700; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }

.sidebar-footer { padding: 14px 20px 0 20px; border-top: 1px solid rgba(244,233,220,0.12); margin-top: 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 18px 28px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--maroon); }
#view-title { margin: 0; font-size: 19px; font-weight: 800; }
.live-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); margin-right: 6px; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.content { padding: 26px 28px 60px 28px; max-width: 1400px; perspective: 1400px; }
.content.view-enter { animation: viewEnter 0.5s cubic-bezier(0.16,1,0.3,1); }
@keyframes viewEnter {
  from { opacity: 0; transform: rotateX(6deg) translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: rotateX(0) translateY(0) scale(1); }
}

/* ============ STAT CARDS ============ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
  border: 1px solid var(--border); position: relative; overflow: hidden; transform-style: preserve-3d;
  transition: transform 0.25s cubic-bezier(0.16,1,0.3,1), box-shadow 0.25s; will-change: transform;
}
.stat-card:hover { box-shadow: 0 22px 40px -12px rgba(61,26,21,0.22); z-index: 2; }
.stat-card::before { content: ''; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: var(--accent, var(--gold)); }
.stat-label { font-size: 11px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 27px; font-weight: 800; margin-top: 6px; letter-spacing: -0.5px; }
.stat-sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

/* ============ PANEL ============ */
.panel {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 22px 24px; margin-bottom: 22px; transition: transform 0.25s cubic-bezier(0.16,1,0.3,1), box-shadow 0.25s;
}
.panel:hover { box-shadow: 0 20px 44px -16px rgba(61,26,21,0.18); }
.panel-title { font-size: 15px; font-weight: 700; margin: 0 0 4px 0; }
.panel-sub { font-size: 12.5px; color: var(--text-dim); margin: 0 0 16px 0; }

.grid-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; }
.grid-2-even { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ============ TABLE ============ */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left; padding: 10px 14px; background: #fbf2e7; color: var(--maroon); font-weight: 700;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; border-bottom: 2px solid var(--border);
}
table.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
table.data-table tbody tr:hover { background: #fdf8f1; }
table.data-table tbody tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-green { background: #e2f4e9; color: var(--green); }
.badge-red { background: #fbe6e3; color: var(--red); }
.badge-gold { background: #fbeed2; color: #8a6216; }
.badge-blue { background: #e2f0ef; color: var(--teal); }
.badge-grey { background: #f0ece7; color: var(--text-dim); }

/* ============ FORM CONTROLS ============ */
.controls-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.input, .select {
  padding: 9px 13px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px; font-family: inherit;
  background: #fff; color: var(--text); outline: none; transition: border-color 0.15s;
}
.input { flex: 1; min-width: 200px; }
.input:focus, .select:focus { border-color: var(--gold); }
.pagination { display: flex; align-items: center; gap: 10px; margin-top: 16px; font-size: 12.5px; color: var(--text-dim); }
.btn {
  border: 1px solid var(--border); background: #fff; border-radius: 7px; padding: 6px 12px; font-size: 12.5px;
  font-weight: 600; cursor: pointer; color: var(--text); transition: all 0.15s;
}
.btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-gold {
  border: none; background: linear-gradient(135deg, var(--gold-light), var(--gold)); color: #2a1410;
  border-radius: 8px; padding: 10px 18px; font-size: 13px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 16px rgba(201,151,61,0.3); transition: transform 0.15s, box-shadow 0.15s;
}
.btn-gold:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(201,151,61,0.4); }
.btn-gold:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 360px; }
.empty-note { color: var(--text-faint); font-size: 13px; padding: 30px; text-align: center; }
.loading-row td { text-align: center; color: var(--text-faint); padding: 24px; }
.section-hidden { display: none; }

/* ============ FABRIC CARDS (catalogue + 3D scene panel) ============ */
.fabric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.fabric-card {
  background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border);
  box-shadow: var(--shadow); transition: transform 0.2s, box-shadow 0.2s; cursor: pointer;
}
.fabric-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.fabric-card .thumb { width: 100%; aspect-ratio: 1; object-fit: cover; background: linear-gradient(135deg, #f0e2d3, #e3cba8); display: block; }
.fabric-card .thumb-default { object-fit: contain; background: #fff; padding: 14px; }
.fabric-card .thumb-wrap { position: relative; cursor: pointer; }
.fabric-card .photo-count-badge {
  position: absolute; bottom: 8px; right: 8px; background: rgba(23,10,8,0.72); color: #f4e9dc;
  font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 20px;
}
.sold-out-ribbon {
  position: absolute; top: 10px; left: -6px; background: var(--red); color: #fff; font-size: 10.5px;
  font-weight: 800; text-transform: uppercase; letter-spacing: 0.4px; padding: 4px 12px 4px 14px;
  border-radius: 0 4px 4px 0; box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.fabric-card .body { padding: 12px 14px; }
.fabric-card .name { font-size: 12.5px; font-weight: 700; line-height: 1.3; }
.fabric-card .meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }
.fabric-card .price { font-size: 13px; font-weight: 800; color: var(--terracotta); margin-top: 6px; }

.fabric3d-frame {
  width: 100%; height: 460px; border-radius: var(--radius); overflow: hidden; position: relative;
  background: radial-gradient(ellipse at 50% 30%, #4a2118 0%, #2a1410 60%, #170a08 100%);
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.fabric3d-frame canvas { display: block; width: 100%; height: 100%; }
.fabric3d-hint { position: absolute; bottom: 12px; left: 14px; color: #e3cba8; font-size: 11px; opacity: 0.8; }

/* ============ OWNER ACCESS BUTTON + NOTIFICATIONS ============ */
.ceo-panel-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 2px;
  background: rgba(201,151,61,0.12); border: 1px solid rgba(201,151,61,0.35); border-radius: 8px;
  padding: 7px 10px; cursor: pointer; transition: background 0.15s;
}
.ceo-panel-btn:hover { background: rgba(201,151,61,0.22); }
.ceo-panel-btn img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; background: #fff; flex-shrink: 0; }
.ceo-panel-btn span { font-size: 11px; font-weight: 700; color: var(--gold-light); letter-spacing: 0.3px; }

.notif-bell {
  position: relative; background: none; border: none; font-size: 18px; cursor: pointer; color: var(--maroon);
  line-height: 1; padding: 4px;
}
.notif-badge {
  position: absolute; top: -2px; right: -2px; background: var(--red); color: #fff; border-radius: 50%;
  min-width: 16px; height: 16px; font-size: 9.5px; font-weight: 800; display: flex; align-items: center;
  justify-content: center; padding: 0 3px;
}
.notif-badge[hidden] { display: none; }
.notif-dropdown {
  position: fixed; top: 58px; right: 24px; width: 100%; max-width: 340px; max-height: 70vh; overflow-y: auto;
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); z-index: 65;
}
.notif-dropdown-section { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.notif-dropdown-section:last-child { border-bottom: none; }
.notif-dropdown-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); margin-bottom: 6px; }
.notif-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.notif-item:last-child { border-bottom: none; }
.notif-item .meta { font-size: 10.5px; color: var(--text-faint); margin-top: 2px; }
.notif-empty { color: var(--text-faint); font-size: 12px; padding: 6px 0; }

/* ============ OWNER CONTROL CENTER (CEO panel) ============ */
.ceo-gate-card {
  position: relative; background: #fff; border-radius: 16px; padding: 30px 28px; width: 100%; max-width: 340px; text-align: center;
  box-shadow: 0 24px 60px rgba(23,10,8,0.35);
}
.ceo-gate-logo { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; margin-bottom: 12px; border: 3px solid var(--gold); }
.ceo-gate-card h3 { margin: 0 0 6px 0; color: var(--maroon); font-family: 'Sora', sans-serif; }
.ceo-gate-card p { font-size: 12.5px; color: var(--text-dim); margin: 0 0 16px 0; }
.ceo-gate-actions { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }

.ceo-panel-card {
  background: #fff; border-radius: 16px; width: 100%; max-width: 760px; max-height: 88vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 70px rgba(23,10,8,0.4); overflow: hidden;
}
.ceo-panel-header {
  display: flex; align-items: center; gap: 12px; padding: 18px 22px; background: var(--maroon); color: #fff; flex-shrink: 0;
}
.ceo-panel-header img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #fff; border: 2px solid var(--gold); }
.ceo-panel-header h3 { margin: 0; font-family: 'Sora', sans-serif; font-size: 16px; }
.ceo-panel-header p { margin: 2px 0 0 0; font-size: 11.5px; color: var(--gold-light); }
.ceo-panel-header .btn { margin-left: auto; background: rgba(244,233,220,0.12); border-color: rgba(244,233,220,0.3); color: #f0e2d3; }
.ceo-tabs { display: flex; gap: 4px; padding: 10px 16px 0 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; overflow-x: auto; }
.ceo-tab {
  background: none; border: none; padding: 8px 12px; font-size: 12px; font-weight: 700; color: var(--text-dim);
  cursor: pointer; border-radius: 8px 8px 0 0; white-space: nowrap;
}
.ceo-tab.active { color: var(--maroon); background: #fbf2e7; }
.ceo-tab-body { padding: 18px 22px; overflow-y: auto; flex: 1; }
.ceo-stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ceo-stat { background: #fbf2e7; border-radius: 10px; padding: 12px 14px; }
.ceo-stat .n { font-size: 20px; font-weight: 800; color: var(--maroon); }
.ceo-stat .l { font-size: 10.5px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; }
.ceo-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.ceo-row:last-child { border-bottom: none; }
.ceo-row .sub { font-size: 11px; color: var(--text-faint); }

@media (max-width: 900px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 30; height: 100vh;
    transform: translateX(-100%); transition: transform 0.22s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(36,18,16,0.4); z-index: 25; }
  .content { padding: 18px 16px 50px 16px; }
  .topbar { padding: 16px 18px; }
  .grid-2, .grid-2-even { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .topbar-status { display: none; }
  #view-title { font-size: 16px; }
  .topbar-right { gap: 10px; }
  .controls-row { flex-direction: column; align-items: stretch; }
  .controls-row .input, .controls-row .select, .controls-row button { width: 100%; }
}

/* ============ LOADING SKELETONS ============ */
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #f7f0e6 37%, var(--border) 63%);
  background-size: 400% 100%; animation: skeleton-shimmer 1.4s ease infinite;
}
@keyframes skeleton-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
