:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --bg-main: #f8fafc;
  --bg-card: rgba(255, 255, 255, 0.8);
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", "Kanit", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: #3a2b7a;
  color: white;
  padding: 2rem 0;
  display: flex;
  flex-direction: column;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 80px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem 2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar .logo {
  padding: 0;
  border-bottom: none;
  transition: opacity 0.3s;
}

.sidebar.collapsed .logo {
  opacity: 0;
  pointer-events: none;
}

.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar.collapsed .sidebar-toggle-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 2rem;
}

.sidebar nav ul {
  list-style: none;
  margin-top: 2rem;
}

.sidebar nav li {
  padding: 0.8rem 1.5rem;
  margin: 0.2rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: #cbd5e1;
  white-space: nowrap;
}

.sidebar.collapsed nav li {
  padding: 0.8rem 0;
  justify-content: center;
  margin: 0.2rem 0.8rem;
}

.sidebar.collapsed nav li span {
  display: none;
}

.sidebar nav li:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.05);
  color: white;
}

.sidebar nav li.active {
  opacity: 1;
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sidebar nav li i {
  width: 22px;
  height: 22px;
  stroke-width: 2px;
}

/* Content Area */
.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-bar {
  height: 75px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Topbar Company Selector */
.company-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: white;
  padding: 0.6rem 1.25rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  position: relative;
  min-width: 320px;
  max-width: 420px;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.company-selector-wrapper:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
  background: #f8fafc;
}

#company-name-display {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: "Kanit", sans-serif;
}

#company-logo-top {
  width: 34px;
  height: 34px;
  background: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 2px;
  flex-shrink: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
  border: 1px solid #f1f5f9;
}

#company-logo-top img {
  height: 100%;
  width: 100%;
  object-fit: contain;
}

/* Custom Dropdown List */
.company-dropdown-list {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(15px);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow:
    0 10px 25px -5px rgba(0, 0, 0, 0.1),
    0 8px 10px -6px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  padding: 0.5rem;
  display: none;
  flex-direction: column;
  gap: 2px;
  max-height: 400px;
  overflow-y: auto;
  animation: slideUp 0.15s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.company-dropdown-list.active {
  display: flex;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  transition: all 0.2s;
  color: var(--text-main);
  font-weight: 500;
  font-size: 0.9rem;
}

.dropdown-item:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.dropdown-item.selected {
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
  font-weight: 700;
}

.dropdown-item img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  object-fit: contain;
  background: white;
  border: 1px solid #e2e8f0;
}

.selector-icon {
  width: 18px !important;
  height: 18px !important;
  color: var(--text-muted);
  transition: transform 0.3s ease;
}

.company-selector-wrapper.active .selector-icon {
  transform: rotate(180deg);
}

.view-container {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

/* Glassmorphism Card */
.card {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Category Setup */
.category-list {
  list-style: none;
  margin-top: 1.5rem;
}

.category-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
}

.is-master-mode .category-item {
  cursor: grab;
}

.is-master-mode .category-item:active {
  cursor: grabbing;
}

.category-item .actions {
  display: flex;
  gap: 0.5rem;
}

.category-item.is-hidden {
  opacity: 0.4;
  background: #f1f5f9;
}

.category-item.is-hidden b {
  text-decoration: line-through;
}

.category-item.is-total {
  border-left: 5px solid var(--primary);
  font-weight: 600;
}

/* Mode Selector Styling */
.mode-selector {
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05);
}

.mode-selector .btn {
  transition: all 0.2s ease;
  border: 1px solid transparent;
  color: var(--text-muted);
}

.mode-selector .btn.active {
  background: white !important;
  color: var(--primary) !important;
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  font-weight: 600;
}

.nested-list {
  margin-left: 2rem;
  padding-left: 1rem;
  border-left: 2px dashed var(--border);
}

