/* ===========================
   CSS VARIABLES - Supabase Design System
   =========================== */
:root {
  --background: oklch(0.9911 0 0);
  --foreground: oklch(0.2046 0 0);
  --card: oklch(0.9911 0 0);
  --card-foreground: oklch(0.2046 0 0);
  --popover: oklch(0.9911 0 0);
  --popover-foreground: oklch(0.4386 0 0);
  --primary: oklch(0.8348 0.1302 160.9080);
  --primary-foreground: oklch(0.2626 0.0147 166.4589);
  --secondary: oklch(0.9940 0 0);
  --secondary-foreground: oklch(0.2046 0 0);
  --muted: oklch(0.9461 0 0);
  --muted-foreground: oklch(0.2435 0 0);
  --accent: oklch(0.9461 0 0);
  --accent-foreground: oklch(0.2435 0 0);
  --destructive: oklch(0.5523 0.1927 32.7272);
  --destructive-foreground: oklch(0.9934 0.0032 17.2118);
  --border: oklch(0.9037 0 0);
  --input: oklch(0.9731 0 0);
  --ring: oklch(0.8348 0.1302 160.9080);
  --chart-1: oklch(0.8348 0.1302 160.9080);
  --chart-2: oklch(0.6231 0.1880 259.8145);
  --chart-3: oklch(0.6056 0.2189 292.7172);
  --chart-4: oklch(0.7686 0.1647 70.0804);
  --chart-5: oklch(0.6959 0.1491 162.4796);
  --sidebar: oklch(0.9911 0 0);
  --sidebar-foreground: oklch(0.5452 0 0);
  --sidebar-primary: oklch(0.8348 0.1302 160.9080);
  --sidebar-primary-foreground: oklch(0.2626 0.0147 166.4589);
  --sidebar-accent: oklch(0.9461 0 0);
  --sidebar-accent-foreground: oklch(0.2435 0 0);
  --sidebar-border: oklch(0.9037 0 0);
  --sidebar-ring: oklch(0.8348 0.1302 160.9080);

  --font-sans: Outfit, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  --font-mono: 'SF Mono', 'Monaco', 'Courier New', monospace;

  --radius: 0.5rem;
  --radius-sm: calc(var(--radius) - 0.25rem);
  --radius-md: calc(var(--radius) - 0.125rem);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 0.25rem);

  --shadow-2xs: 0px 1px 3px 0px hsl(0 0% 0% / 0.09);
  --shadow-xs: 0px 1px 3px 0px hsl(0 0% 0% / 0.09);
  --shadow-sm: 0px 1px 3px 0px hsl(0 0% 0% / 0.17), 0px 1px 2px -1px hsl(0 0% 0% / 0.17);
  --shadow: 0px 1px 3px 0px hsl(0 0% 0% / 0.17), 0px 1px 2px -1px hsl(0 0% 0% / 0.17);
  --shadow-md: 0px 1px 3px 0px hsl(0 0% 0% / 0.17), 0px 2px 4px -1px hsl(0 0% 0% / 0.17);
  --shadow-lg: 0px 1px 3px 0px hsl(0 0% 0% / 0.17), 0px 4px 6px -1px hsl(0 0% 0% / 0.17);
  --shadow-xl: 0px 1px 3px 0px hsl(0 0% 0% / 0.17), 0px 8px 10px -1px hsl(0 0% 0% / 0.17);
  --shadow-2xl: 0px 1px 3px 0px hsl(0 0% 0% / 0.43);

  --tracking-normal: 0.025em;

  /* Typography sizes */
  --font-title: 28px;
  --font-table-header: 12px;
  --font-table-cell: 14px;
  --font-total: 16px;
}

