﻿/* ==========================================================================
   GOOGLE SHEETS PIXEL-PERFECT CLONE STYLES (MATERIAL DESIGN 3)
   ========================================================================== */

:root {
  --green-primary: #0f9d58;
  --green-hover: #0b8043;
  --sheets-blue: #1a73e8;
  --sheets-blue-light: #e8f0fe;
  --sheets-blue-hover: #d2e3fc;
  
  --sheet-border: #e0e2e6;
  --cell-border: #e1e3e1;
  --header-bg: #f8f9fa;
  --header-hover: #f1f3f4;
  --header-selected: #e8f0fe;
  
  --text-main: #1f1f1f;
  --text-muted: #5f6368;
  --text-header: #444746;
  
  --toolbar-bg: #edf2fa;
  --toolbar-btn-hover: #dfe4ec;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: "Roboto", Arial, sans-serif;
  font-size: 13px;
  color: var(--text-main);
  background: #f8f9fa;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ==========================================================================
   1. GOOGLE SHEETS HEADER (Logo, Doc title, Menu bar, Search, Actions)
   ========================================================================== */
.sheets-header {
  display: flex;
  align-items: center;
  padding: 8px 16px 4px 16px;
  background: var(--white);
  border-bottom: 1px solid transparent;
  gap: 12px;
  user-select: none;
}

.sheets-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
  cursor: pointer;
}

.header-main-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Dòng tiêu đề tài liệu */
.doc-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 28px;
}

.doc-title-input {
  font-size: 18px;
  font-weight: 400;
  color: var(--text-main);
  border: 1px solid transparent;
  padding: 2px 6px;
  border-radius: 4px;
  width: 360px;
  outline: none;
  background: transparent;
  font-family: "Roboto", Arial, sans-serif;
}

.doc-title-input:hover {
  border-color: #dadce0;
}

.doc-title-input:focus {
  border-color: var(--sheets-blue);
  background: var(--white);
}

.icon-btn-compact {
  background: transparent;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn-compact:hover {
  background: #f1f3f4;
}

.save-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.save-status:hover {
  background: #f1f3f4;
}

.current-story-badge {
  font-size: 11px;
  color: #137333;
  background: #e6f4ea;
  padding: 2px 8px;
  border-radius: 10px;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid #ceead6;
  font-weight: 500;
}

/* Thanh Menu 9 mục */
.menu-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 2px;
}

.menu-item {
  font-size: 13px;
  color: #444746;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
}

.menu-item:hover {
  background: #f1f3f4;
}

