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

:root {
  /* Colors */
  --bg: #f0f2f5;
  --bg-white: #ffffff;
  --gold: #d4a017;
  --gold-light: #e8c34a;
  --gold-dark: #b8860b;
  --gold-gradient: linear-gradient(135deg, #e8c34a 0%, #d4a017 50%, #c9941c 100%);
  --blue: #1a73e8;
  --blue-dark: #1557b0;
  --red: #d93026;
  --text: #1a1a1a;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --border: #dadce0;
  --border-light: #e8eaed;
  --hover-bg: #f8f9fa;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);
  --radius: 8px;
  --radius-sm: 4px;

  /* Layout */
  --topbar-h: 56px;
  --toolbar-h: 48px;
}

html, body {
  height: 100%;
  font-family: -apple-system, "Noto Sans CJK SC", "WenQuanYi Micro Hei", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ====== Topbar ====== */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: relative;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  display: flex;
  align-items: center;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-online {
  background: #e6f4ea;
  color: #137333;
}

.badge-online::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #137333;
  margin-right: 5px;
  animation: pulse 2s infinite;
}

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

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

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 4px;
  border-radius: 20px;
  background: var(--hover-bg);
  cursor: pointer;
  transition: background 0.15s;
}

.user-chip:hover {
  background: var(--border-light);
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

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

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--hover-bg);
  color: var(--text);
}

/* ====== Toolbar ====== */
.toolbar {
  height: var(--toolbar-h);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  position: relative;
  z-index: 90;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  flex-shrink: 0;
}

.toolbar-spacer {
  flex: 1;
}

.toolbar-right {
  gap: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.97);
}

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

.btn-primary:hover {
  background: var(--blue-dark);
}

.btn-outline {
  background: var(--bg-white);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  background: var(--hover-bg);
  border-color: var(--text-secondary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.week-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 6px;
  background: #fef7e0;
  border: 1px solid #f5d061;
  font-size: 12px;
  font-weight: 500;
  color: #8c6d00;
}

.week-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  flex-shrink: 0;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34a853;
  flex-shrink: 0;
}

.sync-status.syncing .sync-dot {
  background: #fbbc04;
  animation: pulse 1s infinite;
}

.sync-status.error .sync-dot {
  background: #ea4335;
}

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

/* ====== Table Container ====== */
.table-container {
  height: calc(100vh - var(--topbar-h) - var(--toolbar-h));
  overflow: auto;
  padding: 16px;
  background: var(--bg);
}

.table-wrapper {
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 200px;
}

/* ====== Report Table ====== */
.report-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.report-table th,
.report-table td {
  border: 1px solid var(--border);
  vertical-align: top;
  position: relative;
}

/* Header rows */
.report-table thead th {
  background: var(--gold-gradient);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 8px 6px;
  position: sticky;
  top: 0;
  z-index: 10;
  text-shadow: 0 1px 2px rgba(0,0,0,0.15);
  font-size: 13px;
}

.report-table thead th.header-date-row {
  border-bottom: 1px solid rgba(255,255,255,0.3);
  font-size: 13px;
}

.report-table thead th.header-type-row {
  font-size: 12px;
  font-weight: 600;
  background: #c9941c;
}

/* Fixed columns styling */
.report-table th.fixed-col {
  background: #b8860b;
  color: #fff;
  writing-mode: horizontal-tb;
}

.report-table .fixed-col-cell {
  background: #fffbf0;
  font-weight: 500;
}

