/* EMA Design System — shared demo application shell */
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--ema-font-sans);
  font-size: var(--ema-text-md);
  color: var(--ema-text);
  background: var(--ema-bg);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Sidebar ---------- */
.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 224px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  background: var(--ema-surface);
  border-right: 1px solid var(--ema-border);
  transition: transform 250ms var(--ema-ease);
}
.app-logo {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--ema-border);
  font-weight: 800;
  letter-spacing: -0.01em;
}
.app-logo__mark {
  width: 30px; height: 30px; flex: none;
  border-radius: var(--ema-radius-md);
  background: linear-gradient(135deg, var(--ema-primary), var(--ema-secondary));
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: var(--ema-shadow-sm);
}
.app-logo__mark svg { width: 16px; height: 16px; }
.app-logo small { display: block; font-weight: 500; font-size: 0.65rem; color: var(--ema-text-3); letter-spacing: 0.04em; }

.app-nav { flex: 1; padding: 0.75rem 0.6rem; overflow-y: auto; }
.app-nav__item {
  display: flex; align-items: center; gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.7rem;
  margin-bottom: 2px;
  border: none; background: none;
  border-radius: var(--ema-radius-md);
  font: inherit; font-size: var(--ema-text-sm); font-weight: 500;
  color: var(--ema-text-2);
  cursor: pointer;
  text-align: left;
  transition: all 130ms var(--ema-ease);
  text-decoration: none;
}
.app-nav__item svg { width: 16px; height: 16px; flex: none; }
.app-nav__item:hover { background: var(--ema-surface-3); color: var(--ema-text); }
.app-nav__item.active {
  background: var(--ema-primary-soft);
  color: var(--ema-primary);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--ema-primary);
}
.app-nav__badge { margin-left: auto; }

.app-sidebar__footer {
  padding: 0.75rem 0.9rem;
  border-top: 1px solid var(--ema-border);
  font-size: var(--ema-text-xs);
}
.app-sidebar__footer a {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--ema-text-3);
  text-decoration: none;
  transition: color 120ms;
}
.app-sidebar__footer a:hover { color: var(--ema-primary); }
.app-sidebar__footer svg { width: 12px; height: 12px; }