.btn {
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.btn i {
  width: 18px;
  height: 18px;
  stroke-width: 2.2px;
  flex-shrink: 0;
}

.btn-sm {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 8px;
  gap: 0.4rem;
}

.btn-sm i {
  width: 14px;
  height: 14px;
}

.btn-sm span {
  font-weight: 400;
  font-size: 0.75rem;
  opacity: 0.75;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.setup-actions {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.actions-cell {
  display: grid;
  grid-template-columns: repeat(3, 120px);
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
}

.actions-cell .btn-sm {
  width: 100%;
  white-space: nowrap;
}

.slide-sheet-header {
  margin-bottom: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
}

.sheet-close {
  background: #f1f5f9;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #64748b;
  transition: all 0.2s;
}

.sheet-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.help-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Daily Entry Table */
.spreadsheet-container {
  overflow: auto;
  max-height: calc(100vh - 180px);
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
}

table.cashflow-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

table.cashflow-table th,
table.cashflow-table td {
  border: 1px solid var(--border);
  padding: 0.4rem;
  min-width: 70px;
  font-size: 0.8rem;
  text-align: right;
}

table.cashflow-table th {
  background: #f1f5f9;
  position: sticky;
  top: 0;
  z-index: 10;
}

table.cashflow-table thead tr:nth-child(2) th {
  top: 29.5px;
  /* height of row 1 */
  z-index: 9;
}

/* Ensure rowspan="2" sticky columns stay at the very top */
table.cashflow-table th.sticky-col[rowspan="2"] {
  top: 0;
  z-index: 12;
}

table.cashflow-table .sticky-col {
  position: sticky;
  left: 0;
  background: #f8fafc;
  z-index: 11;
  text-align: left;
  min-width: 260px;
  font-weight: 500;
  white-space: nowrap;
}

table.cashflow-table th.sticky-col {
  z-index: 12;
}

.cell-input {
  width: 100%;
  border: none;
  background: transparent;
  text-align: right;
  font-family: inherit;
  padding: 2px;
}

.cell-input:focus {
  background: #e0f2fe;
  outline: none;
}

.cell-input[readonly] {
  background: #f8fafc;
  color: #64748b;
  cursor: default;
  font-weight: 600;
}

/* Consolidated Specifics */
.consolidated-view .sub-header {
  font-size: 0.7rem;
  padding: 2px;
  background: #f8fafc;
  text-align: center;
}

.plan-col {
  background: white;
}

.actual-col {
  background: #fcfdfd;
  border-left: 1px solid #edf2f7;
}

.plan-col.total-cell {
  background: #f1f5f9;
  color: var(--primary);
}

.actual-col.total-cell {
  background: #f1f5f9;
  color: #166534;
}

.toggle-icon {
  width: 16px;
  height: 16px;
  color: #94a3b8;
  transition: transform 0.2s;
}

.is-collapsed .toggle-icon {
  color: var(--primary);
}

.sticky-col:hover .toggle-icon {
  color: var(--primary);
}

.consolidated-view th[colspan="2"] {
  border-bottom: none;
}

.row-indent-0 .sticky-col {
  padding-left: 1rem !important;
}

.row-indent-1 .sticky-col {
  padding-left: 2rem !important;
}

.row-indent-2 .sticky-col {
  padding-left: 3.5rem !important;
}

.row-indent-3 .sticky-col {
  padding-left: 5rem !important;
}

.row-indent-4 .sticky-col {
  padding-left: 6.5rem !important;
}

.row-indent-5 .sticky-col {
  padding-left: 8rem !important;
}

.row-indent-6 .sticky-col {
  padding-left: 9.5rem !important;
}

.row-indent-7 .sticky-col {
  padding-left: 11rem !important;
}

.row-indent-8 .sticky-col {
  padding-left: 12.5rem !important;
}

.row-indent-9 .sticky-col {
  padding-left: 14rem !important;
}

.row-indent-10 .sticky-col {
  padding-left: 15.5rem !important;
}

.auto-total td {
  border-top: 1px solid var(--border);
  border-bottom: 2px double var(--border);
}

.auto-total i {
  font-style: normal;
  font-weight: 700;
}

.table-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.month-selector input[type="month"] {
  background: white;
  border: 1px solid var(--border);
  padding: 0.6rem 1.25rem;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  outline: none;
  min-width: 220px;
}

.month-selector input[type="month"]:hover {
  border-color: var(--primary);
  background: #f8fafc;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}

.month-selector input[type="month"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: white;
}

.search-wrapper {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px !important;
  height: 18px !important;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

.search-wrapper .input-premium {
  padding-left: 3rem;
  background: white;
}

.toggle-group {
  background: #e2e8f0;
  padding: 0.25rem;
  border-radius: 8px;
  display: flex;
}

.toggle-btn {
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.toggle-btn.active {
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  color: var(--primary);
}

.loader {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  padding: 4rem;
  color: var(--text-muted);
  font-family: "Kanit", sans-serif;
  font-weight: 500;
  width: 100%;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #f1f5f9;
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
  position: relative;
}

.spinner::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 4px solid transparent;
  border-bottom: 4px solid rgba(37, 99, 235, 0.3);
  border-radius: 50%;
  animation: spin 1.5s linear infinite reverse;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  border-radius: inherit;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* Badges for Category Indicators */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  margin-left: 0.5rem;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-special {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.badge-deduction {
  background: #fef2f2;
  color: #ef4444;
  border: 1px solid #fee2e2;
}

.badge-autosum {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

.category-item.has-autosum {
  border-left: 5px solid #22c55e;
}

.category-item.is-virtual-total {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  opacity: 0.7;
  margin-top: -0.25rem;
  margin-bottom: 0.75rem;
  pointer-events: none;
  /* Make it unclickable and non-draggable */
}

.virtual-row {
  cursor: default !important;
}

/* Slide Sheet (Drawer) */
.slide-sheet-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.slide-sheet-overlay.active {
  display: block;
  opacity: 1;
}

.slide-sheet {
  position: fixed;
  top: 0;
  right: -560px;
  width: 560px;
  max-width: 95%;
  height: 100%;
  background: white;
  z-index: 1001;
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.08);
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.slide-sheet.active {
  right: 0;
}

.slide-sheet.large {
  width: 80%;
  right: -80%;
}

.slide-sheet.large.active {
  right: 0;
}

.slide-sheet-header {
  padding: 1.75rem 2rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
}

.slide-sheet-header h3 {
  font-family: "Kanit", sans-serif;
  font-weight: 600;
  font-size: 1.25rem;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.slide-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  padding-bottom: 8rem;
  /* Extra space for footer button */
}

.store-link {
    text-decoration: none;
    color: inherit;
    display: inline-block;
    transition: all 0.2s;
}

.store-link code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    color: #475569;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
}

.store-link:hover code {
    background: #e0f2fe;
    color: #0369a1;
    border-color: #bae6fd;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(3, 105, 161, 0.1);
}

.sheet-section {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px dashed var(--border);
}

.sheet-section:last-child {
  border-bottom: none;
}

.sheet-title {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.entry-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s;
}

.entry-item:hover {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.entry-info b {
  display: block;
  font-size: 1rem;
  color: var(--primary);
}

.entry-info small {
  color: var(--text-muted);
}

.bank-badge {
  display: inline-block;
  padding: 2px 8px;
  background: #e2e8f0;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 4px;
}

/* Form Styles in Sheet */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  font-weight: 500;
  margin-bottom: 0.6rem;
  display: block;
  font-size: 0.8rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: "Kanit", sans-serif;
}

.input-premium {
  width: 100%;
  padding: 0.85rem 1.15rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 500;
  color: #1e293b;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
  background: #f8fafc;
}

.input-premium:focus {
  background: white;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}

.input-premium::placeholder {
  color: #94a3b8;
  font-weight: 400;
}

/* File input customization */
input[type="file"].input-premium {
  padding: 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.slide-sheet-header small {
  display: block;
  color: #64748b;
  font-weight: 500;
  margin-top: 2px;
}

.sheet-form-card {
  background: #f8fafc;
  padding: 1.5rem;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  margin-bottom: 2rem;
}

.btn-premium {
  width: 100%;
  padding: 1rem;
  font-weight: 700;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: none;
  font-size: 1.1rem;
  background: var(--primary);
  color: white;
  box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.25);
}

.btn-premium:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 20px -3px rgba(37, 99, 235, 0.35);
  background: var(--primary-hover);
}

.btn-premium:active {
  transform: translateY(0);
}

.btn-premium i {
  width: 22px;
  height: 22px;
}

.slide-sheet-footer {
  padding: 1.5rem 2rem;
  background: white;
  border-top: 1px solid #f1f5f9;
  position: sticky;
  bottom: 0;
  z-index: 10;
  box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.03);
}


/* Dashboard Layout Overhaul */
.dashboard-wrapper {
  display: flex !important;
  flex-direction: column !important;
  gap: 2rem !important;
  padding: 1.5rem 0;
  width: 100%;
}

.dashboard-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 1.5rem 2rem;
  border-radius: 20px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.view-title {
  font-family: "Kanit", sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
}

.view-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.dashboard-content {
  flex: 1 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 1.5rem !important;
  min-width: 0 !important;
}

.filter-group {
  margin-bottom: 2rem;
  background: #f8fafc;
  padding: 1.5rem;
  border-radius: 16px;
  border: 1px solid #f1f5f9;
}

.filter-group label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 1rem;
  font-size: 1rem;
}

.timeframe-toggle {
  display: flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 12px;
}

.btn-time {
  flex: 1;
  border: none;
  background: transparent;
  padding: 0.6rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-time.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.company-checkbox-list {
  max-height: 350px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 12px;
  border: 1px solid #f1f5f9;
}

.comp-check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.comp-check-item:hover {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.comp-check-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.comp-logo-mini {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: contain;
  background: white;
  border: 1px solid #f1f5f9;
  flex-shrink: 0;
}

.comp-logo-mini.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
  color: #64748b;
}

.comp-logo-mini.fallback i {
  width: 14px;
  height: 14px;
}

.comp-check-item span {
  font-size: 0.95rem;
  color: #334155;
  font-weight: 500;
}

/* Summary Cards */
.dashboard-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
}

.summary-card {
  background: white;
  padding: 1.75rem;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  border: 1px solid #f1f5f9;
}

.card-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon i {
  width: 28px;
  height: 28px;
}

.summary-card.plan .card-icon {
  background: #eff6ff;
  color: #3b82f6;
}

.summary-card.actual .card-icon {
  background: #f0fdf4;
  color: #22c55e;
}

.summary-card.plan-out .card-icon {
  background: #fff7ed;
  color: #f97316;
}

.summary-card.actual-out .card-icon {
  background: #fef2f2;
  color: #ef4444;
}

.card-info span {
  font-size: 0.85rem;
  color: #64748b;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.card-info h2 {
  margin: 0.2rem 0 0;
  font-size: 1.75rem;
  font-weight: 800;
  color: #0f172a;
}

.hidden {
  display: none !important;
}

/* Executive Charts */
.executive-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 1.5rem;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  height: 400px;
  box-shadow: 
    0 4px 6px -1px rgba(0, 0, 0, 0.05),
    0 10px 15px -3px rgba(0, 0, 0, 0.03),
    inset 0 0 20px rgba(255, 255, 255, 0.5);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chart-card:hover {
  transform: translateY(-5px);
  box-shadow: 
    0 20px 25px -5px rgba(0, 0, 0, 0.05),
    0 10px 10px -5px rgba(0, 0, 0, 0.02);
}

/* Main trend styling can be added here if needed */

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.chart-header h4 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.chart-body {
  flex: 1;
  position: relative;
  min-height: 0;
}

@media (max-width: 1024px) {
  .executive-charts-grid {
    grid-template-columns: 1fr;
  }
  .chart-card.main-trend {
    grid-column: span 1;
  }
}

/* Layer Matrix Specific Styles - High Specificity */
#main-view .table-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

#main-view .export-btn {
    display: flex !important;
    align-items: center !important;
    background: #1f1f1f !important;
    color: white !important;
    border: none !important;
    border-radius: 20px !important;
    padding: 0 !important;
    cursor: pointer !important;
    overflow: hidden !important;
    font-family: "Kanit", sans-serif !important;
    transition: all 0.2s ease !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    height: 30px !important;
}

#main-view .export-btn:hover {
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15) !important;
    background: #000 !important;
}

#main-view .export-text {
    padding: 6px 18px !important;
    font-size: 0.7rem !important;
    font-weight: 700 !important;
    letter-spacing: 0.8px !important;
}