/* Body cells */
.report-table tbody td {
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.report-table tbody td.editable {
  cursor: text;
  transition: background 0.1s;
}

.report-table tbody td.editable:hover {
  background: #eef5ff;
}

.report-table tbody td.editing {
  background: #e8f0fe;
  box-shadow: inset 0 0 0 2px var(--blue);
}

.report-table tbody td .cell-content {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 24px;
}

.report-table tbody td .cell-content:empty::before {
  content: '点击编辑';
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

/* Row hover */
.report-table tbody tr:hover td {
  background: #f7f9fc;
}

.report-table tbody tr:hover td.fixed-col-cell {
  background: #fff9e0;
}

/* Row number column */
.row-num {
  width: 40px;
  text-align: center;
  background: var(--hover-bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  position: sticky;
  left: 0;
  z-index: 5;
}

.row-num .row-actions {
  display: none;
  position: absolute;
  top: 2px;
  right: 2px;
  gap: 2px;
}

.report-table tbody tr:hover .row-actions {
  display: flex;
}

.row-action-btn {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-action-btn:hover {
  background: var(--border);
  color: var(--red);
}

/* Hidden week indicator */
.week-hidden-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  background: #f1f3f4;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  margin: 4px 0;
  transition: background 0.15s;
}

.week-hidden-bar:hover {
  background: #e8eaed;
}

.week-hidden-bar .restore-icon {
  width: 14px;
  height: 14px;
  color: var(--blue);
}

/* ====== Side Panel (Logs) ====== */
.side-panel {
  position: fixed;
  top: 0;
  right: -420px;
  width: 400px;
  height: 100vh;
  background: var(--bg-white);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.side-panel.open {
  right: 0;
}

.side-panel-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.3);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.side-panel-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.side-panel-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.side-panel-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.log-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
}

.log-entry:hover {
  background: var(--hover-bg);
}

.log-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.log-icon.edit { background: var(--blue); }
.log-icon.add { background: #137333; }
.log-icon.delete { background: var(--red); }
.log-icon.system { background: #5f6368; }
.log-icon.toggle { background: #e8710a; }

.log-body {
  flex: 1;
  min-width: 0;
}

.log-action {
  font-weight: 600;
  color: var(--text);
}

.log-detail {
  color: var(--text-secondary);
  font-size: 11px;
  margin-top: 2px;
  word-break: break-all;
}

.log-meta {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-muted);
}

.log-meta span {
  display: flex;
  align-items: center;
  gap: 3px;
}

.btn-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.btn-close:hover {
  background: var(--hover-bg);
}

/* ====== Modal ====== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: none;
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
}

.modal-content {
  position: relative;
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.2s ease-out;
}

.modal-content.modal-sm {
  width: 360px;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

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

.modal-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.input-full {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.input-full:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.1);
}

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.setting-label {
  font-size: 14px;
  font-weight: 500;
}

.setting-value {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: monospace;
}

.setting-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.2s;
}

.slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background: var(--blue);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

/* ====== Export Overlay ====== */
.export-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(255,255,255,0.9);
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

.export-overlay.show {
  display: flex;
}

.export-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-light);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.export-overlay p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ====== Date range header inputs ====== */
.date-edit-input {
  width: 70px;
  padding: 2px 4px;
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 3px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 12px;
  text-align: center;
  outline: none;
  font-family: inherit;
}

.date-edit-input:focus {
  background: rgba(255,255,255,0.25);
}

.date-edit-input::placeholder {
  color: rgba(255,255,255,0.5);
}

/* ====== Empty state ====== */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 16px;
}

/* ====== Scrollbar styling ====== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--hover-bg);
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* ====== Responsive ====== */
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
  }
  .page-title {
    font-size: 16px;
  }
  .user-ip {
    display: none;
  }
  .toolbar {
    padding: 0 8px;
    gap: 4px;
  }
  .btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .btn span {
    display: none;
  }
  .week-indicator {
    font-size: 11px;
    padding: 3px 8px;
  }
  .table-container {
    padding: 8px;
  }
  .side-panel {
    width: 100vw;
    right: -100vw;
  }
  .modal-content {
    width: 95vw;
  }
}

/* ====== Print / Export mode ====== */
.export-mode .topbar,
.export-mode .toolbar,
.export-mode #tableContainer > *:not(.table-wrapper) {
  display: none !important;
}

.export-mode .table-container {
  height: auto;
  overflow: visible;
  padding: 0;
  background: #fff;
}

.export-mode .table-wrapper {
  box-shadow: none;
  border-radius: 0;
}

.export-mode .report-table td.editable:hover,
.export-mode .report-table tbody tr:hover td {
  background: transparent !important;
}

.export-mode .cell-content:empty::before {
  content: '';
}

.export-mode .row-actions {
  display: none !important;
}

.export-mode .week-hidden-bar,
.export-mode .hidden-cols-bar {
  display: none !important;
}

.export-mode .report-table tbody td.editable {
  cursor: default;
}

/* ====== Context Menu ====== */
.context-menu {
  position: fixed;
  z-index: 500;
  min-width: 200px;
  background: var(--bg-white);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  padding: 4px 0;
  animation: cmIn 0.15s ease-out;
}

@keyframes cmIn {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--text);
  white-space: nowrap;
}

.context-menu-item:hover {
  background: #eef5ff;
}

.context-menu-item:hover .cm-icon {
  color: var(--blue);
}

.cm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.1s;
}

.context-menu-divider {
  height: 1px;
  background: var(--border-light);
  margin: 4px 0;
}

/* ====== Hidden Columns Bar ====== */
.hidden-cols-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: #fef7e0;
  border-top: 2px solid #f5d061;
  font-size: 12px;
}

.hidden-cols-title {
  font-weight: 600;
  color: #8c6d00;
  flex-shrink: 0;
}

.hidden-col-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 10px;
  border-radius: 14px;
  background: var(--bg-white);
  border: 1px solid #f5d061;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 12px;
}

.hidden-col-chip:hover {
  background: #fff3c4;
  border-color: #e6b800;
}

.chip-restore {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
}

.btn-restore-all {
  margin-left: auto;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-white);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.btn-restore-all:hover {
  background: var(--hover-bg);
  border-color: var(--text-secondary);
}

/* ====== Hidden Columns Modal ====== */
.hidden-col-modal-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ====== Table header hover (context menu hint) ====== */
.report-table thead th[data-col-key],
.report-table thead th[data-col-type] {
  cursor: context-menu;
}

.report-table thead th[data-col-key]:hover,
.report-table thead th[data-col-type]:hover {
  filter: brightness(1.08);
}
