/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ffffff;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --primary: #1a73e8;
  --header-bg: #f8f9fa;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  height: 100vh;
}

.hidden { display: none !important; }

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 9999;
}

.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  margin-left: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ── Landing Page ── */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  overflow-y: auto;
  background: #f0f0f0;
}

/* ── Outer frame ── */
.landing-frame {
  width: 100%;
  max-width: 860px;
  border: 1px solid #ccc;
  background: #fff;
  display: flex;
  flex-direction: column;
}

/* Top bar: brand */
.frame-bar {
  text-align: center;
  padding: 14px 0;
  font-size: 15px;
  font-family: Georgia, 'Times New Roman', Times, serif;
  font-weight: 400;
  letter-spacing: 0.2em;
  color: #111;
  border-bottom: 1px solid #ccc;
}

/* Main drop area */
.frame-body {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  padding: 60px 40px;
  cursor: pointer;
  border-bottom: 1px solid #ccc;
  transition: background-color 0.3s;
}

.frame-body.drag-over {
  background: #f8f8f8;
}

/* Corner marks */
.corner {
  position: absolute;
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.corner::before,
.corner::after {
  content: '';
  position: absolute;
  background: #999;
}

/* Horizontal stroke */
.corner::before {
  width: 24px;
  height: 1px;
}

/* Vertical stroke */
.corner::after {
  width: 1px;
  height: 24px;
}

.corner-tl { top: 28px; left: 28px; }
.corner-tl::before { top: 11px; left: 0; }
.corner-tl::after { top: 0; left: 11px; }

.corner-tr { top: 28px; right: 28px; }
.corner-tr::before { top: 11px; right: 0; }
.corner-tr::after { top: 0; right: 11px; }

.corner-bl { bottom: 48px; left: 28px; }
.corner-bl::before { bottom: 11px; left: 0; }
.corner-bl::after { bottom: 0; left: 11px; }

.corner-br { bottom: 48px; right: 28px; }
.corner-br::before { bottom: 11px; right: 0; }
.corner-br::after { bottom: 0; right: 11px; }

/* Drop content */
.drop-title {
  font-size: 42px;
  font-family: Georgia, 'Times New Roman', Times, serif;
  font-weight: 400;
  letter-spacing: 0.03em;
  color: #111;
  margin-bottom: 28px;
}

.drop-action {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 0;
}

.drop-or {
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  color: #999;
  letter-spacing: 0.08em;
}

.browse-btn {
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  letter-spacing: 0.08em;
  color: #333;
  padding: 8px 20px;
  border: 1px solid #333;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.browse-btn:hover {
  background: #111;
  color: #fff;
}

.drop-formats {
  position: absolute;
  bottom: 24px;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  color: #aaa;
  letter-spacing: 0.06em;
}

/* ── Sections (recent data etc.) ── */
.frame-section {
  border-bottom: 1px solid #ccc;
}

.frame-section-header {
  text-align: center;
  padding: 10px 0;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  letter-spacing: 0.1em;
  color: #999;
  background: #f7f7f7;
  border-bottom: 1px solid #e5e5e5;
}

.recent-file-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  cursor: pointer;
  transition: background-color 0.15s;
  border-bottom: 1px solid #eee;
}

.recent-file-item:last-child {
  border-bottom: none;
}

.recent-file-item:hover {
  background: #f9f9f9;
}

.recent-file-icon {
  flex-shrink: 0;
  color: #bbb;
}

.recent-file-name {
  flex: 1;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-file-time {
  font-size: 12px;
  color: #aaa;
  white-space: nowrap;
  flex-shrink: 0;
}

.recent-file-delete {
  width: 22px;
  height: 22px;
  border: 1px solid #ddd;
  background: none;
  color: #bbb;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.recent-file-item:hover .recent-file-delete {
  opacity: 1;
}

.recent-file-delete:hover {
  color: #666;
  border-color: #999;
}

/* ── Footer ── */
.frame-footer {
  text-align: center;
  padding: 14px 0;
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  letter-spacing: 0.06em;
  color: #aaa;
}


/* ── Responsive ── */
@media (max-width: 600px) {
  .landing { padding: 10px; }
  .frame-body { min-height: 320px; padding: 48px 24px; }
  .drop-title { font-size: 28px; }
  .corner-tl, .corner-tr { top: 16px; }
  .corner-bl, .corner-br { bottom: 40px; }
  .corner-tl, .corner-bl { left: 16px; }
  .corner-tr, .corner-br { right: 16px; }
  .recent-file-item { padding: 10px 16px; }
}

/* ── Viewer ── */
.viewer {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Formula Bar ── */
.formula-bar {
  display: flex;
  align-items: stretch;
  min-height: 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.formula-bar-label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  min-width: 50px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--header-bg);
  border-right: 1px solid var(--border);
  user-select: none;
}

.formula-bar-input-wrap {
  flex: 1;
  display: flex;
  min-width: 0;
}

.formula-bar-input-wrap textarea {
  flex: 1;
  border: none;
  outline: none;
  padding: 4px 8px;
  font: 13px -apple-system, "Segoe UI", sans-serif;
  resize: none;
  line-height: 20px;
  background: var(--bg);
}

.formula-bar-input-wrap textarea:focus {
  background: #fefefe;
}

/* ── Search Bar ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-bar input {
  width: 200px;
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
}

.search-bar input:focus {
  border-color: var(--primary);
}

.search-count {
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: center;
}

.search-bar button {
  width: 26px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}

.search-bar button:hover {
  background: #f3f4f6;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.toolbar-filename {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-actions button {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.15s;
}

.toolbar-actions button:hover {
  background: #f3f4f6;
}

.toolbar-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Sheet Container ── */
.sheet-container {
  position: relative;
  flex: 1;
  overflow: hidden;
}

.sheet-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Scrollbars ── */
.scrollbar-v,
.scrollbar-h {
  position: absolute;
  background: transparent;
  z-index: 5;
}

.scrollbar-v {
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
}

.scrollbar-h {
  bottom: 0;
  left: 0;
  width: 100%;
  height: 10px;
}

.scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  min-width: 30px;
  min-height: 30px;
  transition: background-color 0.15s;
  cursor: pointer;
}

.scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.35);
}

.scrollbar-v .scrollbar-thumb {
  width: 100%;
}

.scrollbar-h .scrollbar-thumb {
  height: 100%;
}

/* ── Sheet Tabs ── */
.sheet-tabs {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  gap: 2px;
}

.sheet-tab {
  padding: 4px 12px;
  font-size: 12px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s;
}

.sheet-tab:hover {
  background: rgba(0, 0, 0, 0.04);
}

.status-info {
  margin-left: auto;
  padding: 0 12px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.sheet-tab.active {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
  font-weight: 500;
}

/* ── Context Menu ── */
.context-menu {
  position: fixed;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
  min-width: 140px;
}

.context-menu button {
  display: block;
  width: 100%;
  padding: 6px 16px;
  font-size: 13px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.context-menu button:hover {
  background: #f3f4f6;
}

.context-menu hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* ── Export Progress Overlay ── */
.export-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.75);
  z-index: 9998;
  backdrop-filter: blur(2px);
}
.export-overlay.hidden { display: none; }
.export-text {
  margin-left: 12px;
  color: #374151;
  font-size: 14px;
  font-weight: 500;
}

/* ── Toast Notifications ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 480px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-info { background: #1f2937; color: #fff; }
.toast-success { background: #065f46; color: #fff; }
.toast-error { background: #991b1b; color: #fff; }

.toast-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.7;
  padding: 0 4px;
}

.toast-close:hover { opacity: 1; }

/* ── Update Notification ── */
.update-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: #fff;
  border: 1px solid #ccc;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: #999;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  z-index: 200;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.update-bar.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.update-bar-action {
  font-family: inherit;
  font-size: inherit;
  letter-spacing: inherit;
  color: #333;
  border: 1px solid #333;
  background: none;
  padding: 4px 14px;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.update-bar-action:hover {
  background: #111;
  color: #fff;
}

a.update-bar-action {
  text-decoration: none;
  color: #333;
}

.popup-blocked-bar {
  bottom: 80px;
}

.update-bar-dismiss {
  background: none;
  border: none;
  color: #ccc;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.15s;
}

.update-bar-dismiss:hover {
  color: #999;
}

/* ── Fatal Error Modal ── */
.fatal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.fatal-dialog {
  background: var(--bg);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.fatal-icon {
  font-size: 40px;
  color: #ef4444;
  margin-bottom: 12px;
}

.fatal-dialog h3 {
  font-size: 18px;
  margin-bottom: 8px;
}

.fatal-dialog p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.fatal-hint {
  font-size: 12px;
  opacity: 0.7;
}

.fatal-dialog button {
  margin-top: 16px;
  padding: 8px 24px;
  font-size: 14px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.fatal-dialog button:hover {
  opacity: 0.9;
}

/* ── Filter Panel ── */

.filter-panel {
  position: fixed;
  z-index: 100;
  width: 240px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  user-select: none;
}

.filter-search {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.filter-search input {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  outline: none;
}

.filter-search input:focus {
  border-color: var(--primary);
}

.filter-select-all {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.filter-list {
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}

.filter-item:hover {
  background: #f3f4f6;
}

.filter-item span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-count {
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.filter-actions button {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
}

.filter-actions button:hover {
  background: #f3f4f6;
}

.filter-actions button:last-child {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.filter-actions button:last-child:hover {
  opacity: 0.9;
}

.filter-btn-clear {
  margin-right: auto;
  color: var(--text-secondary);
  border: none !important;
  background: none !important;
}

.filter-btn-clear:hover {
  color: var(--primary);
  background: none !important;
}