#main-view .export-icon {
    background: #a0a0a0 !important;
    padding: 6px 12px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 100% !important;
}

#main-view .export-icon i {
    width: 14px !important;
    height: 14px !important;
    stroke: white !important;
    stroke-width: 3px !important;
}

#main-view .matrix-toggle-container {
    margin-top: 15px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

#main-view .time-nav-section {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#main-view .matrix-toggle-group {
    display: inline-flex !important;
    background: #a0a0a0 !important;
    border-radius: 20px !important;
    padding: 2px !important;
    gap: 2px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
    width: 280px !important;
    height: 30px !important;
    align-items: center !important;
    flex-shrink: 0 !important;
}

#main-view .time-nav-section .matrix-toggle-group {
    width: 420px !important;
}

#main-view .m-toggle-btn {
    flex: 1 !important;
    border: none !important;
    background: transparent !important;
    color: white !important;
    padding: 0 8px !important;
    height: 26px !important;
    font-family: "Kanit", sans-serif !important;
    font-size: 0.7rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    border-radius: 18px !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

#main-view .m-toggle-btn.active {
    background: #1f1f1f !important;
    color: white !important;
    font-weight: 600 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important;
}

#main-view .m-toggle-btn:hover:not(.active) {
    background: rgba(255,255,255,0.1) !important;
}