/* Ô Ngụy trang Tìm kiếm trong bảng tính */
.search-box-disguised {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f1f3f4;
  border-radius: 24px;
  padding: 0 12px;
  height: 36px;
  width: 320px;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.search-box-disguised:focus-within {
  background: #fff;
  border-color: #dadce0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.search-box-disguised input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--text-main);
  width: 100%;
}

.quick-search-btn {
  background: var(--green-primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
}

.quick-search-btn:hover {
  background: var(--green-hover);
}

/* Khu vực hành động bên phải */
.header-right-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.circle-icon-btn {
  background: transparent;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.circle-icon-btn:hover {
  background: #f1f3f4;
}

.boss-key-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #fce8e6;
  color: #c5221f;
  border: 1px solid #f5c2c7;
  border-radius: 18px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.boss-key-btn:hover {
  background: #fad2cf;
}

.share-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #c2e7ff;
  color: #001d35;
  border: none;
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.share-btn:hover {
  background: #b3d7f0;
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: #0b57d0;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

/* ==========================================================================
   2. THANH CÔNG CỤ TOOLBAR (Floating Pill Material 3)
   ========================================================================== */
.sheets-toolbar {
  display: flex;
  align-items: center;
  background: var(--toolbar-bg);
  border-radius: 24px;
  margin: 2px 16px 4px 16px;
  padding: 3px 8px;
  height: 38px;
  gap: 3px;
  user-select: none;
}

.tool-btn {
  background: transparent;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s ease;
}

.tool-btn:hover {
  background: var(--toolbar-btn-hover);
}

.tool-dropdown-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 14px;
  font-size: 12px;
  color: var(--text-header);
  cursor: pointer;
}

.tool-dropdown-pill:hover {
  background: var(--toolbar-btn-hover);
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: #c7c7c7;
  margin: 0 4px;
}

.reading-hint-badge {
  margin-left: auto;
  font-size: 11px;
  color: #444746;
  background: rgba(255, 255, 255, 0.6);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

/* ==========================================================================
   3. THANH CÔNG THỨC FORMULA BAR (Name Box, fx, Input)
   ========================================================================== */
.formula-bar {
  display: flex;
  align-items: center;
  background: var(--white);
  border-top: 1px solid var(--sheet-border);
  border-bottom: 1px solid var(--sheet-border);
  height: 28px;
  padding: 0 8px;
  gap: 6px;
  user-select: none;
}

.name-box-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 64px;
  height: 22px;
  border: 1px solid #dadce0;
  border-radius: 2px;
  padding: 0 4px;
  background: var(--white);
  cursor: pointer;
}

.name-box {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  text-align: center;
  flex: 1;
}

.fx-symbol {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  color: #5f6368;
}

.fx-text {
  font-family: "Georgia", serif;
  font-style: italic;
  font-size: 14px;
  font-weight: bold;
}

.formula-input {
  flex: 1;
  height: 22px;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-main);
  background: transparent;
  font-family: "Roboto", Arial, sans-serif;
  padding: 0 4px;
}

.formula-expand-btn {
  background: transparent;
  border: none;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
}

.formula-expand-btn:hover {
  background: #f1f3f4;
}

/* ==========================================================================
   4. LƯỚI BẢNG TÍNH SPREADSHEET GRID
   ========================================================================== */
.grid-wrapper {
  flex: 1;
  display: grid;
  grid-template-columns: 46px 1fr;
  grid-template-rows: 24px 1fr;
  overflow: hidden;
  background: var(--white);
  position: relative;
}

/* Ô góc trên cùng bên trái (Select All) */
.corner-cell {
  background: var(--header-bg);
  border-right: 1px solid var(--sheet-border);
  border-bottom: 1px solid var(--sheet-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.select-all-triangle {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 8px 8px;
  border-color: transparent transparent #5f6368 transparent;
  opacity: 0.5;
}

.col-headers {
  display: flex;
  background: var(--header-bg);
  border-bottom: 1px solid var(--sheet-border);
  overflow: hidden;
  user-select: none;
}

.col-header {
  flex-shrink: 0;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--sheet-border);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-header);
  background: var(--header-bg);
  cursor: pointer;
  transition: background 0.1s ease;
}

.col-header:hover {
  background: var(--header-hover);
}

.col-header.selected {
  background: var(--sheets-blue-light) !important;
  color: var(--sheets-blue) !important;
  font-weight: 700;
}

.row-headers {
  display: flex;
  flex-direction: column;
  background: var(--header-bg);
  border-right: 1px solid var(--sheet-border);
  overflow: hidden;
  user-select: none;
}

.row-header {
  flex-shrink: 0;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--sheet-border);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-header);
  background: var(--header-bg);
  cursor: pointer;
  transition: background 0.1s ease;
}

.row-header:hover {
  background: var(--header-hover);
}

.row-header.selected {
  background: var(--sheets-blue-light) !important;
  color: var(--sheets-blue) !important;
  font-weight: 700;
}

.grid-cells {
  overflow: auto;
  position: relative;
  background: var(--white);
}

.grid-row {
  display: flex;
  height: 24px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--cell-border);
}

.grid-cell {
  flex-shrink: 0;
  height: 24px;
  box-sizing: border-box;
  border-right: 1px solid var(--cell-border);
  padding: 3px 6px;
  font-size: 12px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: cell;
  user-select: none;
  position: relative;
}

/* ==========================================================================
   CHẾ ĐỘ XUỐNG DÒNG TỰ ĐỘNG (WRAP TEXT) CHO Ô EXCEL
   Khi nội dung dài, hàng tự động co giãn và text xuống nhiều dòng mượt mà
   ========================================================================== */
.grid-cells.wrap-text .grid-row {
  min-height: 24px;
  height: auto;
  align-items: stretch;
}

.grid-cells.wrap-text .grid-cell {
  min-height: 24px;
  height: auto;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  text-overflow: clip;
}

/* Riêng cột A (nội dung câu văn truyện): căn trái 100%, text nhiều dòng hiển thị tự nhiên */
.grid-cells.wrap-text .grid-cell.col-A,
.grid-cell.col-A {
  display: block !important;
  text-align: left !important;
  white-space: normal !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  line-height: 21px !important;
  padding: 6px 12px !important;
}

