* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  color: #e8e8e8;
}

.wrap {
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
  background: linear-gradient(90deg, #00d9ff, #00ff88);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  margin: 0;
  color: #8892a6;
  font-size: 0.95rem;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 1.25rem 2rem;
  text-align: center;
  min-width: 160px;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: #00d9ff;
}

.stat-label {
  font-size: 0.85rem;
  color: #8892a6;
}

.table-section {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 1.5rem;
  overflow: hidden;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.year-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.year-select-label {
  color: #8892a6;
  font-size: 0.9rem;
}

.year-select {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}

.year-select option {
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
}

.year-select:hover,
.year-select:focus {
  border-color: rgba(0, 217, 255, 0.4);
  outline: none;
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
}

.loading,
.error {
  padding: 1.5rem;
  text-align: center;
}

.error {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.1);
  border-radius: 8px;
}

.browser-fallback {
  padding: 1rem;
  margin-top: 1rem;
  background: rgba(0, 217, 255, 0.08);
  border: 1px solid rgba(0, 217, 255, 0.2);
  border-radius: 8px;
}

.browser-fallback p {
  margin: 0 0 0.75rem 0;
  color: #a0aec0;
  font-size: 0.9rem;
}

.btn-browser {
  background: #00d9ff;
  color: #0f3460;
}

.btn-browser:hover {
  background: #00b8e6;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.deals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.deals-table th,
.deals-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.deals-table th {
  color: #8892a6;
  font-weight: 600;
  white-space: nowrap;
}

.deals-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.deals-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.deals-table .date {
  white-space: nowrap;
  color: #a0aec0;
}

.deals-table .name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deals-table .row-label {
  font-weight: 600;
  color: #e8e8e8;
  min-width: 140px;
}

.months-table {
  table-layout: fixed;
  width: 100%;
}

.months-table th,
.months-table td {
  min-width: 0;
  width: calc((100% - 140px) / 12);
  padding: 0.5rem 0.4rem;
  font-size: 0.85rem;
}

.months-table th:first-child,
.months-table td:first-child {
  width: 140px;
}

.table-section-second {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.section-title {
  margin: 0 0 1rem 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: #e8e8e8;
}

/* Диаграмма по месяцам */
.chart-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chart-title {
  margin: 0 0 1rem 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: #e8e8e8;
}

.chart-legend {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: #8892a6;
}

.chart-scroll-hint {
  margin: 0 0 1.25rem 0;
  font-size: 0.8rem;
  color: #6b7280;
}

.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.5rem;
  margin-top: 0.5rem;
}

.chart-scroll::-webkit-scrollbar {
  height: 8px;
}

.chart-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
}

.chart-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.chart-legend-item::before {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 0.4rem;
  vertical-align: middle;
  content: "";
  border-radius: 2px;
}

.chart-legend-budget::before { background: #facc15; }
.chart-legend-rent::before { background: #f97316; }
.chart-legend-kitchen::before { background: #ef4444; }

.chart-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 2rem;
  min-height: 240px;
  min-width: min-content;
  padding: 0 0.5rem;
}

.chart-month {
  flex: 0 0 auto;
  width: 220px;
  min-width: 220px;
  max-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 1rem;
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  box-sizing: border-box;
}

.chart-month:first-child {
  padding-left: 0;
  border-left: none;
}

.chart-month-label {
  font-size: 0.8rem;
  color: #8892a6;
  height: 2.5rem;
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.5rem;
  white-space: nowrap;
  flex-shrink: 0;
  flex-grow: 0;
}

.chart-month-bars {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 400px;
  box-sizing: border-box;
}

.chart-bar-wrap {
  flex: 1;
  min-width: 0;
  max-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chart-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  transition: opacity 0.15s;
}

.chart-bar:hover {
  opacity: 0.9;
}

.chart-bar-value {
  font-size: 0.65rem;
  color: #a0aec0;
  margin-top: 4px;
  text-align: center;
  word-break: break-all;
  line-height: 1.2;
  max-height: 2.4em;
  overflow: hidden;
}

.chart-bar-budget { background: #facc15; }
.chart-bar-rent { background: #f97316; }
.chart-bar-kitchen { background: #ef4444; }

@media (max-width: 768px) {
  .table-wrap {
    margin-left: -0.25rem;
    margin-right: -0.25rem;
  }
  .months-table {
    min-width: 1140px;
    table-layout: fixed;
  }
  .months-table th:first-child,
  .months-table td:first-child {
    width: 120px;
    min-width: 120px;
  }
  .months-table th:not(:first-child),
  .months-table td:not(:first-child) {
    min-width: 85px;
    width: 85px;
    white-space: normal;
    word-break: break-word;
  }
  .deals-table th,
  .deals-table td {
    padding: 0.5rem 0.4rem;
    font-size: 0.8rem;
  }
  .deals-table .name {
    max-width: 140px;
  }
  .deals-table .row-label {
    min-width: 120px;
  }
  .chart-month {
    width: 180px;
    min-width: 180px;
    max-width: 180px;
  }
  .chart-month-bars {
    gap: 8px;
    min-height: 400px;
  }
  .chart-bar-wrap {
    min-width: 0;
  }
  .chart-bar-value {
    font-size: 0.55rem;
  }
}

/* Экран входа по паролю */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 1000;
}

.login-box {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 2rem 2.5rem;
  min-width: 320px;
  max-width: 90vw;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-title {
  margin: 0 0 0.25rem 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #e8e8e8;
}

.login-subtitle {
  margin: 0 0 1.5rem 0;
  color: #8892a6;
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-input {
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  color: #e8e8e8;
  outline: none;
}

.login-input:focus {
  border-color: #00d9ff;
  box-shadow: 0 0 0 2px rgba(0, 217, 255, 0.2);
}

.login-input::placeholder {
  color: #8892a6;
}

.btn-login {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: #1a1a2e;
  background: linear-gradient(135deg, #00d9ff, #00ff88);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-login:hover:not(:disabled) {
  opacity: 0.9;
}

.btn-login:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-message {
  margin: 0;
  font-size: 0.9rem;
  color: #8892a6;
}

.login-message-error {
  color: #f87171;
}
