:root {
  color-scheme: light;
  --canvas: linear-gradient(180deg, #f7f8fb 0%, #edf1f6 100%);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: #ffffff;
  --surface-border: rgba(15, 23, 42, 0.08);
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --accent: #111827;
  --focus-ring: rgba(245, 158, 11, 0.22);
  --toolbar-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: light;
    --canvas: linear-gradient(180deg, #f7f8fb 0%, #edf1f6 100%);
    --surface: rgba(255, 255, 255, 0.9);
    --surface-strong: #ffffff;
    --surface-border: rgba(15, 23, 42, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #475569;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-width: 320px;
  overflow: hidden;
  background:
    radial-gradient(circle at 4% 0%, rgba(15, 23, 42, 0.06), transparent 24%),
    radial-gradient(circle at 96% 0%, rgba(245, 158, 11, 0.1), transparent 20%),
    var(--canvas);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
iframe {
  font: inherit;
}

button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.appShell {
  display: grid;
  grid-template-rows: var(--toolbar-height) minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  height: 100dvh;
  padding: 12px;
  overflow: hidden;
}

.appToolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  height: var(--toolbar-height);
  padding: 8px 10px 8px 18px;
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow:
    0 1px 3px rgba(15, 23, 42, 0.04),
    0 8px 24px rgba(15, 23, 42, 0.05);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.appTitle {
  margin: 0;
  overflow: hidden;
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modeSwitch {
  display: grid;
  grid-template-columns: repeat(3, minmax(52px, 1fr));
  gap: 4px;
  width: 204px;
  min-width: 204px;
  padding: 4px;
  border: 1px solid rgba(15, 23, 42, 0.07);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.05);
}

.modeButton {
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
  transition:
    background-color 180ms ease-out,
    color 180ms ease-out,
    box-shadow 180ms ease-out,
    transform 180ms ease-out;
}

.modeButton:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.68);
}

.modeButton[aria-pressed="true"] {
  background: var(--surface-strong);
  color: var(--text-primary);
  box-shadow:
    0 1px 3px rgba(15, 23, 42, 0.08),
    0 4px 12px rgba(15, 23, 42, 0.06);
}

.appWorkspace {
  display: grid;
  grid-template-columns: minmax(380px, 420px) minmax(0, 1fr);
  gap: 12px;
  width: min(100%, 1920px);
  min-height: 0;
  margin: 0 auto;
  align-items: center;
  overflow: hidden;
}

.phoneStage,
.adminStage {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--surface-border);
  background: var(--surface);
  box-shadow:
    0 24px 64px rgba(15, 23, 42, 0.1),
    0 4px 16px rgba(15, 23, 42, 0.04);
  transition:
    width 420ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 240ms ease-out,
    transform 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.phoneStage {
  justify-self: center;
  width: 420px;
  height: min(780px, 100%);
  padding: 8px;
  border-radius: 24px;
}

.adminStage {
  width: 100%;
  height: min(780px, 100%);
  padding: 8px;
  border-radius: 24px;
}

.phoneFrame,
.adminFrame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 16px;
  background: #ffffff;
}

body[data-mode="customer"] .appWorkspace,
body[data-mode="admin"] .appWorkspace {
  grid-template-columns: minmax(0, 1fr);
}

body[data-mode="customer"] .phoneStage {
  width: min(100%, 460px);
}

body[data-mode="customer"] .adminStage,
body[data-mode="admin"] .phoneStage {
  display: none;
}

body[data-mode="admin"] .adminStage {
  height: min(820px, 100%);
}

@media (max-width: 1100px) {
  body[data-mode="sync"] {
    overflow-y: auto;
  }

  body[data-mode="sync"] .appShell {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  body[data-mode="sync"] .appToolbar {
    position: sticky;
    top: 12px;
    z-index: 10;
  }

  body[data-mode="sync"] .appWorkspace {
    grid-template-columns: 1fr;
    gap: 16px;
    width: min(100%, 820px);
    overflow: visible;
  }

  body[data-mode="sync"] .phoneStage {
    width: min(100%, 420px);
    height: min(780px, calc(100dvh - 92px));
  }

  body[data-mode="sync"] .adminStage {
    height: 680px;
  }
}

@media (max-width: 768px) {
  :root {
    --toolbar-height: 54px;
  }

  .appShell {
    gap: 10px;
    padding: 10px;
  }

  .appToolbar {
    gap: 8px;
    padding: 6px 6px 6px 12px;
    border-radius: 16px;
  }

  .appTitle {
    font-size: 0.96rem;
  }

  .modeSwitch {
    grid-template-columns: repeat(3, minmax(46px, 1fr));
    width: 172px;
    min-width: 172px;
  }

  .modeButton {
    height: 34px;
    padding: 0 6px;
    font-size: 0.8rem;
  }

  .phoneStage,
  .adminStage {
    padding: 0;
    border-radius: 16px;
  }

  .phoneFrame,
  .adminFrame {
    border-radius: 16px;
  }

  body[data-mode="customer"] .phoneStage {
    width: min(100%, 420px);
    height: 100%;
  }

  body[data-mode="admin"] .adminStage {
    height: 100%;
  }

  body[data-mode="sync"] .appToolbar {
    top: 10px;
  }

  body[data-mode="sync"] .phoneStage {
    width: min(100%, 390px);
    height: min(780px, calc(100dvh - 84px));
  }

  body[data-mode="sync"] .adminStage {
    height: 600px;
  }
}

@media (max-width: 390px) {
  .modeSwitch {
    width: 166px;
    min-width: 166px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .modeButton,
  .phoneStage,
  .adminStage {
    transition: none;
  }
}
