* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Calibri, Arial, sans-serif; font-size: 13px; background: #f0f0f0; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* Toolbar */
#toolbar { background: #217346; color: white; padding: 6px 12px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
#toolbar h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.5px; }
#toolbar .help { font-size: 11px; opacity: 0.85; margin-left: auto; }
#toolbar .help span { background: rgba(255,255,255,0.15); padding: 2px 6px; border-radius: 3px; margin-left: 4px; }

/* Format bar */
#format-bar { background: #fafafa; border-bottom: 1px solid #d0d0d0; display: flex; align-items: center; gap: 3px; padding: 3px 8px; flex-shrink: 0; }
.fmt-btn { border: 1px solid #ccc; background: #f5f5f5; padding: 2px 8px; font-size: 13px; font-family: inherit; cursor: pointer; border-radius: 3px; color: #333; min-width: 28px; line-height: 18px; }
.fmt-btn:hover { background: #e8e8e8; }
.fmt-btn.active { background: #d9e8f5; border-color: #217346; color: #217346; }
#fmt-bold { font-weight: 700; }
#fmt-italic { font-style: italic; }
.fmt-separator { width: 1px; height: 18px; background: #d0d0d0; margin: 0 3px; }
#fmt-numfmt { border: 1px solid #ccc; background: #f5f5f5; padding: 2px 6px; font-size: 12px; font-family: inherit; cursor: pointer; border-radius: 3px; color: #333; outline: none; }
#fmt-numfmt:hover { background: #e8e8e8; }

/* Formula bar */
#formula-bar { background: #fff; border-bottom: 1px solid #d0d0d0; display: flex; align-items: center; gap: 0; flex-shrink: 0; }
#cell-name-box { width: 80px; border: none; border-right: 1px solid #d0d0d0; padding: 5px 8px; font-size: 13px; font-family: inherit; text-align: center; background: #f8f8f8; font-weight: 600; color: #333; outline: none; }
#fx-label { padding: 0 8px; color: #888; font-style: italic; font-size: 13px; border-right: 1px solid #d0d0d0; }
#formula-input { flex: 1; border: none; padding: 5px 10px; font-size: 13px; font-family: 'Consolas', monospace; outline: none; color: #1a1a1a; }
#formula-input:focus { background: #fffde7; }

/* Grid wrapper */
#grid-wrapper { flex: 1; overflow: auto; }

/* Table */
table { border-collapse: collapse; table-layout: fixed; }
th, td { border: 1px solid #d0d0d0; }

/* Corner cell */
.corner { width: 50px; min-width: 50px; background: #f5f5f5; border: 1px solid #ccc; position: sticky; top: 0; left: 0; z-index: 4; }

/* Column headers */
.col-header { background: #f5f5f5; text-align: center; padding: 4px 0; font-weight: 600; color: #444; font-size: 12px; position: sticky; top: 0; z-index: 3; user-select: none; overflow: hidden; }
.col-header.selected { background: #d9e8f5; color: #1a6fa8; }

/* Row headers */
.row-header { background: #f5f5f5; text-align: center; padding: 4px 2px; font-weight: 600; color: #444; font-size: 12px; width: 50px; min-width: 50px; position: sticky; left: 0; z-index: 2; user-select: none; overflow: hidden; }
.row-header.selected { background: #d9e8f5; color: #1a6fa8; }

/* Resize handles */
.col-resize-handle { position: absolute; right: 0; top: 0; bottom: 0; width: 5px; cursor: col-resize; z-index: 10; }
.col-resize-handle:hover, .col-resize-handle:active { background: #217346; opacity: 0.5; }
.row-resize-handle { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; cursor: row-resize; z-index: 10; }
.row-resize-handle:hover, .row-resize-handle:active { background: #217346; opacity: 0.5; }

/* Data cells */
td.cell { padding: 0; height: 22px; position: relative; overflow: hidden; }
td.cell.selected { outline: 2px solid #217346; outline-offset: -2px; background: #f0f7f2; z-index: 1; }
td.cell.in-selection { background: #ddefdd; }
td.cell .display { display: block; width: 100%; height: 100%; padding: 2px 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: cell; line-height: 18px; }
td.cell .display.number { text-align: right; }
td.cell .display.error { color: #c00; font-size: 11px; }
td.cell .display.bold { font-weight: 600; }
td.cell .display.italic { font-style: italic; }
td.cell input.editor { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: none; padding: 2px 6px; font-family: 'Consolas', monospace; font-size: 13px; background: #fff; outline: 2px solid #217346; outline-offset: -2px; z-index: 5; }
td.cell.pointing { outline: 2px dashed #1a73e8 !important; outline-offset: -2px; z-index: 2; }
td.cell.pointing-range { background: rgba(26,115,232,0.10) !important; }

/* Status bar */
#status-bar { background: #f0f0f0; border-top: 1px solid #ccc; padding: 3px 12px; font-size: 12px; color: #555; display: flex; gap: 20px; flex-shrink: 0; }
#status-bar .stat { font-weight: 600; color: #333; }

/* Sheet tabs */
#sheet-tabs { background: #e0e0e0; border-top: 1px solid #ccc; display: flex; align-items: stretch; flex-shrink: 0; overflow-x: auto; }
.sheet-tab { display: flex; align-items: center; gap: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; border-right: 1px solid #ccc; white-space: nowrap; user-select: none; color: #555; background: #e0e0e0; }
.sheet-tab:hover { background: #d4d4d4; }
.sheet-tab.active { background: #fff; color: #217346; font-weight: 600; border-top: 2px solid #217346; }
.sheet-tab-label { pointer-events: none; }
.sheet-tab-delete { font-size: 14px; line-height: 1; color: #999; padding: 0 2px; border-radius: 3px; }
.sheet-tab-delete:hover { background: #c00; color: #fff; }
.sheet-add { background: none; border: none; border-right: 1px solid #ccc; padding: 4px 10px; font-size: 16px; color: #777; cursor: pointer; line-height: 1; }
.sheet-add:hover { color: #217346; background: #d4d4d4; }

/* Footer */
#footer { background: #e8e8e8; border-top: 1px solid #ccc; padding: 3px 12px; font-size: 11px; color: #999; text-align: center; flex-shrink: 0; }

/* App back-link (in toolbar) */
.app-nav-back { color: rgba(255,255,255,0.75); font-size: 12px; text-decoration: none; padding: 2px 8px 2px 0; border-right: 1px solid rgba(255,255,255,0.25); margin-right: 8px; white-space: nowrap; flex-shrink: 0; }
.app-nav-back:hover { color: #fff; }

/* Accessibility */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
