:root {
  --bg: #0f0f12;
  --surface: #18181c;
  --surface-hover: #1f1f24;
  --border: #2a2a30;
  --text: #e4e4e7;
  --text-muted: #a1a1aa;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --danger: #ef4444;
  --danger-dim: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --chart-green: #22c55e;
  --chart-red: #ef4444;
  --chart-colors: #22c55e #3b82f6 #f59e0b #8b5cf6 #ec4899 #06b6d4 #84cc16 #f97316;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Предотвращение горизонтальной прокрутки */
html, body {
  overflow-x: hidden;
  max-width: 100%;
}

#app {
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Icons */
.icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.icon-sm {
  width: 18px;
  height: 18px;
}

.icon-lg {
  width: 24px;
  height: 24px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.nav-link.active {
  color: var(--accent);
  background: rgba(34, 197, 94, 0.1);
  border-right: 3px solid var(--accent);
}

.nav-link .icon {
  opacity: 0.9;
}

/* Auth layout */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.auth-card .sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 24px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s;
  max-width: 100%;
}

.form-group select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-group input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s, transform 0.05s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 8px;
}

.btn-primary:hover {
  background: var(--accent-dim);
}

.btn-secondary {
  background: var(--surface-hover);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 8px 12px;
  font-size: 0.875rem;
}

.btn-danger:hover {
  background: var(--danger-dim);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8125rem;
}

