:root {
  color-scheme: dark;
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #334155;
  --bg-card: rgba(30, 41, 59, 0.7);
  --border-subtle: #334155;
  --border-active: #38bdf8;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-cyan: #38bdf8;
  --accent-blue: #3b82f6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #a855f7;

  --badge-cn: #ef4444;
  --badge-hk: #8b5cf6;
  --badge-work: #f59e0b;
  --badge-rest: #475569;

  --cell-width: 64px;
  --sticky-col-1: 130px;
  --sticky-col-2: 120px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: #475569 #0f172a;
}

/* Chrome, Edge, Safari (WebKit & Blink) Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0b1120;
  border-radius: 9999px;
}

::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 9999px;
  border: 2px solid #0b1120;
  background-clip: padding-box;
  transition: all 0.2s ease;
}

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

::-webkit-scrollbar-thumb:active {
  background: #0284c7;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

body {
  font-family: 'Outfit', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Layout */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
}

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

.logo-icon {
  font-size: 28px;
  background: rgba(56, 189, 248, 0.12);
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sub-title {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.month-selector-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  padding: 4px 8px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
}

.current-month-display {
  position: relative;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 1rem;
  padding: 4px 12px;
  cursor: pointer;
  color: var(--accent-cyan);
}

.hidden-month-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

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

.btn-pill {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-pill:hover {
  background: rgba(56, 189, 248, 0.25);
}

.save-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--accent-emerald);
  padding: 6px 12px;
  background: rgba(16, 185, 129, 0.1);
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.save-status.saving {
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.2);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
}

.save-status.saving .status-dot {
  background-color: var(--accent-amber);
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.3); opacity: 1; }
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
}

.user-role-badge {
  background: #0284c7;
  color: white;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent-cyan);
  cursor: pointer;
  font-size: 0.8rem;
  text-decoration: underline;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 100vw;
}

/* Summary Hero Cards */
.summary-hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1.2fr;
  gap: 16px;
}

.hero-card {
  background: var(--bg-card);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: border-color 0.2s, transform 0.2s;
}

.hero-card:hover {
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateY(-2px);
}