.dark {
  --background: oklch(0.1822 0 0);
  --foreground: oklch(0.9288 0.0126 255.5078);
  --card: oklch(0.2046 0 0);
  --card-foreground: oklch(0.9288 0.0126 255.5078);
  --popover: oklch(0.2603 0 0);
  --popover-foreground: oklch(0.7348 0 0);
  --primary: oklch(0.4365 0.1044 156.7556);
  --primary-foreground: oklch(0.9213 0.0135 167.1556);
  --secondary: oklch(0.2603 0 0);
  --secondary-foreground: oklch(0.9851 0 0);
  --muted: oklch(0.2393 0 0);
  --muted-foreground: oklch(0.7122 0 0);
  --accent: oklch(0.3132 0 0);
  --accent-foreground: oklch(0.9851 0 0);
  --destructive: oklch(0.3123 0.0852 29.7877);
  --destructive-foreground: oklch(0.9368 0.0045 34.3092);
  --border: oklch(0.2809 0 0);
  --input: oklch(0.2603 0 0);
  --ring: oklch(0.8003 0.1821 151.7110);
  --chart-1: oklch(0.8003 0.1821 151.7110);
  --chart-2: oklch(0.7137 0.1434 254.6240);
  --chart-3: oklch(0.7090 0.1592 293.5412);
  --chart-4: oklch(0.8369 0.1644 84.4286);
  --chart-5: oklch(0.7845 0.1325 181.9120);
  --sidebar: oklch(0.1822 0 0);
  --sidebar-foreground: oklch(0.6301 0 0);
  --sidebar-primary: oklch(0.4365 0.1044 156.7556);
  --sidebar-primary-foreground: oklch(0.9213 0.0135 167.1556);
  --sidebar-accent: oklch(0.3132 0 0);
  --sidebar-accent-foreground: oklch(0.9851 0 0);
  --sidebar-border: oklch(0.2809 0 0);
  --sidebar-ring: oklch(0.8003 0.1821 151.7110);
}

/* ===========================
   RESET & BASE
   =========================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  color: var(--foreground);
  background: var(--secondary);
  line-height: 1.6;
  letter-spacing: var(--tracking-normal);
}

/* ===========================
   LAYOUT
   =========================== */
.container {
  max-width: 100%;
  padding: 32px;
  min-height: 100vh;
}

.page-title {
  font-size: var(--font-title);
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 28px;
  line-height: 1.2;
  letter-spacing: -0.5px;
}

.content {
  animation: fadeIn 0.4s ease;
}

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

/* ===========================
   DASHBOARD CARDS
   =========================== */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-primary {
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
}

.card-primary .card-header {
  color: var(--primary-foreground);
  opacity: 0.9;
}

.card-primary .card-value {
  color: var(--primary-foreground);
}

.card-primary .card-subtext {
  color: var(--primary-foreground);
  opacity: 0.8;
}

.card-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted-foreground);
  margin-bottom: 8px;
}

.card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 2px;
  letter-spacing: -1px;
}

.card-subtext {
  font-size: 13px;
  color: var(--muted-foreground);
}

.currency-summary,
.top-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.currency-item,
.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
}

.currency-item:last-child,
.category-item:last-child {
  border-bottom: none;
}

.currency-label,
.category-label {
  color: var(--muted-foreground);
  font-weight: 500;
}

.currency-value,
.category-value {
  color: var(--foreground);
  font-weight: 600;
  font-family: var(--font-mono);
}

/* ===========================
   TABLE STYLES
   =========================== */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  background: var(--card);
  border: 1px solid var(--border);
}

/* Custom scrollbar */
.table-scroll::-webkit-scrollbar {
  height: 12px;
}

.table-scroll::-webkit-scrollbar-track {
  background: var(--secondary);
  border-radius: 6px;
}

.table-scroll::-webkit-scrollbar-thumb {
  background: var(--muted-foreground);
  border-radius: 6px;
  border: 2px solid var(--secondary);
}

.table-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
  opacity: 0.8;
}

table {
  width: 100%;
  min-width: 1800px;
  border-collapse: collapse;
  background: var(--card);
}

/* ===========================
   TABLE HEADER
   =========================== */
