/* style.css - Modern Excel & Spreadsheet Styling */

:root {
  --primary: #107c41;
  --primary-hover: #0d6334;
  --primary-light: #e8f5e9;
  --border-color: #e2e8f0;
  --header-bg: #f8fafc;
  --header-border: #cbd5e1;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --cell-select-border: #107c41;
  --cell-select-bg: rgba(16, 124, 65, 0.08);
  --header-select-bg: #e2e8f0;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Consolas, Monaco, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  color: var(--text-main);
  background-color: #f1f5f9;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background: #ffffff;
}

/* ==========================================================================
   Header Bar
   ========================================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-color);
  user-select: none;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.excel-icon {
  width: 30px;
  height: 30px;
  border-radius: 4px;
}

.app-title-group {
  display: flex;
  flex-direction: column;
}

.app-title {
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.1;
}

.app-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.storage-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #475569;
  background: #f1f5f9;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.saved {
  background-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.status-dot.saving {
  background-color: #f59e0b;
  animation: pulse 1s infinite;
}

.status-dot.error {
  background-color: #ef4444;
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-secondary {
  background-color: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
}

.btn-secondary:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
}

/* ==========================================================================
   Toolbar Ribbon
   ========================================================================== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  background-color: #f8fafc;
  border-bottom: 1px solid var(--border-color);
  user-select: none;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  position: relative;
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background-color: #cbd5e1;
  margin: 0 4px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 2px 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.1s;
}

.tool-btn:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

.tool-btn.active {
  background-color: var(--primary-light);
  border-color: #a7f3d0;
  color: var(--primary);
  font-weight: 600;
}

.tool-select {
  height: 28px;
  padding: 2px 8px;
  font-size: 12px;
  color: #334155;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

.tool-select:hover {
  border-color: #94a3b8;
}

.color-picker-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
  border: 1px solid transparent;
  color: #334155;
}

.color-picker-label:hover {
  background-color: #e2e8f0;
}

.color-picker-label input[type="color"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.color-icon {
  font-weight: 700;
  font-size: 13px;
  border-bottom: 3px solid #000000;
  line-height: 1;
}

/* Split AutoSum button */
.btn-split-group {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background-color: #ffffff;
}

.split-main {
  border: none;
  border-radius: 4px 0 0 4px;
  padding: 2px 8px;
  background-color: transparent;
}

.split-arrow {
  border: none;
  border-left: 1px solid #e2e8f0;
  border-radius: 0 4px 4px 0;
  min-width: 20px;
  padding: 0 4px;
  background-color: transparent;
}

.sigma-symbol {
  font-weight: 700;
  font-size: 14px;
  color: var(--primary);
  margin-right: 4px;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 4px 0;
  z-index: 100;
  min-width: 170px;
  margin-top: 2px;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  padding: 6px 12px;
  font-size: 12px;
  color: #334155;
  cursor: pointer;
  transition: background 0.1s;
}

.dropdown-item:hover {
  background-color: #f1f5f9;
  color: var(--primary);
}

/* ==========================================================================
   Formula Bar
   ========================================================================== */
.formula-bar-container {
  display: flex;
  align-items: center;
  padding: 4px 12px;
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
}

.name-box-wrapper {
  width: 90px;
  flex-shrink: 0;
}

.cell-name-box {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  text-align: center;
  background-color: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  outline: none;
}

.cell-name-box:focus {
  border-color: var(--primary);
  background-color: #ffffff;
}

.fx-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: #64748b;
  flex-shrink: 0;
}

.formula-input-wrapper {
  flex: 1;
  position: relative;
}

.formula-input {
  width: 100%;
  height: 28px;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: #0f172a;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  outline: none;
}

.formula-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(16, 124, 65, 0.15);
}

.formula-helper-popup {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background-color: #1e293b;
  color: #f8fafc;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 90;
  line-height: 1.4;
}

/* ==========================================================================
   Spreadsheet Viewport & Grid Table
   ========================================================================== */
.grid-main {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: #ffffff;
}

.spreadsheet-viewport {
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
}

.spreadsheet-table {
  border-collapse: collapse;
  table-layout: fixed;
  user-select: none;
  background-color: #ffffff;
}

/* Corner & Headers */
.corner-header {
  width: 45px;
  min-width: 45px;
  max-width: 45px;
  height: 26px;
  background-color: var(--header-bg);
  border: 1px solid var(--header-border);
  position: sticky;
  top: 0;
  left: 0;
  z-index: 20;
}

.col-header {
  height: 26px;
  background-color: var(--header-bg);
  border: 1px solid var(--header-border);
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 10;
  position: relative;
  padding: 0;
}

.row-header {
  width: 45px;
  min-width: 45px;
  max-width: 45px;
  background-color: var(--header-bg);
  border: 1px solid var(--header-border);
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-align: center;
  position: sticky;
  left: 0;
  z-index: 10;
  position: relative;
  padding: 0;
}

.col-header.selected-header,
.row-header.selected-header {
  background-color: var(--header-select-bg);
  color: var(--primary);
  font-weight: 700;
}

.header-label {
  display: block;
  width: 100%;
  height: 100%;
  line-height: 26px;
}

/* Resizers */
.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 5;
}

.col-resizer:hover {
  background-color: var(--primary);
}

.row-resizer {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 5px;
  cursor: row-resize;
  z-index: 5;
}

.row-resizer:hover {
  background-color: var(--primary);
}

/* Grid Cells */
.grid-cell {
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  font-size: 13px;
  color: var(--text-main);
  background-color: #ffffff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
  cursor: cell;
}

.grid-cell .cell-content {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Selection States */
.grid-cell.selected {
  background-color: var(--cell-select-bg);
}

.grid-cell.active-cell {
  outline: 2px solid var(--cell-select-border);
  outline-offset: -2px;
  z-index: 2;
  background-color: #ffffff;
}

/* Inline cell editor */
.cell-editor-container {
  position: absolute;
  z-index: 30;
  background-color: #ffffff;
  box-shadow: 0 0 0 2px var(--primary);
}

.inline-cell-input {
  width: 100%;
  height: 100%;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 13px;
  border: none;
  outline: none;
  background: #ffffff;
  color: #0f172a;
}

/* ==========================================================================
   Footer: Sheet Tabs & Status Metrics
   ========================================================================== */
.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 12px;
  background-color: #f8fafc;
  border-top: 1px solid var(--border-color);
  user-select: none;
  font-size: 12px;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
}

.add-sheet-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  transition: all 0.1s;
}

.add-sheet-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.sheet-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.sheet-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  font-size: 12px;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  transition: all 0.1s;
}

.sheet-tab:hover {
  color: #0f172a;
  background-color: #f1f5f9;
}

.sheet-tab.active {
  background-color: #ffffff;
  color: var(--primary);
  font-weight: 600;
  border-top: 2px solid var(--primary);
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.05);
}

.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  background: transparent;
  border: none;
  font-size: 14px;
  line-height: 1;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 2px;
}

.tab-close:hover {
  color: #ef4444;
  background-color: #fee2e2;
}

.footer-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: #475569;
}

.metric {
  display: inline-block;
  padding: 2px 6px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
}

.metric strong {
  color: #0f172a;
  margin-right: 2px;
}

.ready-label {
  color: var(--primary);
  font-weight: 600;
  background: transparent;
  border: none;
}