/* ---------- Main / topbar ---------- */
.app-main { flex: 1; margin-left: 224px; min-width: 0; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: 0;
  z-index: 300;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  background: color-mix(in srgb, var(--ema-surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--ema-border);
  min-height: 54px;
}
.app-topbar__burger { display: none; }
.app-topbar__title { font-size: var(--ema-text-lg); font-weight: 700; margin-right: auto; }
.app-topbar .doc-theme-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--ema-border-strong);
  cursor: pointer; padding: 0;
  transition: transform 150ms var(--ema-ease-spring);
}
.app-topbar .doc-theme-dot:hover { transform: scale(1.18); }
.app-topbar .doc-theme-dot.active { border-color: var(--ema-primary); box-shadow: var(--ema-focus-ring); }
.doc-theme-dot--light   { background: linear-gradient(135deg, #f7f9fc 50%, #1f5fa8 50%); }
.doc-theme-dot--dark    { background: linear-gradient(135deg, #151d2a 50%, #5495db 50%); }
.doc-theme-dot--navy    { background: linear-gradient(135deg, #0a1626 50%, #6db3f2 50%); }
.doc-theme-dot--emerald { background: linear-gradient(135deg, #f4faf6 50%, #178a53 50%); }
.app-settings-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--ema-border-strong);
  border-radius: var(--ema-radius-md);
  background: var(--ema-surface);
  color: var(--ema-text-2);
  cursor: pointer;
  transition: all 150ms;
}
.app-settings-btn:hover { color: var(--ema-primary); border-color: var(--ema-primary); transform: rotate(30deg); }
.app-settings-btn svg { width: 15px; height: 15px; }
.doc-set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  margin-bottom: 0.45rem;
  font-size: var(--ema-text-sm);
  color: var(--ema-text-2);
}
.doc-set-row input[type="color"] {
  width: 56px; height: 26px;
  border: 1px solid var(--ema-border-strong);
  border-radius: var(--ema-radius-sm);
  background: var(--ema-surface);
  padding: 1px; cursor: pointer;
}
.doc-set-row select {
  height: 26px; min-width: 110px;
  border: 1px solid var(--ema-border-strong);
  border-radius: var(--ema-radius-sm);
  background: var(--ema-surface);
  color: var(--ema-text);
  font: inherit; font-size: var(--ema-text-sm);
  cursor: pointer; outline: none;
}

.app-content { flex: 1; padding: 1.4rem 1.5rem 3rem; animation: ema-fade-in 200ms var(--ema-ease); }
.app-content h2 { margin: 1.75rem 0 0.75rem; font-size: 1.1rem; }
.app-content h2:first-child { margin-top: 0; }

/* ---------- Widgets ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.9rem; margin-bottom: 1.1rem; }
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }

.panel {
  background: var(--ema-surface);
  border: 1px solid var(--ema-border);
  border-radius: var(--ema-radius-lg);
  box-shadow: var(--ema-shadow-sm);
}
.panel__head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.8rem 1rem 0.4rem;
  background: var(--ema-header-bg, transparent);
  color: var(--ema-header-text, inherit);
  border-radius: var(--ema-radius-lg) var(--ema-radius-lg) 0 0;
}
.panel__head .panel__sub { color: var(--ema-header-text-2, var(--ema-text-3)); }
.panel__title { font-weight: 700; font-size: var(--ema-text-md); }
.panel__sub { font-size: var(--ema-text-xs); color: var(--ema-text-3); }
.panel__body { padding: 0.5rem 1rem 1rem; }

.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 0.9rem; margin-bottom: 0.9rem; }
.two-col--even { grid-template-columns: 1fr 1fr; }
@media (max-width: 1000px) { .two-col, .two-col--even { grid-template-columns: 1fr; } }

/* charts */
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-family: var(--ema-font-sans); font-size: 10px; fill: var(--ema-text-3); }
.chart .grid-line { stroke: var(--ema-border); stroke-dasharray: 2 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.9rem; padding: 0.3rem 0 0; font-size: var(--ema-text-xs); color: var(--ema-text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* simple list */
.simple-list { list-style: none; margin: 0; padding: 0; }
.simple-list li {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--ema-border);
  font-size: var(--ema-text-sm);
}
.simple-list li:last-child { border-bottom: none; }
.simple-list .when { margin-left: auto; color: var(--ema-text-3); font-size: var(--ema-text-xs); white-space: nowrap; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(225px, 1fr); gap: 0.8rem; overflow-x: auto; padding-bottom: 0.75rem; }
.kanban__col {
  background: var(--ema-surface-2);
  border: 1px solid var(--ema-border);
  border-radius: var(--ema-radius-lg);
  display: flex; flex-direction: column;
  max-height: 70vh;
}
.kanban__head {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 0.8rem;
  font-weight: 700; font-size: var(--ema-text-sm);
  border-bottom: 1px solid var(--ema-border);
}
.kanban__head .ema-badge { margin-left: auto; }
.kanban__sum { padding: 0.3rem 0.8rem; font-size: var(--ema-text-xs); color: var(--ema-text-3); border-bottom: 1px solid var(--ema-border); }
.kanban__cards { padding: 0.6rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.55rem; }
.deal-card {
  background: var(--ema-surface);
  border: 1px solid var(--ema-border);
  border-radius: var(--ema-radius-md);
  padding: 0.6rem 0.7rem;
  box-shadow: var(--ema-shadow-sm);
  transition: transform 150ms var(--ema-ease), box-shadow 150ms;
  animation: ema-pop-in 250ms var(--ema-ease-out);
}
.deal-card:hover { transform: translateY(-2px); box-shadow: var(--ema-shadow-md); }
.deal-card__name { font-weight: 600; font-size: var(--ema-text-sm); display: flex; justify-content: space-between; gap: 0.4rem; }
.deal-card__meta { display: flex; align-items: center; gap: 0.45rem; margin-top: 0.45rem; font-size: var(--ema-text-xs); color: var(--ema-text-3); }
.deal-card__value { font-weight: 700; color: var(--ema-primary); }

/* ---------- Recon detail (airline) ---------- */
.recon-compare { width: 100%; border-collapse: collapse; font-size: var(--ema-text-sm); }
.recon-compare th, .recon-compare td { text-align: right; padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--ema-border); }
.recon-compare th:first-child, .recon-compare td:first-child { text-align: left; }
.recon-compare th { font-size: var(--ema-text-xs); text-transform: uppercase; letter-spacing: 0.05em; color: var(--ema-text-3); }
.recon-compare .diff-bad { color: var(--ema-danger); font-weight: 700; }
.recon-compare .diff-ok { color: var(--ema-success); }
.recon-compare tr:last-child td { border-bottom: none; }

/* progress-in-cell */
.cell-progress { display: flex; align-items: center; gap: 0.5rem; }
.cell-progress .ema-progress { flex: 1; min-width: 50px; }
.cell-progress span { font-size: var(--ema-text-xs); color: var(--ema-text-3); min-width: 34px; text-align: right; }

/* ---------- POS (point of sale) ---------- */
.pos-layout { display: grid; grid-template-columns: 1fr 340px; gap: 0.9rem; align-items: start; }
@media (max-width: 1000px) { .pos-layout { grid-template-columns: 1fr; } }
.pos-cats { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.pos-cat {
  border: 1px solid var(--ema-border-strong);
  background: var(--ema-surface);
  color: var(--ema-text-2);
  font: inherit; font-size: var(--ema-text-sm); font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: var(--ema-radius-full);
  cursor: pointer;
  transition: all 130ms var(--ema-ease);
}
.pos-cat:hover { border-color: var(--ema-primary); color: var(--ema-primary); }
.pos-cat.active { background: var(--ema-primary); border-color: var(--ema-primary); color: var(--ema-on-primary); }
.pos-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 0.6rem; }
.pos-product {
  background: var(--ema-surface);
  border: 1px solid var(--ema-border);
  border-radius: var(--ema-radius-lg);
  padding: 0.7rem;
  cursor: pointer;
  text-align: center;
  user-select: none;
  transition: all 130ms var(--ema-ease);
  position: relative;
  overflow: hidden;
}
.pos-product:hover { border-color: var(--ema-primary); box-shadow: var(--ema-shadow-md); transform: translateY(-2px); }
.pos-product:active { transform: scale(0.96); }
.pos-product__emoji { font-size: 1.7rem; line-height: 1.3; }
.pos-product__name { font-size: var(--ema-text-sm); font-weight: 600; margin: 0.25rem 0 0.15rem; }
.pos-product__price { font-size: var(--ema-text-sm); color: var(--ema-primary); font-weight: 700; }
.pos-product__stock { font-size: 0.62rem; color: var(--ema-text-3); }
.pos-product--out { opacity: 0.45; pointer-events: none; }

.pos-cart { position: sticky; top: 70px; }
.pos-cart__items { max-height: 38vh; overflow-y: auto; }
.pos-line {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--ema-border);
  font-size: var(--ema-text-sm);
}
.pos-line__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pos-line__qty { display: inline-flex; align-items: center; gap: 0.35rem; }
.pos-line__qty button {
  width: 1.35rem; height: 1.35rem;
  border: 1px solid var(--ema-border-strong);
  background: var(--ema-surface);
  color: var(--ema-text-2);
  border-radius: var(--ema-radius-sm);
  cursor: pointer;
  font: inherit; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 110ms;
}
.pos-line__qty button:hover { border-color: var(--ema-primary); color: var(--ema-primary); }
.pos-line__total { font-weight: 700; min-width: 64px; text-align: right; }
.pos-totals { font-size: var(--ema-text-sm); color: var(--ema-text-2); display: flex; flex-direction: column; gap: 0.25rem; padding: 0.6rem 0; }
.pos-totals div { display: flex; justify-content: space-between; }
.pos-totals .grand { font-size: var(--ema-text-lg); font-weight: 800; color: var(--ema-text); border-top: 1px solid var(--ema-border); padding-top: 0.4rem; margin-top: 0.2rem; }

/* ---------- Trace timeline (airline) ---------- */
.trace-timeline { list-style: none; margin: 0.5rem 0 0; padding: 0; position: relative; }
.trace-timeline::before {
  content: "";
  position: absolute; left: 13px; top: 8px; bottom: 8px;
  width: 2px;
  background: var(--ema-border);
}
.trace-step { display: flex; gap: 0.8rem; padding: 0.45rem 0; position: relative; }
.trace-step__dot {
  width: 28px; height: 28px; flex: none;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ema-primary-soft);
  color: var(--ema-primary);
  border: 2px solid var(--ema-surface);
  z-index: 1;
}
.trace-step__dot svg { width: 13px; height: 13px; }
.trace-step--ok .trace-step__dot { background: var(--ema-success-soft); color: var(--ema-success); }
.trace-step--warn .trace-step__dot { background: var(--ema-warning-soft); color: var(--ema-warning); }
.trace-step--bad .trace-step__dot { background: var(--ema-danger-soft); color: var(--ema-danger); }
.trace-step__body { flex: 1; min-width: 0; padding-top: 0.15rem; }
.trace-step__title { font-weight: 600; font-size: var(--ema-text-sm); display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.trace-step__meta { font-size: var(--ema-text-xs); color: var(--ema-text-3); margin-top: 0.1rem; }
.trace-step__amount { margin-left: auto; font-weight: 700; font-size: var(--ema-text-sm); white-space: nowrap; padding-top: 0.2rem; }

/* ---------- SSO: login & portal ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background:
    radial-gradient(900px 420px at 10% 0%, color-mix(in srgb, var(--ema-primary) 14%, transparent), transparent 60%),
    radial-gradient(700px 380px at 95% 100%, color-mix(in srgb, var(--ema-secondary) 12%, transparent), transparent 60%),
    var(--ema-bg);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--ema-surface);
  border: 1px solid var(--ema-border);
  border-radius: var(--ema-radius-xl);
  box-shadow: var(--ema-shadow-xl);
  padding: 2rem 1.8rem 1.6rem;
  animation: ema-pop-up 350ms var(--ema-ease-spring);
}
.login-logo { display: flex; align-items: center; gap: 0.6rem; font-weight: 800; font-size: 1.1rem; margin-bottom: 1.2rem; }
.login-divider {
  display: flex; align-items: center; gap: 0.7rem;
  margin: 1rem 0;
  color: var(--ema-text-3); font-size: var(--ema-text-xs);
}
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--ema-border); }
.social-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.55rem;
  width: 100%;
  height: var(--ema-control-h-md);
  border: 1px solid var(--ema-border-strong);
  border-radius: var(--ema-radius-md);
  background: var(--ema-surface);
  color: var(--ema-text);
  font: inherit; font-size: var(--ema-text-sm); font-weight: 600;
  cursor: pointer;
  transition: all 130ms var(--ema-ease);
  margin-bottom: 0.45rem;
}
.social-btn:hover { border-color: var(--ema-primary); background: var(--ema-primary-soft); }
.social-btn svg, .social-btn .g { width: 16px; height: 16px; flex: none; }
.login-demo-accounts {
  margin-top: 1.1rem;
  border-top: 1px dashed var(--ema-border);
  padding-top: 0.8rem;
  font-size: var(--ema-text-xs);
  color: var(--ema-text-3);
}
.login-demo-accounts code {
  cursor: pointer;
  color: var(--ema-primary);
  background: var(--ema-primary-soft);
  border-radius: var(--ema-radius-xs);
  padding: 0 0.3rem;
  font-family: var(--ema-font-mono);
}
.login-demo-accounts code:hover { background: var(--ema-primary-soft-2); }
.login-demo-accounts li { margin: 0.2rem 0; }

.portal-topbar {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.7rem 1.5rem;
  background: var(--ema-surface);
  border-bottom: 1px solid var(--ema-border);
}
.portal-main { max-width: 980px; margin: 0 auto; padding: 2rem 1.2rem 4rem; }
.portal-apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; margin-top: 1.2rem; }
.portal-app {
  display: flex; gap: 0.85rem; align-items: flex-start;
  background: var(--ema-surface);
  border: 1px solid var(--ema-border);
  border-radius: var(--ema-radius-lg);
  padding: 1.1rem;
  text-decoration: none; color: var(--ema-text);
  transition: all 180ms var(--ema-ease);
  position: relative;
}
.portal-app:hover { transform: translateY(-3px); box-shadow: var(--ema-shadow-lg); border-color: var(--ema-primary-border); }
.portal-app--locked { opacity: 0.55; }
.portal-app--locked:hover { transform: none; box-shadow: none; border-color: var(--ema-border); }
.portal-app__icon {
  width: 42px; height: 42px; flex: none;
  border-radius: var(--ema-radius-md);
  background: linear-gradient(135deg, var(--ema-primary), var(--ema-secondary));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.portal-app__icon svg { width: 20px; height: 20px; }
.portal-app--locked .portal-app__icon { background: var(--ema-surface-3); color: var(--ema-text-3); }
.portal-app h3 { margin: 0 0 0.15rem; font-size: var(--ema-text-md); }
.portal-app p { margin: 0; font-size: var(--ema-text-xs); color: var(--ema-text-3); }
.portal-app__lock { position: absolute; top: 0.7rem; right: 0.7rem; color: var(--ema-text-3); }
.portal-app__lock svg { width: 14px; height: 14px; }

/* ---------- App user chip (topbar) ---------- */
.app-user {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid transparent;
  background: none;
  border-radius: var(--ema-radius-full);
  padding: 0.15rem 0.55rem 0.15rem 0.15rem;
  cursor: pointer;
  font: inherit; color: var(--ema-text-2); font-size: var(--ema-text-xs);
  transition: all 130ms;
}
.app-user:hover { background: var(--ema-surface-3); }
.app-user .ema-avatar { width: 28px; height: 28px; font-size: 0.6rem; }
.app-user__dot {
  position: absolute; top: -1px; right: -1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ema-warning);
  border: 2px solid var(--ema-surface);
  animation: ema-pulse 1.8s infinite;
}

/* ---------- Menu layouts: rail & top ---------- */
.app--rail .app-sidebar { width: 64px; }
.app--rail .app-logo { justify-content: center; padding: 0.9rem 0.4rem; }
.app--rail .app-logo > span:last-child { display: none; }
.app--rail .app-nav__item { justify-content: center; padding: 0.55rem 0.4rem; }
.app--rail .app-nav__item > span { display: none; }
.app--rail .app-nav__item .app-nav__badge { display: none; }
.app--rail .app-sidebar__footer a span { display: none; }
.app--rail .app-sidebar__footer { text-align: center; }
.app--rail .app-main { margin-left: 64px; }

.app--top { flex-direction: column; }
.app--top .app-sidebar {
  position: sticky; top: 0; bottom: auto;
  width: 100%; height: auto;
  flex-direction: row; align-items: center;
  z-index: 450;
  transform: none !important;
}
.app--top .app-logo { border-bottom: none; padding: 0.45rem 1rem; white-space: nowrap; }
.app--top .app-logo small { display: none; }
.app--top .app-nav { display: flex; flex: 1; padding: 0.3rem 0.4rem; overflow-x: auto; scrollbar-width: none; }
.app--top .app-nav__item { width: auto; margin: 0 1px; white-space: nowrap; }
.app--top .app-nav__item.active { box-shadow: inset 0 -2px 0 var(--ema-primary); }
.app--top .app-sidebar__footer { border-top: none; padding: 0 0.9rem; white-space: nowrap; }
.app--top .app-main { margin-left: 0; }
@media (max-width: 900px) {
  .app--top .app-sidebar { position: sticky; }
  .app--top .app-topbar__burger { display: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app-sidebar { transform: translateX(-100%); box-shadow: var(--ema-shadow-xl); }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .app-topbar__burger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border: 1px solid var(--ema-border-strong);
    border-radius: var(--ema-radius-md);
    background: var(--ema-surface);
    color: var(--ema-text-2);
    cursor: pointer;
  }
  .app-topbar__burger svg { width: 16px; height: 16px; }
  .app-content { padding: 1rem 0.9rem 3rem; }
  .kpi-row { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
}
