:root {
  color-scheme: light;
  --bg: #eff4fb;
  --panel: #ffffff;
  --panel-border: #cfd8e6;
  --grid-border: #d8e1ee;
  --grid-header: #f3f6fb;
  --grid-header-strong: #eef3fa;
  --text: #172235;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --active-outline: #4f6df5;
  --danger: #b91c1c;
  --shadow: 0 16px 36px rgba(23, 34, 53, 0.08);
}

html {
  height: 100%;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  height: 100%;
  font-family: "Segoe UI", "Yu Gothic UI", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.08), transparent 24%),
    linear-gradient(180deg, #f9fbff 0%, var(--bg) 100%);
  color: var(--text);
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  min-width: 0;
  padding: 12px 12px 0;
}

.menu-bar {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-height: 40px;
  margin-bottom: 10px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.menu-tabs {
  display: flex;
  align-items: stretch;
}

.menu-tab {
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.menu-tab:hover,
.menu-tab:focus-visible,
.menu-tab.is-active {
  color: var(--accent-strong);
  background: rgba(37, 99, 235, 0.06);
  outline: none;
}

.menu-tab.is-active {
  border-bottom-color: var(--accent);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 10px;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 220px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 18px 34px rgba(23, 34, 53, 0.14);
}

.menu-dropdown.hidden {
  display: none;
}

.icon-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding: 8px 10px;
  overflow-x: auto;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.icon-toolbar-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.icon-toolbar-button:hover,
.icon-toolbar-button:focus-visible {
  border-color: var(--panel-border);
  background: rgba(37, 99, 235, 0.08);
  color: var(--accent-strong);
  outline: none;
  transform: translateY(-1px);
}

.icon-toolbar-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.icon-toolbar-button:disabled:hover,
.icon-toolbar-button:disabled:focus-visible {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.icon-toolbar-svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-dropdown-column {
  display: grid;
  min-width: 220px;
}

.menu-dropdown-submenu {
  padding-left: 8px;
  border-left: 1px solid var(--panel-border);
}

.menu-item {
  border: none;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 11px 14px;
  border-radius: 10px;
  text-align: left;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: #eef4ff;
  color: var(--accent-strong);
  outline: none;
}

.menu-item.is-active {
  background: #eef4ff;
  color: var(--accent-strong);
}

.menu-item.is-disabled {
  color: var(--muted);
  cursor: default;
}

.menu-item.is-disabled:hover,
.menu-item.is-disabled:focus-visible {
  background: transparent;
  color: var(--muted);
}

.menu-item-hint {
  color: #94a3b8;
  font-size: 12px;
  white-space: nowrap;
}

.button {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 15px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: #aebbd0;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button-primary:hover:not(:disabled) {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  min-width: 0;
}

.sheet-picker-bar,
.grid-panel,
.status-bar {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.sheet-picker-bar,
.status-bar {
  padding: 12px 16px;
}

.status-message,
.document-summary,
.panel-note {
  margin: 0;
  color: var(--muted);
}

.document-summary {
  font-size: 13px;
}

.sheet-picker-bar.hidden {
  display: none;
}

.sheet-picker-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
}

.sheet-picker-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.sheet-picker-row select {
  min-width: 240px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: #fff;
  font: inherit;
}

.grid-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

.grid-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--panel-border);
  background: linear-gradient(180deg, #fbfcff 0%, #f6f9fd 100%);
}

.name-box {
  min-width: 74px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 6px 10px;
  background: #fff;
  font-family: "Consolas", "SFMono-Regular", monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.formula-bar {
  display: flex;
  align-items: stretch;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.formula-prefix {
  display: grid;
  place-items: center;
  width: 40px;
  flex: 0 0 40px;
  border-right: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.formula-input {
  width: 100%;
  min-height: 34px;
  max-height: 100px;
  padding: 7px 10px;
  border: none;
  resize: vertical;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.35;
}

.formula-input:focus {
  outline: none;
}

.quick-search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #fff;
}

.quick-search-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.quick-search-input {
  min-width: 0;
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.quick-search-input:focus {
  outline: none;
}

.quick-search-clear {
  border: none;
  background: #edf2fb;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.quick-search-clear:hover,
.quick-search-clear:focus-visible {
  background: #dbe7fb;
  color: var(--accent-strong);
  outline: none;
}

.status-bar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  min-width: 0;
}

.grid-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  background: #fff;
}

.print-chrome {
  display: none;
  padding: 8px 14px;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-wrap;
}

.print-surface {
  display: none;
}

.print-document {
  color: #111827;
  background: #ffffff;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.print-document-header,
.print-document-footer {
  color: #475569;
  font-size: 12px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.print-document-header {
  margin-bottom: 8px;
}

.print-document-footer {
  margin-top: 8px;
}

.print-sheet {
  background: #ffffff;
}

.print-sheet-meta {
  margin: 0 0 8px;
  color: #475569;
  font-size: 12px;
  line-height: 1.35;
}

.print-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #ffffff;
}

.print-table thead {
  display: table-header-group;
}

.print-table tbody {
  display: table-row-group;
}

.print-table tr,
.print-table th,
.print-table td {
  break-inside: avoid;
  page-break-inside: avoid;
}

.print-table th,
.print-table td {
  border: 1px solid #d8e1ee;
  padding: 2px 8px;
  color: #172235;
  font-size: 13px;
  line-height: 1.2;
  vertical-align: top;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.print-corner-cell,
.print-row-header {
  width: 36px;
  min-width: 36px;
  background: #f3f6fb;
  color: #475569;
  font-weight: 600;
  text-align: center;
}

.print-header-cell {
  background: #eef4ff;
  color: #172235;
  font-weight: 700;
  text-align: left;
}

.print-data-cell {
  background: #ffffff;
  color: #172235;
}

.floating-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

.floating-panel,
.header-menu {
  pointer-events: auto;
  position: fixed;
  min-width: 280px;
  max-width: min(96vw, 420px);
  padding: 14px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: 0 20px 42px rgba(23, 34, 53, 0.18);
}

.floating-panel {
  top: 72px;
  right: 16px;
  display: grid;
  gap: 12px;
}

.floating-panel-wide {
  max-width: min(96vw, 640px);
}

.floating-panel-header,
.floating-panel-actions,
.inline-row,
.page-setup-grid,
.advanced-filter-condition,
.header-menu-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.floating-panel-header {
  justify-content: space-between;
}

.floating-panel-title {
  margin: 0;
  font-size: 15px;
}

.floating-panel-close,
.link-button,
.mini-button {
  border: none;
  background: transparent;
  color: var(--accent-strong);
  padding: 4px 6px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.floating-panel-close:hover,
.floating-panel-close:focus-visible,
.link-button:hover,
.link-button:focus-visible,
.mini-button:hover,
.mini-button:focus-visible {
  background: #eef4ff;
  outline: none;
}

.floating-panel label,
.advanced-filter-condition label,
.page-setup-grid label,
.header-menu label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.floating-panel input,
.floating-panel select,
.floating-panel textarea,
.header-menu input,
.header-menu select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.floating-panel textarea {
  min-height: 72px;
  resize: vertical;
}

.floating-panel-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.floating-panel-checks label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}

.floating-panel-checks input {
  width: auto;
  padding: 0;
}

.floating-panel-actions {
  justify-content: flex-end;
}

.floating-panel-meta,
.floating-panel-example,
.floating-panel-error,
.header-menu-note {
  margin: 0;
  font-size: 12px;
}

.floating-panel-meta,
.floating-panel-example,
.header-menu-note {
  color: var(--muted);
}

.floating-panel-error {
  color: var(--danger);
  font-weight: 700;
}

.help-panel-section {
  display: grid;
  gap: 6px;
}

.help-panel-heading {
  margin: 0;
  font-size: 13px;
}

.help-panel-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.help-panel-facts {
  display: grid;
  gap: 8px;
}

.help-panel-fact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #f8fbff;
}

.help-panel-fact-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.advanced-filter-list {
  display: grid;
  gap: 10px;
}

.advanced-filter-condition {
  align-items: end;
}

.advanced-filter-number {
  min-width: 28px;
  padding-bottom: 10px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
}

.advanced-filter-condition .grow,
.page-setup-grid .grow {
  flex: 1;
  min-width: 120px;
}

.page-setup-basics > label {
  flex: 1 1 140px;
}

.page-setup-margins {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.import-preview {
  display: grid;
  gap: 8px;
}

.import-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.import-preview-table-wrap {
  overflow: auto;
  max-height: 240px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #fbfcff;
}

.import-preview-table {
  width: 100%;
  border-collapse: collapse;
}

.text-export-preview {
  margin: 0;
  padding: 10px 12px;
  color: var(--text);
  font: 12px/1.45 "Consolas", "SFMono-Regular", monospace;
  white-space: pre-wrap;
}

.import-preview-table td {
  min-width: 96px;
  padding: 8px 10px;
  border: 1px solid #e3eaf4;
  color: var(--text);
  font-size: 12px;
  white-space: pre-wrap;
  vertical-align: top;
}

.advanced-filter-remove {
  margin-left: auto;
}

.page-setup-grid {
  align-items: end;
}

.header-menu {
  display: grid;
  gap: 10px;
  min-width: 260px;
}

.header-menu-actions {
  justify-content: flex-end;
}

.sheet-grid {
  border-collapse: collapse;
  min-width: max-content;
}

.sheet-grid th,
.sheet-grid td {
  border: 1px solid var(--grid-border);
  width: 84px;
  min-width: 84px;
  height: 22px;
  padding: 2px 8px;
  font-size: 13px;
  line-height: 1.2;
}

.corner-cell,
.column-header,
.row-header {
  position: sticky;
  background: var(--grid-header);
  color: #475569;
  font-weight: 600;
  text-align: center;
}

.corner-cell {
  top: 0;
  left: 0;
  z-index: 4;
  min-width: 36px;
  width: 36px;
  background: var(--grid-header-strong);
}

.column-header {
  top: 0;
  z-index: 3;
  background: var(--grid-header-strong);
}

.row-header {
  left: 0;
  z-index: 2;
  min-width: 36px;
  width: 36px;
  background: var(--grid-header);
}

.grid-cell {
  background: #fff;
  color: var(--text);
  cursor: default;
  vertical-align: middle;
  white-space: pre-wrap;
  position: relative;
}

.sheet-grid tr.is-hidden {
  display: none;
}

.grid-spacer-row,
.grid-spacer-cell {
  border: none;
  padding: 0;
  background: transparent;
  pointer-events: none;
}

.grid-spacer-cell {
  height: 0;
  min-width: 0;
}

.grid-spacer-column {
  border: none;
  padding: 0;
  background: transparent;
  pointer-events: none;
}

.grid-cell.is-hidden,
.row-header.is-hidden {
  display: none;
}

.grid-cell.is-selected {
  background: rgba(37, 99, 235, 0.08);
}

.grid-cell.is-fill-preview {
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.1), rgba(37, 99, 235, 0.04));
}

.copied-range-outline {
  position: absolute;
  inset: -2px;
  display: block;
  pointer-events: none;
  z-index: 5;
  border: 0 solid transparent;
  box-sizing: border-box;
}

.copied-range-outline.copy-edge-top {
  border-top-width: 2px;
  border-top-style: dashed;
  border-top-color: #0f7b45;
}

.copied-range-outline.copy-edge-right {
  border-right-width: 2px;
  border-right-style: dashed;
  border-right-color: #0f7b45;
}

.copied-range-outline.copy-edge-bottom {
  border-bottom-width: 2px;
  border-bottom-style: dashed;
  border-bottom-color: #0f7b45;
}

.copied-range-outline.copy-edge-left {
  border-left-width: 2px;
  border-left-style: dashed;
  border-left-color: #0f7b45;
}

.grid-cell.is-active {
  box-shadow: inset 0 0 0 2px var(--active-outline);
}

.grid-cell.is-find-hit {
  box-shadow:
    inset 0 0 0 2px var(--active-outline),
    inset 0 0 0 999px rgba(245, 158, 11, 0.15);
}

.grid-cell.is-formal-header {
  background: linear-gradient(180deg, #f8fbff 0%, #eef4ff 100%);
  font-weight: 700;
}

.row-header.is-selected,
.column-header.is-selected {
  background: #e6efff;
  color: var(--accent-strong);
}

.row-header.is-formal-header {
  background: #dfeaff;
  color: var(--accent-strong);
  font-weight: 700;
}

.cell-editor {
  display: block;
  width: calc(100% + 16px);
  min-height: 22px;
  margin: -2px -8px;
  padding: 2px 8px;
  border: none;
  resize: none;
  overflow: hidden;
  background: #fff;
  color: var(--text);
  font: inherit;
  line-height: 1.2;
}

.cell-editor:focus {
  outline: none;
}

.fill-handle {
  position: absolute;
  right: -4px;
  bottom: -4px;
  z-index: 4;
  width: 8px;
  height: 8px;
  padding: 0;
  border: 1px solid #ffffff;
  border-radius: 2px;
  background: var(--accent);
  cursor: crosshair;
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.28);
}

.header-tools {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 4;
}

.header-tools-button {
  border: none;
  background: #e7ecf5;
  color: #7a8798;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}

.header-tools-button:hover,
.header-tools-button:focus-visible {
  background: #d9e1ee;
  outline: none;
}

.header-tools-button.is-filtered {
  background: rgba(37, 99, 235, 0.12);
  color: var(--accent-strong);
}

.header-tools-button.is-filtered:hover,
.header-tools-button.is-filtered:focus-visible {
  background: rgba(37, 99, 235, 0.18);
}

@media print {
  html,
  body.is-printing-light-table {
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  body.is-printing-light-table > :not(#printSurface) {
    display: none !important;
  }

  body.is-printing-light-table #printSurface {
    display: block !important;
    overflow: visible !important;
    padding: 0;
    margin: 0;
  }

  body.is-printing-light-table #printSurface,
  body.is-printing-light-table #printSurface * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

@media (max-width: 900px) {
  .sheet-picker-bar,
  .status-bar,
  .sheet-picker-row,
  .menu-bar,
  .grid-toolbar,
  .quick-search,
  .floating-panel-actions,
  .page-setup-grid,
  .advanced-filter-condition {
    flex-direction: column;
    align-items: stretch;
  }

  .menu-bar {
    padding: 8px;
  }

  .icon-toolbar {
    padding: 8px;
  }

  .menu-dropdown {
    left: 8px;
    right: 8px;
    min-width: 0;
  }

  .sheet-picker-row select {
    min-width: 0;
    width: 100%;
  }

  .name-box {
    width: 100%;
  }

  .formula-bar {
    width: 100%;
  }

  .quick-search {
    min-width: 0;
    width: 100%;
  }

  .page-setup-margins {
    grid-template-columns: 1fr;
  }

  .floating-panel,
  .header-menu {
    left: 8px !important;
    right: 8px !important;
    top: auto;
    bottom: 8px;
    max-width: none;
  }
}
