:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17171c;
  background: #f6f5fb;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html, body, #root { width: 100%; min-width: 320px; min-height: 100%; margin: 0; }
body {
  min-height: 100vh;
  background: #f7f7fb;
  color: #17171c;
}
body.editor-mode {
  overflow: hidden;
  background: #f4f4f7;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, [role="button"]:focus-visible, a:focus-visible { outline: 3px solid rgba(111,75,232,.24); outline-offset: 2px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* Emergency site chrome fallback */
.msc-emergency-header {
  min-height: 74px;
  background: #fff;
  border-bottom: 1px solid #ececec;
}
.msc-emergency-header-inner {
  width: 1200px;
  max-width: 90%;
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  font-family: "Open Sans", Arial, sans-serif;
}
.msc-emergency-brand {
  font-weight: 800;
  font-size: 20px;
  color: #6f4be8;
  text-decoration: none;
}
.msc-emergency-links {
  display: flex;
  gap: 20px;
  align-items: center;
}
.msc-emergency-links a {
  color: #333;
  text-decoration: none;
  font-size: 14px;
}
.msc-emergency-footer {
  padding: 28px 5%;
  color: #d7d7d7;
  background: #202020;
  font: 14px/1.6 "Open Sans", Arial, sans-serif;
}
.msc-emergency-footer-inner {
  width: 1200px;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}
.msc-emergency-footer a { color: #fff; text-decoration: none; }
body.editor-mode [data-motricialy-site-header],
body.editor-mode [data-motricialy-site-footer] {
  display: none !important;
}
body.editor-mode #root { min-height: 100vh; }

.brand { display: inline-flex; align-items: center; gap: 9px; color: #17171c; text-decoration: none; font-weight: 720; letter-spacing: -0.015em; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.brand-button { border: 0; background: transparent; padding: 0; cursor: pointer; }

.tool-home {
  min-height: calc(100vh - 148px);
  background:
    radial-gradient(circle at 50% 0%, rgba(111,75,232,.10), transparent 34%),
    linear-gradient(180deg, rgba(248,247,252,1) 0%, rgba(246,245,251,1) 100%);
}
.tool-home-inner {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0 72px;
}
.tool-hero {
  max-width: 760px;
  margin: 0 auto 28px;
  text-align: center;
}
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  background: #efeafe;
  color: #5d35cc;
  font-size: 12px;
  font-weight: 740;
}
.tool-badge svg { width: 15px; height: 15px; }
.tool-hero h1 {
  margin: 16px 0 12px;
  font-size: clamp(34px, 5vw, 56px);
  line-height: 1.02;
  letter-spacing: -.04em;
}
.tool-hero p {
  margin: 0 auto;
  max-width: 660px;
  color: #66636d;
  font-size: 17px;
  line-height: 1.7;
}
.tool-card {
  width: min(1200px, 100%);
  margin: 0 auto;
}

.restore-card {
  margin: 0 auto 18px;
  max-width: 760px;
  display: grid;
  grid-template-columns: 42px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 13px 14px;
  border: 1px solid #ddd7f5;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(43,32,83,.05);
  text-align: left;
}
.restore-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 11px; background: #f1edff; color: #6542d8; }
.restore-copy { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.restore-copy strong { font-size: 14px; }
.restore-copy span { color: #77727e; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.upload-card {
  max-width: 860px;
}
.upload-panel {
  width: 100%;
  padding: 52px 34px 40px;
  border: 1.5px dashed #c5bde4;
  border-radius: 24px;
  background: rgba(255,255,255,.96);
  cursor: pointer;
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease, background .16s ease;
  box-shadow: 0 20px 55px rgba(47,35,90,.07);
  text-align: center;
}
.upload-panel:hover,
.upload-panel.is-dragging {
  border-color: #6f4be8;
  background: #fcfbff;
  box-shadow: 0 24px 64px rgba(78,54,160,.13);
}
.upload-panel.is-dragging { transform: translateY(-2px); }
.upload-icon {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #f1edff, #e4dcff);
  color: #5d35cc;
}
.upload-icon svg { width: 32px; height: 32px; }
.upload-panel h2 { margin: 0 0 10px; font-size: 26px; letter-spacing: -.025em; }
.upload-panel p { margin: 0 auto 24px; max-width: 560px; color: #77727e; font-size: 15px; line-height: 1.7; }
.upload-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.upload-note { display: block; margin-top: 16px; color: #8d8995; font-size: 12px; }

.primary-button, .secondary-button, .toolbar-button, .download-button, .text-button, .icon-button { border: 0; cursor: pointer; }
.primary-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 18px;
  border-radius: 12px;
  background: #6f4be8;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 15px rgba(111,75,232,.2);
}
.primary-button:hover { background: #5d35cc; }
.secondary-button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 12px;
  color: #5936c7;
  background: #f0ebff;
  font-weight: 680;
}
.secondary-button:hover { background: #e8e0ff; }
.secondary-quiet {
  background: #f8f5ff;
  border: 1px solid #ddd4ff;
}
.text-button { padding: 8px 4px; background: transparent; color: #77727e; font-size: 12px; }
.text-button:hover { color: #4e4a55; }

.editor-shell { height: 100vh; display: grid; grid-template-rows: 56px 32px minmax(0,1fr) 36px; background: #f4f4f7; overflow: hidden; }
.appbar { display: flex; align-items: center; gap: 18px; padding: 0 14px; border-bottom: 1px solid #dedde3; background: #fff; z-index: 20; }
.appbar .brand { min-width: 122px; }
.file-meta { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 12px; }
.file-meta strong { min-width: 0; max-width: min(460px, 38vw); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 720; }
.save-state { display: inline-flex; align-items: center; gap: 6px; color: #85818b; font-size: 10.5px; white-space: nowrap; }
.save-state i { width: 6px; height: 6px; border-radius: 50%; background: #3aa76d; }
.save-state.is-saving i { background: #e19a34; }
.app-actions { display: flex; align-items: center; gap: 6px; }
.toolbar-button { height: 34px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border-radius: 8px; background: transparent; color: #4e4a55; font-size: 12px; font-weight: 650; }
.toolbar-button:hover { background: #f2f1f5; }
.toolbar-button svg { width: 15px; height: 15px; }
.download-button { height: 36px; display: inline-flex; align-items: center; gap: 7px; padding: 0 13px; border-radius: 9px; background: #6f4be8; color: #fff; font-size: 12px; font-weight: 720; }
.download-button:hover:not(:disabled) { background: #5d35cc; }
.download-button:disabled { opacity: .6; cursor: progress; }
.download-button svg { width: 15px; height: 15px; }
.safe-mode-bar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 14px; background: #faf9fe; border-bottom: 1px solid #e9e5f4; color: #5f596a; font-size: 10.5px; white-space: nowrap; overflow: hidden; }
.safe-mode-bar > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.safe-mode-bar svg { width: 13px; height: 13px; vertical-align: -2px; color: #6846d9; }
.preserve-note { color: #7659cb; font-weight: 680; }
.editor-stage { min-height: 0; position: relative; overflow: hidden; background: #fff; }
.univer-mount { position: absolute; inset: 0; }
.sheet-tabs { min-width: 0; display: flex; align-items: stretch; gap: 1px; padding: 0 8px; border-top: 1px solid #dbdae0; background: #f7f7f9; overflow-x: auto; }
.sheet-tabs button { min-width: 74px; max-width: 180px; border: 0; border-top: 2px solid transparent; padding: 0 13px; background: transparent; color: #68646e; cursor: pointer; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-tabs button:hover { background: #eeeef2; }
.sheet-tabs button.is-active { border-top-color: #6f4be8; background: #fff; color: #3d3944; font-weight: 680; }
.tab-hint { margin-left: auto; padding: 0 10px; display: flex; align-items: center; color: #9a96a0; font-size: 9.5px; white-space: nowrap; }

.dialog-backdrop { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 22px; background: rgba(21,18,31,.34); backdrop-filter: blur(3px); }
.dialog { position: relative; width: min(480px, 100%); padding: 27px; border-radius: 18px; background: #fff; box-shadow: 0 30px 90px rgba(20,16,39,.25); }
.dialog h2 { margin: 0 35px 9px 0; font-size: 20px; letter-spacing: -.02em; }
.dialog p { margin: 0; color: #706b76; font-size: 13px; line-height: 1.6; }
.dialog ul { margin: 15px 0 0; padding: 13px 16px 13px 31px; border-radius: 10px; background: #f7f5fb; color: #625c6a; font-size: 12px; line-height: 1.55; }
.dialog-close { position: absolute; right: 14px; top: 14px; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: transparent; color: #7f7986; }
.dialog-close:hover { background: #f0eef4; }
.dialog-action { width: 100%; margin-top: 19px; }
.icon-button { background: transparent; }
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(4px);
}
.loading-card, .editor-preparing-card {
  width: min(420px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.loading-card strong, .editor-preparing-card strong {
  margin-top: 12px;
  color: #302b39;
  font-size: 14px;
  font-weight: 760;
}
.loading-card span, .editor-preparing-card span {
  margin-top: 5px;
  color: #7a7482;
  font-size: 11.5px;
  line-height: 1.5;
}
.spinner { width: 24px; height: 24px; border: 2px solid #ddd7f3; border-top-color: #6f4be8; border-radius: 50%; animation: spin .7s linear infinite; }
.progress-track {
  position: relative;
  width: 100%;
  height: 7px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: #ebe7f5;
}
.progress-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 38%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6f4be8, #815ff0);
  animation: progress-sweep 1.35s ease-in-out infinite;
}
.editor-preparing {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #fff;
}
.editor-preparing-card {
  padding: 22px 24px;
  border: 1px solid #e7e2f4;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 16px 44px rgba(52,38,104,.08);
}
.editor-preparing-card strong { margin-top: 0; font-size: 15px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes progress-sweep {
  0% { transform: translateX(-110%); }
  55% { transform: translateX(95%); }
  100% { transform: translateX(245%); }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
  .progress-bar { animation: none; width: 65%; }
}

/* Keep Univer inside the app viewport and avoid global theme leakage. */
.editor-stage .univer-app-container, .editor-stage [class*="univer"] { max-width: none; }
.preserve-note { border: 0; background: transparent; padding: 0; cursor: pointer; color: #7659cb; font: inherit; font-weight: 680; white-space: nowrap; }
.preserve-note:hover { color: #5d35cc; text-decoration: underline; text-underline-offset: 2px; }

@media (max-width: 900px) {
  .msc-emergency-links a:not(:first-child) { display: none; }
}

@media (max-width: 760px) {
  .tool-home-inner { width: min(100%, calc(100% - 24px)); padding: 38px 0 56px; }
  .tool-hero p { font-size: 15px; }
  .upload-panel { padding: 34px 18px 28px; border-radius: 18px; }
  .upload-panel h2 { font-size: 23px; }
  .upload-actions { flex-direction: column; }
  .upload-actions .primary-button, .upload-actions .secondary-button { width: 100%; }
  .restore-card { grid-template-columns: 38px 1fr auto; }
  .restore-card .text-button { display: none; }
  .appbar { gap: 9px; padding: 0 8px; }
  .appbar .brand span { display: none; }
  .appbar .brand { min-width: auto; }
  .file-meta { gap: 7px; }
  .file-meta strong { max-width: 34vw; }
  .toolbar-button span { display: none; }
  .toolbar-button { width: 34px; padding: 0; justify-content: center; }
  .download-button span { display: none; }
  .download-button { width: 36px; padding: 0; justify-content: center; }
  .preserve-note, .tab-hint { display: none; }
}