thead {
  background: var(--muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

th {
  padding: 14px 16px;
  text-align: left;
  font-size: var(--font-table-header);
  font-weight: 600;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  white-space: nowrap;
  border-right: 1px solid var(--border);
}

th:last-child {
  border-right: none;
}

th.col-number {
  text-align: right;
}

/* ===========================
   TABLE BODY
   =========================== */
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background-color: var(--secondary);
}

tbody tr:last-child {
  border-bottom: none;
}

td {
  padding: 13px 16px;
  font-size: var(--font-table-cell);
  color: var(--foreground);
  white-space: nowrap;
  border-right: 1px solid var(--border);
}

td:last-child {
  border-right: none;
}

/* Number columns */
td.col-number {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 500;
}

/* Text columns with wrapping */
td.col-description,
td.col-deal-name {
  max-width: 300px;
  white-space: normal;
  line-height: 1.4;
}

/* ===========================
   TABLE FOOTER (TOTAL)
   =========================== */
tfoot {
  background: var(--muted);
  border-top: 2px solid var(--border);
}

tfoot td {
  padding: 16px;
  font-weight: 700;
  font-size: var(--font-total);
  color: var(--foreground);
}

tfoot td.total-label {
  text-align: right;
  padding-right: 24px;
}

tfoot td.total-amount {
  font-family: var(--font-mono);
  color: var(--primary);
  font-size: 18px;
}

/* ===========================
   STATUS BADGE
   =========================== */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.status-badge.paid,
.status-badge.оплачено {
  background: oklch(from var(--chart-1) l c h / 0.2);
  color: oklch(0.45 0.13 160.9080);
}

.status-badge.pending,
.status-badge.ожидание {
  background: oklch(from var(--chart-4) l c h / 0.2);
  color: oklch(0.55 0.16 70.0804);
}

.status-badge.cancelled,
.status-badge.отменено {
  background: oklch(from var(--destructive) l c h / 0.2);
  color: oklch(0.4 0.19 32.7272);
}

/* ===========================
   DEAL LINK
   =========================== */
.deal-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.deal-link:hover {
  color: var(--ring);
  text-decoration: underline;
}

/* ===========================
   EXPORT BUTTONS
   =========================== */
.export-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.btn-export {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;

  background: var(--primary);
  color: var(--primary-foreground);

  border: none;
  border-radius: var(--radius);

  font-size: 15px;
  font-weight: 600;

  cursor: pointer;
  transition: all 0.2s ease;

  box-shadow: var(--shadow-sm);
}

.btn-excel {
  background: var(--chart-1);
  color: var(--primary-foreground);
}

.btn-pdf {
  background: var(--destructive);
  color: var(--destructive-foreground);
}

.btn-export:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.btn-export:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-export:disabled {
  background: var(--muted);
  color: var(--muted-foreground);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ===========================
   LOADER
   =========================== */
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  gap: 16px;
  min-height: 400px;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loader-text {
  font-size: 16px;
  color: var(--muted-foreground);
  font-weight: 500;
}

/* ===========================
   ERROR MESSAGE
   =========================== */
.error-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  gap: 24px;
  text-align: center;
  min-height: 400px;
}

.error-icon {
  font-size: 64px;
}

.error-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--destructive);
}

.error-description {
  font-size: 15px;
  color: var(--muted-foreground);
  max-width: 400px;
  line-height: 1.6;
}

.btn-retry {
  padding: 10px 20px;
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
}

.btn-retry:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

/* ===========================
   RESPONSIVE
   =========================== */
@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}

@media (max-width: 768px) {
  .container {
    padding: 16px;
  }

  .page-title {
    font-size: 24px;
    margin-bottom: 20px;
  }

  .dashboard {
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 24px;
  }

  .card {
    padding: 18px;
  }

  .card-value {
    font-size: 28px;
  }

  th, td {
    padding: 10px 12px;
    font-size: 12px;
  }

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

/* ===========================
   UTILITIES
   =========================== */
.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.font-mono {
  font-family: 'SF Mono', 'Monaco', 'Courier New', monospace;
}

.hidden {
  display: none !important;
}
