:root {
  --sidebar-width: 246px;
  --sidebar-collapsed: 76px;
  --saas-bg: #f4f3f1;
  --saas-blue: #315b9a;
}

body {
  min-width: 0;
  background: var(--saas-bg);
}

body:not(.authenticated) .saas-sidebar {
  display: none;
}

.tailor-view .tailor-hide {
  display: none !important;
}

.saas-sidebar {
  position: fixed;
  z-index: 35;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  padding: 18px 12px;
  flex-direction: column;
  color: #f8f2eb;
  background: #2e2023;
  box-shadow: 8px 0 32px rgba(43, 30, 32, .08);
  transition: width .22s ease, transform .22s ease;
}

.sidebar-brand {
  position: relative;
  min-height: 62px;
  padding: 8px 44px 16px 12px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-brand span {
  display: block;
  font: 600 24px/1 Georgia, serif;
  letter-spacing: .17em;
}

.sidebar-brand small {
  display: block;
  margin-top: 7px;
  color: #ccb996;
  font-size: 9px;
  letter-spacing: .18em;
}

.sidebar-brand button {
  position: absolute;
  top: 7px;
  right: 4px;
  width: 34px;
  height: 34px;
  color: #dbcfc5;
  background: rgba(255,255,255,.07);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.saas-sidebar nav {
  display: grid;
  gap: 3px;
  margin-top: 18px;
}

.nav-item {
  display: flex;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  align-items: center;
  gap: 12px;
  color: #d8cac3;
  background: transparent;
  border: 0;
  border-radius: 10px;
  text-align: left;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: .16s ease;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,.07);
  transform: translateX(2px);
}

.nav-item.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(168,132,73,.28), rgba(255,255,255,.07));
  box-shadow: inset 3px 0 #c29b59;
}

.nav-item i {
  display: grid;
  width: 22px;
  height: 22px;
  flex: none;
  place-items: center;
  color: #d6b77f;
  font-size: 17px;
  font-style: normal;
}

