.sheet-container { max-width: 100%; height: min(70vh, 720px); overflow: auto; border: 1px solid #cbd2de; background: white; }
.sheet-grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; width: max-content; font-size: 14px; }
.sheet-grid th, .sheet-grid td { height: 28px; padding: 3px 7px; border-right: 1px solid #e2e6ed; border-bottom: 1px solid #e2e6ed; }
.sheet-grid th { background: #f3f5f8; color: #647084; font-weight: 400; text-align: center; user-select: none; }
.sheet-grid td { position: relative; min-width: 120px; max-width: 120px; overflow: hidden; white-space: pre; }
.sheet-grid .sheet-selected { outline: 2px solid #285ccc; outline-offset: -2px; background: #f5f8ff; }
.sheet-cell-input { display: block; position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); margin: 0; padding: 1px 5px; border: 0; border-radius: 0; outline: none; resize: none; overflow: hidden; background: transparent; color: inherit; font: inherit; white-space: pre; }
.sheet-hint, .sheet-status { font-size: 13px; color: #7b8492; }
.sheet-grid thead th { padding: 0; height: 32px; white-space: nowrap; }
.sheet-grid .sheet-sort-button, .sheet-grid .sheet-filter-button { padding: 5px 8px; border-radius: 0; font: inherit; text-align: center; }
.sheet-grid .sheet-sort-button { min-width: 65px; }
.sheet-grid th[aria-sort="ascending"], .sheet-grid th[aria-sort="descending"] { color: #285ccc; background: #e6edff; }
.sheet-grid .sheet-filter-button { color: #647084; border-left: 1px solid #dce2ec; }
.sheet-grid .sheet-filter-active { color: #fff; background: #285ccc; }
.sheet-grid .sheet-filter-active:hover { background: #194ab5; }
.sheet-empty { margin: 24px; font-size: 14px; }
.sheet-filter-dialog { width: min(390px, 90vw); padding: 24px; border: 1px solid #cbd2de; border-radius: 10px; color: #242b38; box-shadow: 0 16px 48px #15243d33; }
.sheet-filter-dialog::backdrop { background: #17223755; }
.sheet-filter-dialog h2 { margin: 0 0 20px; font-size: 18px; }
.sheet-filter-dialog label { display: grid; gap: 6px; margin-bottom: 16px; font-size: 14px; }
.sheet-filter-dialog input, .sheet-filter-dialog select { width: 100%; padding: 9px; border: 1px solid #bdc7d7; border-radius: 4px; color: inherit; background: white; font: inherit; }
.sheet-filter-dialog p { font-size: 13px; }
.sheet-filter-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 20px; }
.sheet-filter-actions button { padding: 8px 12px; font-size: 14px; }
.sheet-filter-actions button[type="submit"] { background: #285ccc; color: white; }
.sheet-toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.sheet-freeze-menu { position: relative; z-index: 20; }
.sheet-freeze-menu summary { cursor: pointer; padding: 7px 12px; border: 1px solid #cbd2de; border-radius: 5px; background: #f6f7f9; font-size: 14px; }
.sheet-freeze-menu summary:focus-visible { outline: 2px solid #285ccc; outline-offset: 2px; }
.sheet-freeze-options { position: absolute; top: calc(100% + 4px); left: 0; width: 150px; padding: 4px; background: white; border: 1px solid #cbd2de; border-radius: 6px; box-shadow: 0 4px 12px #15243d22; }
.sheet-freeze-options button { display: block; width: 100%; padding: 8px 12px; font-size: 14px; }
.sheet-freeze-status { color: #647084; font-size: 13px; }
.sheet-grid .sheet-frozen { position: sticky; z-index: 2; background: #fff; background-clip: border-box; }
.sheet-grid th.sheet-frozen { background: #f3f5f8; }
.sheet-grid .sheet-frozen-row.sheet-frozen-col { z-index: 4; }
.sheet-grid thead .sheet-frozen { z-index: 5; }
.sheet-grid thead .sheet-frozen-row.sheet-frozen-col { z-index: 7; }
.sheet-grid th.sheet-frozen[aria-sort="ascending"], .sheet-grid th.sheet-frozen[aria-sort="descending"] { background: #e6edff; }
.sheet-grid .sheet-frozen.sheet-selected { background: #f5f8ff; }
.sheet-context-menu { position: fixed; z-index: 100; min-width: 160px; padding: 4px; border: 1px solid #cbd2de; border-radius: 6px; background: white; box-shadow: 0 6px 20px #15243d33; }
.sheet-context-menu button { display: block; width: 100%; padding: 9px 14px; border-radius: 3px; font-size: 14px; }
.sheet-context-menu .sheet-menu-danger { color: #b42318; }
.sheet-delete-dialog { width: min(410px, 90vw); padding: 24px; border: 1px solid #cbd2de; border-radius: 10px; color: #242b38; box-shadow: 0 16px 48px #15243d33; }
.sheet-delete-dialog::backdrop { background: #17223755; }
.sheet-delete-dialog h2 { margin: 0 0 16px; font-size: 18px; }
.sheet-delete-dialog p { color: #525e70; font-size: 14px; }
.sheet-delete-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.sheet-delete-actions button { padding: 8px 14px; font-size: 14px; }
.sheet-delete-actions .sheet-delete-confirm { background: #b42318; color: white; }
.sheet-grid th[data-row], .sheet-grid th[data-sheet-corner] { cursor: context-menu; }
.sheet-grid th[data-row]:focus-visible, .sheet-grid th[data-sheet-corner]:focus-visible { outline: 2px solid #285ccc; outline-offset: -2px; }
/* UI-3: old sheet ribbon, two rows, retaining the glass variables. */
#sheets .sheet-toolbar { display:flex; flex-direction:column; align-items:stretch; gap:4px; margin:0; padding:8px 10px; border:1px solid var(--line); border-bottom:0; border-radius:var(--r-sm) var(--r-sm) 0 0; background:var(--col-bg); backdrop-filter:blur(var(--blur)); }
#sheets .sheet-tool-row { display:flex; align-items:center; gap:6px; min-height:32px; flex-wrap:wrap; }
#sheets .sheet-tool-row button { padding:6px 9px; font-size:13px; white-space:nowrap; }
#sheets .sheet-tool-row button:disabled { opacity:.35; cursor:default; }
#sheets .sheet-tool-row select { width:auto; min-width:64px; height:30px; padding:3px 6px; font:inherit; font-size:13px; border:1px solid var(--field-bd); }
#sheets #gridFont { width:122px; }
#sheets #gridSize { width:64px; }
#sheets .sheet-address { width:100px; min-width:0; height:30px; padding:4px 8px; font:13px Arial,sans-serif; border:1px solid var(--field-bd); }
#sheets .sheet-color { display:inline-flex; align-items:center; gap:3px; padding:3px 5px; font-size:14px; }
#sheets .sheet-color input { width:22px; height:24px; padding:0; border:0; cursor:pointer; }
#sheets [data-grid-style="bold"] { font-weight:700; }
#sheets [data-grid-style="italic"] { font-style:italic; }
#sheets [data-grid-style="underline"] { text-decoration:underline; }
#sheets [data-grid-style="strike"] { text-decoration:line-through; }
#sheets .sheet-freeze-menu summary { border:0; padding:6px 9px; background:transparent; }
#sheets .sheet-freeze-options { z-index:25; }
#sheets .sheet-freeze-status { margin-left:auto; font-size:12px; }
#sheets .sheet-container { height:min(64vh,720px); border-radius:0; }
#sheets .sheet-grid td { min-width:0; max-width:none; white-space:pre-wrap; vertical-align:middle; cursor:cell; user-select:none; }
#sheets .sheet-grid .sheet-selected { outline:2px solid var(--accent); outline-offset:-2px; }
#sheets .sheet-cell-text { white-space:inherit; overflow-wrap:anywhere; }
#sheets .sheet-cell-input { z-index:3; resize:none; text-align:inherit; text-decoration:inherit; color:inherit; font:inherit; white-space:pre-wrap; cursor:text; user-select:text; background:var(--card-bg); }
#sheets .sheet-input-idle { opacity:0; pointer-events:none; }
#sheets .sheet-fill-handle { display:block; position:absolute; right:0; bottom:0; width:7px; height:7px; background:var(--accent); border:1px solid var(--card-bg); cursor:crosshair; z-index:5; }
#sheets .sheet-bottom-status { display:flex; align-items:center; gap:6px; padding:5px 10px; border:1px solid var(--line); border-top:0; background:var(--col-bg); font-size:12px; }
#sheets .grid-selection-info { margin-right:auto; color:var(--tx-sub); }
#sheets .sheet-bottom-status button { padding:4px 8px; font-size:12px; }
#sheets .sheet-toolbar { position:relative; z-index:30; }
/* UI-4: independent worksheet tabs and legacy advanced dialogs. */
#sheets .worksheet-tabs { display:flex; align-items:center; gap:3px; overflow:auto; padding:5px 8px; border:1px solid var(--line); border-top:0; background:var(--col-bg); }
#sheets .worksheet-tabs button { flex:none; padding:8px 15px; font-size:13px; border-radius:var(--r-xs); }
#sheets .worksheet-tab[aria-pressed="true"] { box-shadow:inset 0 -2px var(--accent); }
#sheets .sheet-notice { margin:0; padding:7px 12px; color:var(--red); font-size:13px; background:var(--panel-bg); border-inline:1px solid var(--line); }
#sheets .sheet-notice:empty { display:none; }
#sheets .sheet-column-button { min-width:48px; text-align:center; padding:5px; }
#sheets .sheet-sort-button { min-width:24px; padding:5px 3px; }
#sheets .sheet-validation-arrow { position:absolute; right:2px; top:2px; width:20px; height:22px; padding:0; text-align:center; border-radius:var(--r-xs); background:var(--accent-soft); color:var(--accent); z-index:6; font-size:12px; }
#sheets .sheet-has-validation .sheet-cell-text { padding-right:20px; }
#sheets .sheet-has-validation .sheet-cell-input { width:calc(100% - 25px); }
#sheets .sheet-find-match { box-shadow:inset 0 0 0 2px var(--amber); }
#sheets .sheet-find-current { box-shadow:inset 0 0 0 3px var(--accent); }
.sheet-advanced-dialog { width:min(460px,calc(100vw - 32px)); max-height:90vh; overflow:auto; padding:24px; border:1px solid var(--line); border-radius:var(--r); color:var(--tx); background:var(--panel-bg); box-shadow:var(--sh-pop); }
.sheet-advanced-dialog::backdrop { background:#17253d66; }
.sheet-advanced-dialog h2 { margin:0 0 20px; font-size:18px; }
.sheet-advanced-dialog label { display:grid; gap:7px; margin-bottom:16px; font-size:14px; color:var(--tx-sub); }
.sheet-advanced-dialog label:has(input[type="checkbox"]) { display:flex; align-items:center; }
.sheet-advanced-dialog :is(input:not([type="checkbox"]),select,textarea) { width:100%; padding:8px; border:1px solid var(--field-bd); border-radius:var(--r-xs); color:var(--tx); background:var(--field-bg); font:inherit; }
.sheet-advanced-dialog input[type="color"] { height:36px; padding:3px; }
.sheet-advanced-dialog p { font-size:13px; line-height:1.6; }
.sheet-dialog-actions { display:flex; justify-content:flex-end; flex-wrap:wrap; gap:6px; margin-top:18px; }
.sheet-dialog-actions button { padding:8px 12px; font-size:13px; border:1px solid var(--line); }
.sheet-dialog-actions button[type="submit"] { background:var(--accent-soft); color:var(--accent); }
.sheet-validation-menu { z-index:100; max-height:240px; overflow:auto; }