#main-view .custom-date-wrapper {
    display: none;
    align-items: center !important;
    gap: 8px !important;
    background: #f8fafc !important;
    padding: 0 10px !important;
    height: 30px !important;
    border-radius: 20px !important;
    border: 1px solid #e2e8f0 !important;
}

#main-view .premium-date-input {
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    padding: 1px 4px !important;
    font-size: 0.7rem !important;
    height: 22px !important;
    width: 100px !important;
    font-family: "Kanit", sans-serif !important;
    color: #334155 !important;
    outline: none !important;
}

#main-view .apply-date-btn {
    background: #1f1f1f !important;
    color: white !important;
    border: none !important;
    width: 22px !important;
    height: 22px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    transition: transform 0.2s !important;
    padding: 0 !important;
}

#main-view .apply-date-btn:hover {
    transform: scale(1.1) !important;
}

#main-view .apply-date-btn i {
    width: 12px !important;
    height: 12px !important;
}

#main-view .cashflow-table {
    border-collapse: collapse !important; /* Fixed: collapse is more reliable for sticky offsets */
    border-spacing: 0 !important;
    width: 100% !important;
}

#main-view .cashflow-table thead th {
    height: 48px !important;
    padding: 8px 10px !important;
    vertical-align: middle !important;
    background-color: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    color: #475569 !important;
    font-weight: 600 !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    white-space: nowrap !important;
    left: auto !important;
}