/* Các cột kế toán phụ: căn chỉnh vị trí đẹp mắt khi hàng cao lên */
.grid-cells.wrap-text .grid-cell.col-B,
.grid-cells.wrap-text .grid-cell.col-C {
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-cells.wrap-text .grid-cell.col-E,
.grid-cells.wrap-text .grid-cell.col-F,
.grid-cells.wrap-text .grid-cell.col-G {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* Nút công cụ trạng thái Active trên thanh Toolbar */
.tool-btn.active {
  background: #e8f0fe !important;
  color: var(--sheets-blue) !important;
}
.tool-btn.active svg {
  fill: var(--sheets-blue) !important;
}

/* Ô được chọn (Active Cell) với viền xanh 2px */
.grid-cell.selected {
  outline: 2px solid var(--sheets-blue);
  outline-offset: -2px;
  background: rgba(26, 115, 232, 0.04);
  z-index: 10;
}

/* Chấm vuông kéo công thức (Fill Handle) đặc trưng của Google Sheets / Excel */
.grid-cell.selected::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 6px;
  height: 6px;
  background: var(--sheets-blue);
  border: 1px solid var(--white);
  cursor: crosshair;
  z-index: 20;
}

/* Kích thước & Căn chỉnh các cột ngụy trang */
.col-A { width: 850px; font-weight: 400; color: #1f1f1f; text-align: left !important; font-size: 13.5px; line-height: 1.55; padding: 6px 12px !important; } /* Nội dung truyện căn trái */
.col-B { width: 130px; text-align: center; font-size: 11px; }
.col-C { width: 130px; text-align: center; font-size: 11px; }
.col-D { width: 140px; text-align: center; font-size: 11px; color: var(--text-muted); }
.col-E { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }
.col-F { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }
.col-G { width: 130px; text-align: right; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   5. THANH SHEET TABS Ở ĐÁY (Mỗi chương là 1 tab trang tính)
   ========================================================================== */
.sheets-bottom-bar {
  display: flex;
  align-items: center;
  background: #f8f9fa;
  border-top: 1px solid var(--sheet-border);
  height: 38px;
  padding: 0 8px;
  gap: 4px;
  user-select: none;
}

.add-sheet-btn, .all-sheets-btn, .sheet-nav-arrow {
  background: transparent;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

.add-sheet-btn:hover, .all-sheets-btn:hover, .sheet-nav-arrow:hover:not(:disabled) {
  background: #e8eaed;
}

.sheet-nav-arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.sheet-tabs-list {
  display: flex;
  align-items: flex-end;
  height: 100%;
  overflow-x: auto;
  gap: 2px;
  padding-bottom: 2px;
}

/* Từng Sheet Tab */
.sheet-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 14px 0 16px;
  background: #e9ecef;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  border: 1px solid var(--sheet-border);
  border-bottom: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  position: relative;
}

.sheet-tab:hover {
  background: #dee2e6;
  color: var(--text-main);
}

/* Tab đang kích hoạt (Active) */
.sheet-tab.active {
  background: var(--white);
  color: var(--green-primary);
  font-weight: 700;
  box-shadow: 0 -1px 3px rgba(0,0,0,0.06);
}

/* Đường vạch màu dưới đáy tab trang tính chuẩn Google Sheets */
.sheet-tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: var(--green-primary);
}

.sheet-tab-arrow {
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 4px 3px 0 3px;
  border-color: #5f6368 transparent transparent transparent;
  margin-left: 2px;
}

/* Tab gợi ý chương tiếp theo */
.sheet-tab.next-preview-tab {
  color: var(--sheets-blue);
  font-style: italic;
  border-style: dashed;
  background: #f1f5fd;
}

.sheet-tab.next-preview-tab:hover {
  background: #e4edfd;
}

.bottom-bar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.calc-status {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.explore-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--white);
  border: 1px solid #dadce0;
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: #1a73e8;
  cursor: pointer;
}

.explore-btn:hover {
  background: #f8f9fa;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* ==========================================================================
   6. MODAL TÌM KIẾM TRUYỆN (VLOOKUP Assistant)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-dialog {
  background: var(--white);
  width: 720px;
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--sheet-border);
  background: #f8f9fa;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.search-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-input {
  flex: 1;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  outline: none;
}

.search-input:focus {
  border-color: var(--green-primary);
  box-shadow: 0 0 0 2px rgba(15, 157, 88, 0.2);
}

.modal-btn {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.primary-btn { background: var(--green-primary); color: #fff; }
.primary-btn:hover { background: var(--green-hover); }

.secondary-btn { background: #f1f3f4; color: var(--text-main); border: 1px solid #dadce0; }
.secondary-btn:hover { background: #e8eaed; }

.modal-status {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  min-height: 20px;
}

.section-heading {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.story-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 380px;
  overflow-y: auto;
}

.story-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--sheet-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.story-item:hover {
  border-color: var(--green-primary);
  background: #f6fdf8;
}

.story-name {
  font-size: 14px;
  font-weight: 600;
  color: #1a73e8;
  margin-bottom: 4px;
}

.story-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.story-tag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.tag-full { background: #e6f4ea; color: #137333; }
.tag-hot { background: #fce8e6; color: #c5221f; }

.chapters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.selected-story-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.chapter-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  max-height: 380px;
  overflow-y: auto;
}

.chapter-item {
  padding: 8px 12px;
  border: 1px solid var(--sheet-border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #fff;
}

.chapter-item:hover {
  background: #e8f0fe;
  border-color: #1a73e8;
  color: #1a73e8;
}

/* Trạng thái khi vừa bấm sao chép liên kết chia sẻ */
.share-btn.copied {
  background: #e6f4ea !important;
  color: #137333 !important;
  border: 1px solid #ceead6 !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
