.bce-app {
  --bce-app-width: 100vw;
  --bce-app-height: 100dvh;
  --bce-app-max-width: none;
  --bce-app-margin-inline: calc(50% - 50vw);
  --bce-app-margin-block: 0;
  --bce-app-padding: 18px;
  --bce-grid-min-height: 280px;
  --bce-border: #d8deea;
  --bce-border-strong: #aeb8c8;
  --bce-soft: #f5f7fb;
  --bce-text: #172033;
  --bce-muted: #667085;
  --bce-accent: #2563eb;
  --bce-accent-dark: #1d4ed8;
  --bce-danger: #b42318;
  --bce-danger-soft: #fff1f0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: var(--bce-app-width);
  height: var(--bce-app-height);
  min-height: 520px;
  max-width: var(--bce-app-max-width);
  margin-block: var(--bce-app-margin-block);
  margin-inline: var(--bce-app-margin-inline);
  padding: var(--bce-app-padding);
  overflow: hidden;
  color: var(--bce-text);
  background: #f8fafc;
  border: 0;
  border-radius: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

.admin-bar .bce-app { --bce-app-height: calc(100dvh - 32px); }
.bce-app[hidden], .bce-app [hidden] { display: none !important; }
.bce-app *, .bce-app *::before, .bce-app *::after { box-sizing: border-box; }
.bce-app svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.bce-topbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 0 2px 14px;
}
.bce-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bce-logo {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 8px 22px rgba(37, 99, 235, .24);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
}
.bce-title { margin: 0 0 2px; font-size: clamp(20px, 2vw, 26px); line-height: 1.25; }
.bce-privacy { margin: 0; overflow: hidden; color: #59657a; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.bce-topbar-actions, .bce-plan-wrap { display: flex; align-items: center; gap: 9px; }
.bce-language-control { display: inline-flex; align-items: center; gap: 7px; color: var(--bce-muted); font-size: 12px; font-weight: 650; }
.bce-language-control select {
  min-height: 34px;
  padding: 4px 30px 4px 10px;
  border: 1px solid var(--bce-border);
  border-radius: 999px;
  background: #fff;
  color: var(--bce-text);
  font: inherit;
}
.bce-plan { display: inline-flex; padding: 5px 11px; border-radius: 999px; font-size: 12px; font-weight: 750; }
.bce-plan--free { background: #eef1f6; color: #455268; }
.bce-plan--pro { background: #fff1c7; color: #724b00; }
.bce-upgrade { color: var(--bce-accent); font-size: 13px; font-weight: 750; text-decoration: none; }

.bce-controls {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--bce-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 8px 25px rgba(20, 31, 55, .05);
}
.bce-toolbar-separator { width: 1px; height: 24px; margin: 0 2px; background: var(--bce-border); }
.bce-btn, .bce-file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid #b8c2d1;
  border-radius: 9px;
  background: #fff;
  color: #24324a;
  font: inherit;
  font-size: 13px;
  font-weight: 680;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease, transform .15s ease;
}
.bce-btn:hover:not(:disabled), .bce-file-label:hover { border-color: var(--bce-accent); color: var(--bce-accent); transform: translateY(-1px); }
.bce-btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.bce-file-label, .bce-btn--primary { border-color: var(--bce-accent); color: #fff; background: var(--bce-accent); }
.bce-file-label:hover, .bce-btn--primary:hover:not(:disabled) { color: #fff; background: var(--bce-accent-dark); }
.bce-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }

.bce-settings {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(360px, .85fr) minmax(520px, 1.4fr);
  gap: 10px;
  align-items: start;
  margin-top: 10px;
}
.bce-general-options {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: end;
  padding: 11px;
  border: 1px solid var(--bce-border);
  border-radius: 13px;
  background: #fff;
}
.bce-field { display: inline-flex; flex-direction: column; gap: 4px; color: #59657a; font-size: 11px; font-weight: 700; }
.bce-field select, .bce-field input, .bce-encoding-card select, .bce-replace-label input {
  min-height: 36px;
  border: 1px solid #bdc6d5;
  border-radius: 8px;
  background: #fff;
  padding: 5px 9px;
  color: var(--bce-text);
  font: inherit;
  font-size: 13px;
}
.bce-field select:focus, .bce-field input:focus, .bce-encoding-card select:focus, .bce-replace-label input:focus {
  outline: none;
  border-color: var(--bce-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
.bce-check-field { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; color: #455268; font-size: 12px; font-weight: 650; }
.bce-check-field input { margin: 0; }
.bce-search-wrap { flex: 1 1 180px; min-width: 160px; }
.bce-search-box { position: relative; display: block; }
.bce-search-box svg { position: absolute; top: 50%; left: 9px; width: 15px; height: 15px; color: #7a8699; transform: translateY(-50%); pointer-events: none; }
.bce-search { width: 100%; padding-left: 31px !important; }

.bce-encoding-drawer {
  min-width: 0;
  border: 1px solid var(--bce-border);
  border-radius: 13px;
  background: #fff;
  overflow: hidden;
}
.bce-encoding-drawer > summary {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  color: #455268;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  list-style: none;
}
.bce-encoding-drawer > summary::-webkit-details-marker { display: none; }
.bce-summary-icon { display: inline-grid; place-items: center; width: 27px; height: 27px; border-radius: 7px; background: #eef4ff; color: var(--bce-accent); font-size: 11px; }
.bce-encoding-panel { display: grid; grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr); gap: 7px; align-items: center; padding: 10px; }
.bce-encoding-card {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #e0e5ee;
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #fbfcff);
}
.bce-encoding-title { color: #3a465a; font-size: 11px; font-weight: 780; }
.bce-encoding-card select { width: 100%; }
.bce-encoding-note { min-height: 2.8em; color: #748094; font-size: 10px; line-height: 1.4; }
.bce-encoding-arrow { display: grid; place-items: center; color: #8a96a9; font-size: 18px; }

.bce-pro-tools { flex: 0 0 auto; margin-top: 8px; }
.bce-pro-panel { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 9px 10px; border: 1px solid #ead18c; border-radius: 11px; background: #fffbeb; }
.bce-pro-panel strong { margin-right: 2px; font-size: 12px; }
.bce-pro-locked { padding: 9px 11px; border-radius: 10px; background: #f5f2ff; color: #514575; font-size: 12px; }
.bce-pro-locked__link { margin-left: 8px; white-space: nowrap; }
.bce-pro-locked a { color: #5b45b0; font-weight: 750; }
.bce-replace-label { display: inline-flex; gap: 5px; align-items: center; color: #59657a; font-size: 11px; font-weight: 650; }
.bce-replace-label input { width: 130px; min-height: 34px; }

.bce-status {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 11px;
  margin-top: 8px;
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--bce-accent);
  border-radius: 9px;
  background: #eff6ff;
  font-size: 12px;
}
.bce-status--error { border-color: #fecdca; border-left-color: var(--bce-danger); background: var(--bce-danger-soft); color: #7a271a; }
.bce-progress { flex: 0 0 auto; height: 6px; overflow: hidden; margin-top: 5px; border-radius: 999px; background: #e8edf5; }
.bce-progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #2563eb, #7c3aed); transition: width .15s linear; }

.bce-workspace { position: relative; flex: 1 1 auto; min-height: var(--bce-grid-min-height); margin-top: 8px; overflow: hidden; }
.bce-grid-shell { position: relative; width: 100%; height: 100%; border: 1px solid var(--bce-border-strong); border-radius: 12px; overflow: hidden; background: #fff; box-shadow: 0 10px 30px rgba(20, 31, 55, .07); }
.bce-grid { position: relative; width: 100%; height: 100%; min-height: 0; overflow: auto; background: #fff; contain: strict; }
.bce-grid-surface { position: relative; min-width: 100%; }
.bce-grid-header, .bce-grid-row { display: grid; }
.bce-grid-header { position: sticky; top: 0; z-index: 5; height: 42px; background: #eef2f7; border-bottom: 1px solid var(--bce-border-strong); box-shadow: 0 2px 5px rgba(20, 31, 55, .05); }
.bce-grid-row { position: absolute; left: 0; height: 36px; background: #fff; }
.bce-grid-row:nth-child(even) { background: #fbfcfe; }
.bce-grid-corner, .bce-header-cell, .bce-row-number, .bce-grid-cell { min-width: 0; height: 100%; border-right: 1px solid var(--bce-border); border-bottom: 1px solid var(--bce-border); }
.bce-grid-corner { position: sticky; left: 0; z-index: 7; display: flex; align-items: center; justify-content: center; background: #e8edf5; font-size: 11px; font-weight: 750; }
.bce-header-cell { display: flex; align-items: center; gap: 4px; padding: 4px; background: #eef2f7; }
.bce-header-input, .bce-cell-input { width: 100%; min-width: 0; height: 100%; border: 1px solid transparent; border-radius: 4px; background: transparent; padding: 4px 6px; color: inherit; font: inherit; font-size: 13px; }
.bce-header-input { font-weight: 750; }
.bce-header-input:focus, .bce-cell-input:focus { outline: none; border-color: var(--bce-accent); background: #fff; box-shadow: inset 0 0 0 1px var(--bce-accent); }
.bce-sort { flex: 0 0 28px; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: #627089; cursor: pointer; }
.bce-sort:hover { background: #dce4ef; color: #172033; }
.bce-row-number { position: sticky; left: 0; z-index: 3; display: flex; align-items: center; gap: 5px; padding: 0 6px; background: #f3f6fa; font-size: 11px; color: #5d697d; }
.bce-row-number input { margin: 0; }
.bce-grid-cell { padding: 2px; }

.bce-row-actions {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(148, 163, 184, .45);
  border-radius: 14px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 14px 35px rgba(15, 23, 42, .18);
  backdrop-filter: blur(12px);
}
.bce-selection-count { max-width: 130px; padding: 0 7px; overflow: hidden; color: #667085; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.bce-row-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: #eef4ff;
  color: #1d4ed8;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.bce-row-action:hover:not(:disabled) { background: #dbeafe; transform: translateY(-1px); }
.bce-row-action:disabled { opacity: .38; cursor: not-allowed; }
.bce-row-action--danger { background: #fff1f0; color: var(--bce-danger); }
.bce-row-action--danger:hover:not(:disabled), .bce-row-actions--selected .bce-row-action--danger { background: #fee4e2; }

.bce-limits { flex: 0 0 auto; margin: 6px 2px 0; color: #667085; font-size: 10px; text-align: right; }
.bce-app[dir="rtl"] .bce-search-box svg { right: 9px; left: auto; }
.bce-app[dir="rtl"] .bce-search { padding-right: 31px !important; padding-left: 9px !important; }
.bce-app[dir="rtl"] .bce-row-actions { right: auto; left: 18px; }

@media (max-width: 1100px) {
  .bce-settings { grid-template-columns: 1fr; }
  .bce-encoding-drawer > summary { display: flex; }
  .bce-encoding-drawer:not([open]) .bce-encoding-panel { display: none; }
}

@media (max-width: 782px) {
  .admin-bar .bce-app { --bce-app-height: calc(100dvh - 46px); }
  .bce-app { --bce-app-padding: 10px; min-height: 480px; }
  .bce-topbar { align-items: flex-start; }
  .bce-privacy { max-width: 50vw; }
  .bce-topbar-actions { flex-direction: column; align-items: flex-end; gap: 5px; }
  .bce-language-control > span { display: none; }
  .bce-controls { padding: 8px; }
  .bce-btn, .bce-file-label { padding-inline: 10px; }
  .bce-toolbar-separator { display: none; }
  .bce-general-options { align-items: stretch; }
  .bce-field, .bce-search-wrap { flex: 1 1 140px; }
  .bce-encoding-panel { grid-template-columns: 1fr; }
  .bce-encoding-arrow { transform: rotate(90deg); }
  .bce-encoding-note { min-height: auto; }
  .bce-row-actions { right: 10px; bottom: 10px; max-width: calc(100% - 20px); }
  .bce-selection-count { display: none; }
  .bce-row-action span { display: none; }
  .bce-row-action { width: 42px; justify-content: center; padding: 7px; }
}

@media (max-width: 480px) {
  .bce-logo { display: none; }
  .bce-title { font-size: 20px; }
  .bce-privacy { max-width: 58vw; font-size: 10px; }
  .bce-controls { flex-wrap: nowrap; overflow-x: auto; }
  .bce-controls > * { flex: 0 0 auto; }
  .bce-pro-tools { display: none; }
}

/* Spreadsheet interaction layer (v0.3+) */
.bce-app {
  --bce-row-height: 36px;
  --bce-header-height: 44px;
  --bce-row-number-width: 72px;
  --bce-column-width: 170px;
  --bce-selection: #2563eb;
  --bce-selection-fill: rgba(37, 99, 235, .10);
  --bce-selection-fill-strong: rgba(37, 99, 235, .17);
}
.bce-sheet-hint {
  flex: 0 0 auto;
  margin: 7px 2px 0;
  color: #68758a;
  font-size: 11px;
  line-height: 1.4;
}
.bce-grid { direction: ltr; user-select: none; }
.bce-grid-header { height: var(--bce-header-height); }
.bce-grid-row { height: var(--bce-row-height); }
.bce-grid-corner,
.bce-row-number {
  appearance: none;
  margin: 0;
  border-top: 0;
  border-left: 0;
  border-radius: 0;
  font: inherit;
  cursor: pointer;
}
.bce-grid-corner:hover,
.bce-row-number:hover { background: #dce6f4; color: #1d4ed8; }
.bce-header-cell {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 28px;
  gap: 3px;
  padding: 4px 3px;
  transition: background .1s ease;
}
.bce-header-cell--selected { background: #dbeafe; }
.bce-column-selector {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: #e3eaf4;
  color: #4a586e;
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  cursor: ew-resize;
}
.bce-column-selector:hover,
.bce-header-cell--selected .bce-column-selector { background: #bfdbfe; color: #1d4ed8; }
.bce-header-input { padding-inline: 5px; }
.bce-row-number {
  justify-content: flex-end;
  padding: 0 10px 0 5px;
  cursor: ns-resize;
  font-variant-numeric: tabular-nums;
}
.bce-row-number--selected { background: #dbeafe; color: #1d4ed8; font-weight: 800; }
.bce-grid-cell {
  position: relative;
  cursor: cell;
  background: inherit;
  transition: background .06s linear;
}
.bce-cell-input[readonly] {
  cursor: cell;
  user-select: none;
  caret-color: transparent;
}
.bce-grid-cell--selected { background: var(--bce-selection-fill); }
.bce-grid-cell--active { background: var(--bce-selection-fill-strong); }
.bce-grid-cell--fill-preview { background: rgba(14, 165, 233, .10); }
.bce-selection-edge--top { box-shadow: inset 0 2px 0 var(--bce-selection); }
.bce-selection-edge--bottom { box-shadow: inset 0 -2px 0 var(--bce-selection); }
.bce-selection-edge--left { border-left: 2px solid var(--bce-selection); }
.bce-selection-edge--right { border-right: 2px solid var(--bce-selection); }
.bce-grid-cell--editing {
  z-index: 8;
  background: #fff;
  box-shadow: inset 0 0 0 2px var(--bce-selection), 0 4px 14px rgba(37, 99, 235, .18);
}
.bce-grid-cell--editing .bce-cell-input {
  cursor: text;
  user-select: text;
  caret-color: auto;
  background: #fff;
}
.bce-fill-handle {
  position: absolute;
  right: -5px;
  bottom: -5px;
  z-index: 12;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--bce-selection);
  box-shadow: 0 1px 4px rgba(15, 23, 42, .35);
  cursor: crosshair;
  touch-action: none;
}
.bce-sheet-actions {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: min(560px, calc(100% - 380px));
  padding: 6px;
  border: 1px solid rgba(148, 163, 184, .45);
  border-radius: 14px;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 14px 35px rgba(15, 23, 42, .16);
  backdrop-filter: blur(12px);
}
.bce-range-summary {
  min-width: 150px;
  max-width: 260px;
  padding: 0 8px;
  overflow: hidden;
  color: #536177;
  font-size: 11px;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bce-sheet-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 10px;
  border: 0;
  border-radius: 9px;
  background: #eef4ff;
  color: #1d4ed8;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}
.bce-sheet-action:hover:not(:disabled) { background: #dbeafe; }
.bce-sheet-action:disabled { opacity: .38; cursor: not-allowed; }
.bce-sheet-action svg { width: 16px; height: 16px; }
.bce-app[dir="rtl"] .bce-sheet-actions { right: 18px; left: auto; }
.bce-app[dir="rtl"] .bce-row-actions { right: auto; left: 18px; }
.bce-app[dir="rtl"] .bce-grid { direction: ltr; }
.bce-app[dir="rtl"] .bce-cell-input { direction: auto; text-align: start; }

@media (max-width: 900px) {
  .bce-sheet-hint { display: none; }
  .bce-sheet-actions { left: 10px; bottom: 62px; max-width: calc(100% - 20px); }
  .bce-range-summary { min-width: 0; max-width: 170px; }
  .bce-app[dir="rtl"] .bce-sheet-actions { right: 10px; left: auto; }
}
@media (max-width: 560px) {
  .bce-sheet-actions { padding: 5px; }
  .bce-range-summary { max-width: 130px; }
  .bce-sheet-action span { display: none; }
  .bce-sheet-action { width: 38px; padding: 6px; }
}
