* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #1f2430;
  background: #f4f5f7;
}

body {
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: #232936;
  color: #eef1f6;
  flex: 0 0 auto;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: 0.5px; }
.doc-nav { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; min-width: 0; }
.doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #c8d0e0;
}
.toolbar { display: flex; gap: 6px; flex: 0 0 auto; }

button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid #4a5468;
  border-radius: 4px;
  background: #333c4f;
  color: #eef1f6;
  cursor: pointer;
}
button:hover { background: #414c63; }
button:disabled { opacity: 0.45; cursor: default; }
.doc-list-view button {
  background: #3b6ea5;
  border-color: #3b6ea5;
  color: #fff;
}
.doc-list-view button:hover { background: #4a7fbb; }

/* Conflict banner */
.conflict-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #b3261e;
  color: #fff;
  flex: 0 0 auto;
}
.conflict-banner button {
  background: #fff;
  color: #b3261e;
  border-color: #fff;
}
.conflict-banner button:hover { background: #ffe9e7; }

/* Document list view */
.doc-list-view {
  flex: 1 1 auto;
  overflow: auto;
  padding: 24px;
}
.doc-list-view h1 { margin-top: 0; }
.doc-list-view ul { list-style: none; margin: 12px 0; padding: 0; }
.doc-list-view li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #d6dae2;
  border-radius: 6px;
  margin-bottom: 6px;
}
.doc-list-view li .doc-title {
  flex: 1 1 auto;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-list-view li .doc-meta { color: #6b7280; font-size: 12px; flex: 0 0 auto; }
.doc-list-view li button { flex: 0 0 auto; }

/* Sheet view */
.sheet-view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #fff;
}
.formula-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #d6dae2;
  flex: 0 0 auto;
}
.cell-ref {
  width: 64px;
  padding: 6px 8px;
  text-align: center;
  font-weight: 600;
  border-right: 1px solid #d6dae2;
  background: #f7f8fa;
}
.formula-bar {
  flex: 1 1 auto;
  border: none;
  outline: none;
  padding: 7px 10px;
  font: inherit;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}

.grid-scroll {
  flex: 1 1 auto;
  overflow: auto;
  position: relative;
}
table.grid {
  border-collapse: collapse;
  table-layout: fixed;
  user-select: none;
}
table.grid th, table.grid td {
  border-right: 1px solid #dfe3ea;
  border-bottom: 1px solid #dfe3ea;
  padding: 0;
  margin: 0;
}
table.grid th {
  background: #eef0f4;
  font-weight: 600;
  font-size: 12px;
  color: #4b5563;
  position: sticky;
  z-index: 2;
}
table.grid th.corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
  width: 44px;
  min-width: 44px;
}
table.grid th.col-head {
  top: 0;
  width: 80px;
  min-width: 80px;
  height: 24px;
  text-align: center;
}
table.grid th.row-head {
  left: 0;
  width: 44px;
  min-width: 44px;
  text-align: center;
}
table.grid td.cell {
  height: 24px;
  width: 80px;
  min-width: 80px;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: cell;
  background: #fff;
}
table.grid td.cell[aria-selected="true"] {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  background: #eff6ff;
}
table.grid td.cell.editing {
  outline: 2px solid #1d4ed8;
  outline-offset: -2px;
}
table.grid td.cell .err { color: #b3261e; }

/* In-cell editor */
.cell-editor {
  position: fixed;
  z-index: 10;
  border: 2px solid #1d4ed8;
  padding: 2px 4px;
  font: inherit;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  min-width: 80px;
  min-height: 24px;
  outline: none;
  background: #fff;
}