.auth-card .link-line {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.auth-card .link-line a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.auth-card .link-line a:hover {
  text-decoration: underline;
}

.error-msg {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

/* Main layout */
.main-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 330px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar .logo {
  font-size: 1.15rem;
  font-weight: 700;
  padding: 0 24px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar .logo .icon {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--accent);
}

.sidebar nav {
  flex: 1;
}

.rates-widget {
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

/* Десктопный виджет курсов в сайдбаре */
.sidebar .rates-widget {
  margin: 16px 24px 0;
}

.rates-widget .title {
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rates-widget .rate {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  color: var(--text);
}

.rates-widget .rate span:last-child {
  font-weight: 600;
  color: var(--accent);
}

.rates-widget .date {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Мобильный виджет курсов (по умолчанию скрыт, показывается внизу на мобильных) */
.rates-widget-mobile {
  display: none;
  margin: 16px 16px 24px;
  /* остальное наследует из .rates-widget */
}

.content {
  flex: 1;
  padding: 32px;
  overflow: auto;
}

.content h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.content .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.card h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color 0.2s;
}

.stat-card:hover {
  border-color: var(--surface-hover);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-card.income .value { color: var(--accent); }
.stat-card.expense .value { color: var(--danger); }
.stat-card.balance .value { color: var(--text); }

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 100%;
}

th, td {
  text-align: left;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  word-wrap: break-word;
}

th {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-hover);
  white-space: nowrap;
}

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

tr:hover td {
  background: rgba(255,255,255,0.02);
}

td.cell-icon {
  width: 44px;
  padding-right: 0;
  vertical-align: middle;
}

.amount-positive { color: var(--accent); font-weight: 600; }
.amount-negative { color: var(--danger); font-weight: 600; }

.actions-cell {
  white-space: nowrap;
  width: 1%;
}

.actions-cell .btn {
  margin-left: 4px;
}

/* Category badge with icon */
.cat-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cat-cell .icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.cat-cell .icon-wrap .icon {
  width: 18px;
  height: 18px;
}

/* Inline form */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
  margin-bottom: 0;
}

.inline-form .form-group { 
  margin-bottom: 0;
  flex: 0 0 auto;
  min-width: 200px;
}

.inline-form .form-group.full-row { 
  flex: 1 1 100%;
  min-width: 100%;
}

.inline-form select[name="category_id"] {
  min-width: 220px;
  width: 100%;
}

.inline-form input[type="number"] {
  min-width: 150px;
  width: 100%;
}

.inline-form input[type="date"] {
  min-width: 180px;
  width: 100%;
}

.inline-form .btn {
  flex-shrink: 0;
  margin-top: 0;
}

/* Charts */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.chart-card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.chart-container {
  position: relative;
  height: 280px;
}

/* Адаптивность для планшетов */
@media (max-width: 1024px) {
  .content {
    padding: 24px;
  }
  
  .stats-row {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
  }
  
  .stat-card .value {
    font-size: 1.5rem;
  }
  
  .inline-form .form-group {
    min-width: 180px;
  }
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px 8px;
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-link { padding: 10px 14px; font-size: 0.9rem; }
  /* Прячем десктопный виджет курсов в шапке на мобилках */
  .sidebar .rates-widget-desktop { display: none; }
  /* Мобильный виджет внизу страницы */
  .rates-widget-mobile { display: block; }
  .content { padding: 16px; }
  
  .content h1 {
    font-size: 1.25rem;
  }
  
  .content .subtitle {
    font-size: 0.85rem;
  }
  
  .card {
    padding: 16px;
    margin-bottom: 16px;
  }
  
  .stats-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .stat-card {
    padding: 16px;
  }
  
  .stat-card .value {
    font-size: 1.5rem;
  }
  
  .inline-form {
    flex-direction: column;
    gap: 16px;
  }
  
  .inline-form .form-group {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
    overflow: hidden; /* не даём инпутам выезжать за рамки */
  }
  
  .inline-form select[name="category_id"],
  .inline-form input[type="number"],
  .inline-form input[type="date"] {
    width: 100%;
    max-width: 100%;
    display: block;
  }

  /* На некоторых моб. браузерах date-инпут имеет внутренний min-width */
  .inline-form input[type="date"] {
    min-width: 0 !important;
    inline-size: 100%;
    max-inline-size: 100%;
  }
  
  .inline-form .btn {
    width: 100%;
    margin-top: 0;
  }
  
  .date-input-group {
    flex-direction: column;
    gap: 16px;
  }
  
  .date-input-group .form-group {
    width: 100%;
  }
  
  .date-input-group input[type="date"] {
    max-width: 100%;
    width: 100%;
    min-width: 0;
  }
  
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  table {
    font-size: 0.875rem;
    min-width: 600px;
  }
  
  th, td {
    padding: 10px 12px;
  }
  
  .quick-actions {
    flex-direction: column;
  }
  
  .quick-actions a {
    width: 100%;
    justify-content: center;
  }
  
  .chart-container {
    height: 240px;
  }
  
  .auth-card {
    padding: 24px 20px;
    margin: 16px;
  }
  
  .auth-card h1 {
    font-size: 1.25rem;
  }
}

/* Адаптивность для маленьких мобильных устройств */
@media (max-width: 480px) {
  .content {
    padding: 12px;
  }
  
  .card {
    padding: 12px;
  }
  
  .content h1 {
    font-size: 1.1rem;
  }
  
  .stat-card .value {
    font-size: 1.25rem;
  }
  
  .sidebar .logo {
    font-size: 1.1rem;
    padding: 0 16px 16px;
  }
  
  .nav-link {
    padding: 8px 12px;
    font-size: 0.85rem;
  }
  
  .btn {
    padding: 10px 16px;
    font-size: 0.9rem;
  }
  
  .form-group input,
  .form-group select {
    padding: 10px 12px;
    font-size: 0.95rem;
  }
  
  table {
    font-size: 0.8rem;
    min-width: 500px;
  }
  
  th, td {
    padding: 8px 10px;
  }
  
  .chart-container {
    height: 200px;
  }
  
  .auth-card {
    padding: 20px 16px;
  }
}

/* Quick actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.quick-actions a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  transition: border-color 0.2s, background 0.2s;
}

.quick-actions a:hover {
  border-color: var(--accent);
  background: rgba(34, 197, 94, 0.08);
  color: var(--accent);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

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

/* Группа выбора дат (Аналитика) */
.date-input-group {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.date-input-group .form-group {
  margin-bottom: 0;
}

.date-input-group input[type="date"] {
  max-width: 200px;
}

/* Убираем стрелочки у полей суммы (number input) */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}