#main-view .sub-header-cell {
    background-color: #eff6ff !important;
    height: 48px !important;
    font-size: 0.75rem !important;
    color: #1e40af !important;
    position: sticky !important;
    top: 48px !important;
    z-index: 99 !important;
    white-space: nowrap !important;
}

#main-view .cashflow-table td {
    border: 1px solid #f1f5f9 !important;
    padding: 10px 15px !important;
    font-size: 0.85rem !important;
    color: #334155 !important;
    background-color: #ffffff !important;
}

#main-view .spreadsheet-container {
    overflow: auto !important;
    max-width: 100% !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    background: white !important;
    position: relative !important;
    max-height: 75vh !important;
}

#main-view .row-indent-0 {
    background-color: #f8fafc !important;
    cursor: pointer !important;
}

#main-view .row-indent-1 {
    background-color: #ffffff !important;
}

#main-view .row-indent-0:hover, 
#main-view .row-indent-1:hover {
    background-color: #f1f5f9 !important;
}

/* Sticky Column Logic */
#main-view .sticky-col {
    position: sticky !important;
    left: 0 !important;
    z-index: 50 !important;
    background-color: #ffffff !important;
    border-right: 2px solid #e2e8f0 !important;
    box-shadow: 4px 0 8px -4px rgba(0,0,0,0.1) !important;
}

/* Specific background colors for ALL cells in special rows */
#main-view tr.row-indent-0 td, 
#main-view tr.row-indent-0 .sticky-col,
#main-view tr.row-indent-0 .total-cell,
#main-view tr.row-indent-0 .actual-col { 
    background-color: #cbd5e1 !important; 
    color: #1e3a8a !important; 
} 

#main-view tr.store-count-row td,
#main-view tr.store-count-row .sticky-col,
#main-view tr.store-count-row .total-cell,
#main-view tr.store-count-row .actual-col { 
    background-color: #dcfce7 !important; 
    color: #166534 !important; 
} 

#main-view .row-indent-1 .sticky-col { background-color: #ffffff !important; }

/* Intersection Cells (Corner Pieces) */
#main-view thead tr:nth-child(1) th:not(.sticky-col) {
    left: auto !important;
    z-index: 110 !important;
}

#main-view thead tr:nth-child(2) th {
    position: sticky !important;
    top: 48px !important;
    z-index: 109 !important;
    height: 48px !important;
    background-color: #eff6ff !important;
}