.sidebar-bottom {
  display: grid;
  gap: 5px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-profile {
  display: flex;
  min-width: 0;
  padding: 10px 9px;
  align-items: center;
  gap: 10px;
}

.profile-avatar {
  display: grid;
  width: 36px;
  height: 36px;
  flex: none;
  place-items: center;
  color: #342326;
  background: #ddc394;
  border-radius: 11px;
  font-weight: 800;
}

.sidebar-profile b,
.sidebar-profile small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-profile b { color: #fff; font-size: 12px; }
.sidebar-profile small { margin-top: 2px; color: #ae9d95; font-size: 10px; }

.saas-frame {
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: margin-left .22s ease;
}

.saas-frame > header {
  min-height: 72px;
  padding: 12px 24px;
  color: var(--ink);
  background: rgba(250,249,247,.92);
  border-bottom: 1px solid #e5e1dc;
  box-shadow: 0 5px 18px rgba(45, 35, 31, .035);
}

.mobile-nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.sidebar-overlay,
.mobile-close-icon,
.mobile-search-icon {
  display: none;
}

[hidden] {
  display: none !important;
}

button,
a,
input,
select,
textarea {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(49, 91, 154, .28);
  outline-offset: 2px;
}

.top-page {
  min-width: 130px;
}

.top-page small,
.top-page b {
  display: block;
}

.top-page small {
  color: var(--gold);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .13em;
}

.top-page b {
  margin-top: 3px;
  font: 500 19px Georgia, serif;
}

.saas-frame .global-search-trigger {
  width: min(420px, 34vw);
  color: #776f67;
  background: #fff;
  border-color: #ddd7cf;
}

.saas-frame .global-search-trigger kbd {
  color: #7b726b;
  background: #f0eeeb;
}

.top-context {
  display: flex;
  gap: 8px;
  align-items: center;
}

.store-chip,
.today-chip {
  padding: 7px 9px;
  color: #6f675f;
  background: #fff;
  border: 1px solid #e2ddd6;
  border-radius: 8px;
  font-size: 10px;
  white-space: nowrap;
}

.saas-frame .header-actions .user-chip {
  color: #716860;
}

.icon-action {
  position: relative;
  width: 42px;
  height: 42px;
  color: var(--wine);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.icon-action .notice-count {
  position: absolute;
  top: -6px;
  right: -6px;
}

.saas-frame > main {
  max-width: 1540px;
  padding: 32px clamp(18px, 3vw, 42px) 64px;
}

body.sidebar-collapsed .saas-sidebar {
  width: var(--sidebar-collapsed);
}

body.sidebar-collapsed .saas-frame {
  margin-left: var(--sidebar-collapsed);
}

body.sidebar-collapsed .sidebar-brand span,
body.sidebar-collapsed .sidebar-brand small,
body.sidebar-collapsed .nav-item span,
body.sidebar-collapsed .sidebar-profile div {
  display: none;
}

body.sidebar-collapsed .sidebar-brand {
  padding-right: 0;
}

body.sidebar-collapsed .sidebar-brand button {
  right: 10px;
  transform: rotate(180deg);
}

body.sidebar-collapsed .nav-item {
  justify-content: center;
  padding-inline: 0;
}

.dashboard-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.mini-chart {
  display: flex;
  min-height: 190px;
  padding: 20px;
  align-items: end;
  gap: 10px;
}

.chart-column {
  display: flex;
  min-width: 0;
  height: 145px;
  flex: 1;
  align-items: end;
  justify-content: center;
  gap: 3px;
  border-bottom: 1px solid var(--line);
}

.chart-column i {
  display: block;
  width: min(18px, 42%);
  min-height: 3px;
  background: var(--wine);
  border-radius: 5px 5px 0 0;
  transform-origin: bottom;
  animation: chart-grow .55s ease both;
}

.chart-column i.completed {
  background: var(--gold);
}

.chart-column span {
  position: absolute;
  margin-top: 155px;
  color: var(--muted);
  font-size: 9px;
}

@keyframes chart-grow {
  from { transform: scaleY(0); opacity: .2; }
}

.stat strong {
  animation: metric-in .35s ease both;
}

@keyframes metric-in {
  from { opacity: 0; transform: translateY(5px); }
}

.module-workspace {
  min-height: calc(100vh - 140px);
}

body.module-active #app > :not(.module-workspace) {
  display: none !important;
}

.module-hero {
  display: flex;
  margin-bottom: 24px;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.module-hero h1 {
  margin: 3px 0 0;
  font: 500 clamp(30px, 4vw, 44px)/1.1 Georgia, serif;
}

.module-hero p {
  margin: 8px 0 0;
  color: var(--muted);
}

.view-switcher {
  display: flex;
  padding: 4px;
  gap: 3px;
  overflow-x: auto;
  background: #eae7e2;
  border-radius: 11px;
}

.view-switcher button {
  min-height: 38px;
  padding: 7px 11px;
  color: #6f675f;
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.view-switcher button.active {
  color: var(--wine);
  background: #fff;
  box-shadow: 0 3px 10px rgba(49,38,34,.08);
}

.module-filter-bar {
  display: flex;
  margin-bottom: 18px;
  padding: 10px;
  gap: 8px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid #e7e1da;
  border-radius: 13px;
}

.module-filter-bar input {
  min-width: 240px;
  flex: 1;
}

.module-filter-bar select {
  width: auto;
  min-width: 145px;
}

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

.saas-card {
  min-width: 0;
  padding: 18px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #e8e2da;
  border-radius: 15px;
  box-shadow: 0 9px 26px rgba(50, 39, 32, .055);
}

button.saas-card {
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.saas-card:hover {
  border-color: #d1b98f;
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(50,39,32,.085);
}

.saas-card h3 {
  margin: 7px 0 3px;
  font: 500 19px Georgia, serif;
}

.saas-card p,
.saas-card small {
  color: var(--muted);
}

.saas-card small {
  display: block;
  margin-top: 8px;
}

.card-meta {
  display: flex;
  margin-top: 13px;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-pill {
  padding: 4px 7px;
  color: #6a6159;
  background: #f3f0ec;
  border-radius: 99px;
  font-size: 9px;
  font-weight: 700;
}

.kanban-board {
  display: grid;
  grid-template-columns: repeat(8, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
}

.kanban-column {
  min-height: 320px;
  padding: 12px;
  background: #ebe8e3;
  border-radius: 14px;
}

.kanban-column > h3 {
  display: flex;
  margin: 0 0 12px;
  justify-content: space-between;
  font-size: 12px;
}

.kanban-column .saas-card {
  margin-bottom: 9px;
  padding: 13px;
  box-shadow: none;
}

.crm-list,
.measurement-library,
.calendar-grid,
.analytics-grid {
  display: grid;
  gap: 14px;
}

.crm-list { grid-template-columns: repeat(3, 1fr); }
.measurement-library { grid-template-columns: repeat(3, 1fr); }
.analytics-grid { grid-template-columns: repeat(4, 1fr); }

.measurement-template-row {
  display: flex;
  margin-bottom: 14px;
  gap: 8px;
  overflow-x: auto;
}

.measurement-template-row span {
  min-width: max-content;
  padding: 8px 12px;
  color: var(--wine);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 99px;
  font-size: 10px;
  font-weight: 750;
}

.measurement-preview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 13px;
}

.measurement-preview span {
  padding: 7px;
  background: #f7f4ef;
  border-radius: 7px;
  font-size: 10px;
}

.measurement-preview b {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 8px;
  text-transform: uppercase;
}

.module-section-title {
  margin: 30px 0 14px;
  font: 500 23px Georgia, serif;
}

.module-chart-space {
  margin-top: 20px;
}

.customer-actions {
  display: flex;
  margin-top: 14px;
  gap: 7px;
}

.customer-actions a,
.customer-actions button {
  min-height: 38px;
  padding: 7px 10px;
  color: var(--wine);
  background: #faf7f2;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  font-size: 10px;
  font-weight: 700;
}

.calendar-grid {
  grid-template-columns: repeat(7, 1fr);
}

.calendar-day {
  min-height: 145px;
}

.calendar-day > b {
  display: block;
  margin-bottom: 10px;
}

.calendar-event {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 6px;
  overflow: hidden;
  color: var(--wine);
  background: #f7e9eb;
  border: 0;
  border-radius: 7px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9px;
  cursor: pointer;
}

.command-palette {
  width: min(680px, calc(100% - 24px));
  max-height: min(720px, 84vh);
  margin-top: 8vh;
  overflow: hidden;
  border-radius: 16px;
}

.command-input-wrap {
  display: grid;
  grid-template-columns: auto 1fr auto;
  padding: 14px 16px;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.command-input-wrap input {
  border: 0;
  box-shadow: none;
  font-size: 15px;
}

.command-input-wrap kbd {
  padding: 4px 6px;
  color: var(--muted);
  background: #f0ede9;
  border-radius: 5px;
  font-size: 9px;
}

.command-results {
  max-height: 560px;
  padding: 8px;
  overflow-y: auto;
}

.command-result {
  display: flex;
  width: 100%;
  min-height: 58px;
  padding: 10px 12px;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 9px;
  text-align: left;
  cursor: pointer;
}

.command-result:hover,
.command-result:focus {
  background: #f4f0ea;
  outline: 0;
}

.command-result b,
.command-result small {
  display: block;
}

.command-result small {
  margin-top: 3px;
  color: var(--muted);
}

.command-result > span:last-child {
  color: var(--gold);
  font-size: 10px;
}

.skeleton .stat,
.skeleton-card {
  position: relative;
  overflow: hidden;
  min-height: 110px;
  background: #eae7e2;
}

.skeleton .stat::after,
.skeleton-card::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.65), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.2s infinite;
}

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

.recommendation-panel {
  margin-top: 20px;
}

.recommendation-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.recommendation-list > div {
  padding: 12px 14px;
  color: var(--ink);
  background: #faf8f4;
  border: 1px solid #eee8df;
  border-radius: 10px;
}

@keyframes shimmer {
  to { transform: translateX(100%); }
}

@media (max-width: 1180px) {
  .top-context, .saas-frame .header-actions .user-chip { display: none; }
  .module-grid, .crm-list { grid-template-columns: repeat(2, 1fr); }
  .analytics-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
  html,
  body {
    max-width: 100%;
    overflow-x: clip;
  }

  body.mobile-sidebar-open {
    overflow: hidden;
  }

  .saas-sidebar {
    width: min(310px, 88vw);
    max-width: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-105%);
  }

  body.mobile-sidebar-open .saas-sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    z-index: 34;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    background: rgba(31, 22, 24, .58);
    border: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }

  body.mobile-sidebar-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-close-icon { display: inline; }
  .desktop-collapse-icon { display: none; }

  .saas-frame,
  body.sidebar-collapsed .saas-frame {
    margin-left: 0;
  }

  .mobile-nav-toggle {
    display: inline-grid;
    flex: none;
    place-items: center;
  }

  .saas-frame > header {
    position: sticky;
    top: 0;
    z-index: 25;
    min-height: 62px;
    padding: 10px 14px;
    flex-wrap: nowrap;
  }

  .top-page {
    min-width: 0;
  }

  .top-page small { display: none; }
  .top-page b { font-size: 16px; }
  .saas-frame .global-search-trigger {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
    flex: none;
    justify-content: center;
  }
  .saas-frame .global-search-trigger > span:first-child,
  .saas-frame .global-search-trigger kbd { display: none; }
  .mobile-search-icon { display: inline; font-size: 21px; }
  .header-actions { margin-left: auto; }
  .header-actions .icon-action { width: 44px; min-width: 44px; height: 44px; }
  .saas-frame .header-actions .primary { display: none; }
  .dashboard-chart-grid { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: repeat(2, 1fr); }

  dialog:not(.login) {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  dialog:not(.login) .modal-head {
    top: 0;
    z-index: 8;
  }

  dialog:not(.login) .close {
    width: 44px;
    height: 44px;
    flex: none;
  }

  .command-palette {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  .command-input-wrap {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 64px;
    background: #fff;
  }

  .command-input-wrap input { min-width: 0; font-size: 16px; }
  .command-input-wrap kbd { display: none; }
  .command-result { min-height: 60px; padding: 12px 14px; }
}

@media (max-width: 620px) {
  .saas-frame > main { padding: 22px 13px 48px; }
  .module-hero { align-items: flex-start; flex-direction: column; }
  .view-switcher { width: 100%; }
  .module-grid, .crm-list, .measurement-library, .analytics-grid { grid-template-columns: 1fr; }
  .calendar-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }
  .calendar-grid::-webkit-scrollbar { display: none; }
  .calendar-day {
    width: min(82vw, 320px);
    min-width: min(82vw, 320px);
    scroll-snap-align: start;
  }
  .mini-chart { min-height: 165px; padding-inline: 12px; }
  .command-palette { margin-top: 3vh; }
  .module-filter-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .module-filter-bar input { min-width: 0; grid-column: 1 / -1; }
  .module-filter-bar select { width: 100%; min-width: 0; }
  .kanban-board {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    overscroll-behavior-inline: contain;
    padding-bottom: 8px;
  }
  .kanban-column {
    width: min(86vw, 330px);
    min-width: min(86vw, 330px);
    min-height: 0;
    scroll-snap-align: start;
  }
  .module-actions { width: 100%; }
  .module-actions .btn { flex: 1 1 140px; }

  .view-switcher {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .view-switcher button { min-height: 44px; }
  .saas-card { padding: 15px; }
  .customer-actions { display: grid; grid-template-columns: repeat(3, 1fr); }
  .customer-actions a,
  .customer-actions button {
    display: grid;
    min-height: 44px;
    place-items: center;
  }
}

@media (max-width: 380px) {
  .saas-frame > header { padding-inline: 10px; gap: 8px; }
  .top-page b {
    max-width: 116px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .module-filter-bar { grid-template-columns: 1fr; }
  .module-filter-bar input { grid-column: auto; }
}