.hero-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-header .label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.mode-badge {
  background: rgba(168, 85, 247, 0.15);
  color: var(--accent-purple);
  border: 1px solid rgba(168, 85, 247, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.rate-metric, .payout-metric, .grand-payout-metric {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.currency {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.amount {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

.grand-payout-metric .amount {
  color: var(--accent-emerald);
  font-size: 2.2rem;
}

.unit {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.mode-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.4;
}

.employer-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.employer-avatar.pat {
  background: #3b82f6;
  color: white;
}

.employer-avatar.fra {
  background: #10b981;
  color: white;
}

.employer-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.emp-hours-tag, .total-hours-tag {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 2px 8px;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--accent-cyan);
}

.hours-breakdown, .total-breakdown {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* Timesheet Spreadsheet Section */
.timesheet-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.section-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toolbar-left h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.hint-tag {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: 8px;
}

.toolbar-right {
  display: flex;
  gap: 10px;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-admin-link {
  background: rgba(245, 158, 11, 0.12);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: all 0.2s;
}

.btn-admin-link:hover {
  background: rgba(245, 158, 11, 0.22);
}

/* SPREADSHEET TABLE & FREEZE COLUMNS */
.spreadsheet-scroll-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  max-width: 100%;
  scrollbar-width: thin;
  scrollbar-color: #38bdf8 #090e1a;
  scroll-behavior: smooth;
  box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

.spreadsheet-scroll-wrap.is-dragging {
  cursor: grabbing;
  user-select: none;
}

/* Dedicated horizontal scrollbar for the spreadsheet table */
.spreadsheet-scroll-wrap::-webkit-scrollbar {
  height: 10px;
}

.spreadsheet-scroll-wrap::-webkit-scrollbar-track {
  background: #090e1a;
  border-bottom-left-radius: 9px;
  border-bottom-right-radius: 9px;
  border-top: 1px solid rgba(51, 65, 85, 0.4);
}

.spreadsheet-scroll-wrap::-webkit-scrollbar-thumb {
  background: linear-gradient(90deg, #334155 0%, #475569 50%, #334155 100%);
  border-radius: 9999px;
  border: 2px solid #090e1a;
  background-clip: padding-box;
  box-shadow: inset 0 0 4px rgba(255, 255, 255, 0.08);
  transition: all 0.2s ease;
}

.spreadsheet-scroll-wrap::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(90deg, #0284c7 0%, #38bdf8 50%, #0284c7 100%);
  border: 2px solid #090e1a;
  background-clip: padding-box;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
}

.spreadsheet-scroll-wrap::-webkit-scrollbar-thumb:active {
  background: linear-gradient(90deg, #0369a1 0%, #0284c7 100%);
  border: 2px solid #090e1a;
  background-clip: padding-box;
}

.timesheet-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
  background: var(--bg-surface);
}

.timesheet-table th, .timesheet-table td {
  border-right: 1px solid #283548;
  border-bottom: 1px solid #283548;
  text-align: center;
  vertical-align: middle;
  padding: 6px 4px;
}

/* Sticky First Column: Employer */
.timesheet-table .sticky-col-1 {
  position: sticky;
  left: 0;
  z-index: 10;
  width: var(--sticky-col-1);
  min-width: var(--sticky-col-1);
  background: #1a2333;
  text-align: left;
  padding-left: 12px;
  font-weight: 600;
  box-shadow: 2px 0 5px rgba(0,0,0,0.25);
}

/* Sticky Second Column: Work Type */
.timesheet-table .sticky-col-2 {
  position: sticky;
  left: var(--sticky-col-1);
  z-index: 10;
  width: var(--sticky-col-2);
  min-width: var(--sticky-col-2);
  background: #1e293b;
  text-align: left;
  padding-left: 10px;
  font-size: 0.8rem;
  box-shadow: 2px 0 5px rgba(0,0,0,0.25);
}

/* Table Header Row 1: Dates & Days of Week */
.date-header-cell {
  min-width: var(--cell-width);
  width: var(--cell-width);
  padding: 8px 2px;
  background: #172033;
}

.date-header-cell.weekend {
  background: #19233a;
}

.date-header-cell.holiday {
  background: #271d2b;
}

.date-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 700;
  display: block;
}

.weekday-text {
  font-size: 0.72rem;
  color: var(--text-secondary);
  display: block;
  margin-top: 2px;
}

.badge-holiday-tag {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 4px;
  border-radius: 4px;
  margin-top: 3px;
  white-space: nowrap;
  font-weight: 600;
}

.badge-holiday-tag.cn {
  background: rgba(239, 68, 68, 0.25);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-holiday-tag.hk {
  background: rgba(139, 92, 246, 0.25);
  color: #c084fc;
  border: 1px solid rgba(139, 92, 246, 0.4);
}

.badge-holiday-tag.work {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-holiday-tag.rest {
  background: rgba(71, 85, 105, 0.3);
  color: #cbd5e1;
}

/* Input Cell */
.cell-input {
  width: 100%;
  height: 34px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  transition: all 0.15s ease;
}

.cell-input:hover {
  background: rgba(15, 23, 42, 0.8);
  border-color: #475569;
}

.cell-input:focus {
  outline: none;
  background: #0f172a;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.3);
}

.cell-input.has-value {
  color: var(--accent-cyan);
}

.cell-input.overtime-has-value {
  color: #fb923c;
}

.cell-input.just-saved {
  background: rgba(16, 185, 129, 0.25) !important;
  border-color: #10b981 !important;
}

/* Daily Total Footer Row */
.total-cell {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.92rem;
  background: #172033;
}

.total-cell.exceeds-8 {
  color: #fb7185;
  background: rgba(244, 63, 94, 0.15);
}

/* Details & Rules Section */
.details-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 20px;
}

.details-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.rule-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 16px;
}

.rule-box h4 {
  font-size: 0.95rem;
  color: var(--accent-cyan);
  margin-bottom: 8px;
}

.rule-box p, .rule-box ul {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.rule-box ul {
  list-style: none;
}

.formula-code {
  font-family: 'JetBrains Mono', monospace;
  background: #0f172a;
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 8px;
  color: var(--text-primary);
  border: 1px solid #334155;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  width: 440px;
  max-width: 90vw;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

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

.modal-header h3 {
  font-size: 1.1rem;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quick-accounts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-account {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: all 0.2s;
}

.btn-account small {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-account:hover, .btn-account.active {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.08);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.form-input {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

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

.btn-primary {
  background: #0284c7;
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary:hover {
  background: #0369a1;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}

.toast-notification {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  border: 1px solid #38bdf8;
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 9999;
  font-size: 0.88rem;
  display: none;
  animation: slideIn 0.3s ease;
}

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

@media (max-width: 1024px) {
  .summary-hero {
    grid-template-columns: 1fr 1fr;
  }
}