#main-view thead th.sticky-col {
    z-index: 130 !important;
    top: 0 !important;
    left: 0 !important;
    background-color: #f8fafc !important;
    position: sticky !important;
}

#main-view .sub-header-cell.sticky-col {
    z-index: 129 !important;
    top: 47px !important; /* Adjusted for collapse overlap */
    left: 0 !important;
    background-color: #eff6ff !important;
    position: sticky !important;
}

#main-view .actual-col {
    color: #059669 !important;
    font-weight: 600 !important;
}

#main-view .total-cell {
    background: #f8fafc !important;
}

#main-view .row-total b {
    color: #1e3a8a !important;
}

#main-view .store-count-row {
    background: #dcfce7 !important;
}

#main-view .store-count-row td {
    color: #166534 !important;
    font-weight: 700 !important;
    border-bottom: 2px solid #bbf7d0 !important;
    position: sticky !important;
    top: 93px !important; 
    z-index: 108 !important;
    background-color: #dcfce7 !important;
    height: 48px !important;
}

#main-view .store-count-row td.sticky-col {
    z-index: 128 !important;
    top: 93px !important;
    left: 0 !important;
}

#main-view .row-indent-1 .sticky-col { background-color: #ffffff !important; }
#main-view .row-indent-0 .sticky-col { background-color: #f8fafc !important; }

#main-view .toggle-icon {
    transition: transform 0.2s ease;
    width: 14px;
    height: 14px;
    color: #64748b;
}

#main-view .toggle-icon.collapsed {
    transform: rotate(-90deg);
}

#main-view .collapsed-row {
    display: none !important;
}

#main-view .clickable-cell {
    cursor: pointer;
    transition: background 0.2s;
}

#main-view .clickable-cell:hover {
    background: #eff6ff !important;
    color: #2563eb !important;
}

/* Slide Sheet Specific Styles (NOT in #main-view) */
.detail-summary-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 1.5rem !important;
    margin-bottom: 2rem !important;
}

.summary-item {
    padding: 1.25rem !important;
    background: white !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    text-align: center !important;
}

.summary-item .label {
    display: block !important;
    font-size: 0.8rem !important;
    color: #64748b !important;
    margin-bottom: 0.5rem !important;
}

.summary-item .value {
    display: block !important;
    font-size: 1.5rem !important;
    font-weight: 700 !important;
    color: #1e293b !important;
}

.status-badge {
    padding: 2px 8px !important;
    border-radius: 4px !important;
    font-size: 0.7rem !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    display: inline-block !important;
}

.status-unsold { background: #fee2e2 !important; color: #ef4444 !important; }
.status-sold { background: #dcfce7 !important; color: #166534 !important; }

.detail-table th {
    background: #f8fafc !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    border: 1px solid #e2e8f0 !important;
    text-align: left !important;
    padding: 12px 15px !important;
    vertical-align: middle !important;
    color: #475569 !important;
}

.detail-table td {
    padding: 10px 15px !important;
    font-size: 0.85rem !important;
    border: 1px solid #f1f5f9 !important;
    vertical-align: middle !important;
}

.row-has-sale { background: #f0fdf4 !important; }
.row-has-sale:hover { background: #dcfce7 !important; }
.row-no-sale { background: #fff !important; }
.row-no-sale:hover { background: #f8fafc !important; }

.store-sale-amount {
    font-family: inherit !important;
    font-weight: 700 !important;
    font-size: 1.1rem !important;
    color: #059669 !important;
}

/* Marketing Matrix New Layout */
.marketing-new-layout th {
    white-space: normal;
    line-height: 1.2;
    padding: 8px 4px !important;
}

.marketing-new-layout .sub-header-cell {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: #f8fafc;
}

.marketing-new-layout td {
    padding: 10px 8px !important;
    font-size: 0.85rem;
}

.marketing-new-layout .text-primary {
    color: var(--primary) !important;
}

.marketing-new-layout .text-danger {
    color: #ef4444 !important;
}

.marketing-new-layout .row-total {
    background: #f8fafc;
}

.marketing-new-layout .sticky-col {
    min-width: 180px;
    font-weight: 700 !important;
    background: #fff !important;
    border-right: 2px solid var(--border);
}

.spreadsheet-container:has(.marketing-new-layout) {
    max-height: calc(100vh - 220px);
}
