/* ==========================================================================
   Spend Money — Main Stylesheet
   §15 UI Design Specification
   ========================================================================== */

/* Google Fonts — DM Sans + Inter */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Inter:wght@400;500&display=swap');

/* ==========================================================================
   §15.1 Color System
   ========================================================================== */

:root {
  /* Backgrounds */
  --bg-primary:    #16202e;
  --bg-secondary:  #1e2d3d;
  --bg-tertiary:   #243347;
  --bg-hover:      #2a3d55;

  /* Accents */
  --accent-cyan:   #00c8e8;
  --accent-gold:   #f5a623;
  --accent-green:  #4cd964;
  --accent-red:    #ff3b30;

  /* Text */
  --text-primary:  #e8edf2;
  --text-secondary:#8a9bb0;
  --text-muted:    #4a5d72;

  /* UI */
  --border:        #243347;
  --shadow:        rgba(0, 0, 0, 0.4);

  /* Sidebar dimensions */
  --sidebar-width: 60px;
  --topbar-height: 56px;

  /* Chart palette (9 default categories) */
  --cat-groceries:      #4cd964;
  --cat-transport:      #00c8e8;
  --cat-restaurants:    #f5a623;
  --cat-health:         #ff3b30;
  --cat-clothing:       #bf5af2;
  --cat-entertainment:  #ff9f0a;
  --cat-utilities:      #30b0c7;
  --cat-communications: #ffd60a;
  --cat-other:          #636366;
}

/* ==========================================================================
   §15.2 Typography
   ========================================================================== */

body {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  color: var(--text-primary);
}

.amount,
.hero-amount,
.expense-amount {
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.hero-amount {
  font-size: 36px;
  color: var(--accent-cyan);
  line-height: 1.1;
}

.page-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ==========================================================================
   §15.3 Layout Structure
   ========================================================================== */

/* App shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 12px;
  padding-bottom: 12px;
  z-index: 100;
  border-right: 1px solid var(--border);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: var(--accent-cyan);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #000;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  width: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav-item {
  width: 100%;
  position: relative;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 44px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  font-size: 20px;
  position: relative;
}

.sidebar-nav-link:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  text-decoration: none;
}

.sidebar-nav-link.active {
  color: var(--accent-cyan);
  border-left-color: var(--accent-cyan);
  background: rgba(0, 200, 232, 0.08);
  box-shadow: inset 3px 0 8px rgba(0, 200, 232, 0.12);
}

/* Tooltip on hover */
.sidebar-nav-link .nav-tooltip {
  position: absolute;
  left: calc(var(--sidebar-width) + 6px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 200;
}

.sidebar-nav-link:hover .nav-tooltip {
  opacity: 1;
}

/* Sidebar bottom: logout */
.sidebar-bottom {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* ---------- Top Bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 99;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.topbar-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Main Content ---------- */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  padding: 24px;
  min-height: calc(100vh - var(--topbar-height));
  flex: 1;
  animation: fadeIn 0.2s ease;
}

/* ==========================================================================
   §15.12 Animations & Micro-interactions
   ========================================================================== */

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  animation: pulse 1.5s ease-in-out infinite;
  vertical-align: middle;
  margin-right: 6px;
}

.status-dot.dot-error {
  background: var(--accent-red);
}

/* ==========================================================================
   §15.13 Bootstrap 5 Overrides
   ========================================================================== */

body {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid var(--border);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  color: var(--text-primary);
}

.card-body {
  color: var(--text-primary);
}

.table {
  --bs-table-bg: transparent;
  --bs-table-striped-bg: var(--bg-hover);
  --bs-table-hover-bg: var(--bg-hover);
  --bs-table-border-color: var(--border);
  color: var(--text-primary);
}

.table > :not(caption) > * > * {
  background-color: transparent;
  color: var(--text-primary);
}

.table thead th {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
}

.table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s ease;
}

.table tbody tr:hover {
  background: var(--bg-hover) !important;
}

.table tbody td {
  padding: 12px;
  vertical-align: middle;
  border: none;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
}

.modal-header {
  border-bottom: 1px solid var(--border);
}

.modal-footer {
  border-top: 1px solid var(--border);
}

.dropdown-menu {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow);
}

.dropdown-item {
  color: var(--text-primary);
  font-size: 14px;
  padding: 8px 16px;
}

.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.dropdown-divider {
  border-color: var(--border);
}

/* Alert overrides */
.alert {
  border-radius: 8px;
  border: none;
  font-size: 14px;
}

.alert-danger {
  background: rgba(255, 59, 48, 0.15);
  color: #ff6b6b;
}

.alert-success {
  background: rgba(76, 217, 100, 0.15);
  color: #4cd964;
}

.alert-info {
  background: rgba(0, 200, 232, 0.12);
  color: var(--accent-cyan);
}

.alert-warning {
  background: rgba(245, 166, 35, 0.15);
  color: var(--accent-gold);
}

/* Badge overrides */
.badge {
  font-weight: 500;
  font-size: 11px;
}

/* ==========================================================================
   §15.11 Buttons & Forms
   ========================================================================== */

/* Primary button */
.btn-primary {
  background: var(--accent-cyan);
  color: #000;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 8px 20px;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-cyan);
  color: #000;
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 200, 232, 0.3);
}

.btn-primary:active {
  filter: brightness(0.95);
  transform: translateY(0);
}

/* Ghost / outline button */
.btn-outline,
.btn-outline-cyan {
  border: 1px solid var(--accent-cyan);
  color: var(--accent-cyan);
  background: transparent;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 20px;
  transition: background 0.15s ease, color 0.15s ease;
}

.btn-outline:hover,
.btn-outline-cyan:hover {
  background: rgba(0, 200, 232, 0.1);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  padding: 8px 20px;
}

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

.btn-danger {
  background: var(--accent-red);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  padding: 8px 20px;
  transition: filter 0.15s ease;
}

.btn-danger:hover {
  background: var(--accent-red);
  filter: brightness(1.1);
}

.btn-link {
  color: var(--accent-cyan);
  text-decoration: none;
  padding: 0;
}

.btn-link:hover {
  color: var(--accent-cyan);
  filter: brightness(1.2);
}

/* Form inputs */
.form-control,
.form-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 8px;
  font-size: 14px;
  padding: 10px 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-select:focus {
  background: var(--bg-tertiary);
  border-color: var(--accent-cyan);
  color: var(--text-primary);
  box-shadow: 0 0 0 3px rgba(0, 200, 232, 0.15);
  outline: none;
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-control:disabled,
.form-select:disabled {
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
}

.form-text {
  color: var(--text-muted);
  font-size: 12px;
}

.invalid-feedback {
  color: var(--accent-red);
  font-size: 12px;
}

/* Select options */
.form-select option {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ==========================================================================
   §15.6 Category Badge Circles
   ========================================================================== */

.category-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--category-color, var(--bg-hover));
  opacity: 0.9;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.category-badge-sm {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

/* Category colors */
.cat-groceries      { --category-color: var(--cat-groceries); }
.cat-transport      { --category-color: var(--cat-transport); }
.cat-restaurants    { --category-color: var(--cat-restaurants); }
.cat-health         { --category-color: var(--cat-health); }
.cat-clothing       { --category-color: var(--cat-clothing); }
.cat-entertainment  { --category-color: var(--cat-entertainment); }
.cat-utilities      { --category-color: var(--cat-utilities); }
.cat-communications { --category-color: var(--cat-communications); }
.cat-other          { --category-color: var(--cat-other); }

/* ==========================================================================
   Source / Status Badges
   ========================================================================== */

.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.source-badge.manual {
  background: rgba(138, 155, 176, 0.15);
  color: var(--text-secondary);
}

.source-badge.ocr {
  background: rgba(0, 200, 232, 0.15);
  color: var(--accent-cyan);
}

.source-badge.telegram {
  background: rgba(48, 176, 199, 0.15);
  color: #30b0c7;
}

/* ==========================================================================
   Dashboard (§15.5)
   ========================================================================== */

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 24px;
}

.hero-stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
}

.hero-stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  margin-bottom: 8px;
}

.hero-stat-subtext {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

.quick-add-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.quick-add-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.quick-add-pill:hover:not(:disabled):not(.disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-cyan);
  text-decoration: none;
}

.quick-add-pill.primary {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: #000;
  font-weight: 600;
}

.quick-add-pill.primary:hover {
  filter: brightness(1.1);
  color: #000;
}

.quick-add-pill:disabled,
.quick-add-pill.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Recent expenses list */
.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.expense-row:last-child {
  border-bottom: none;
}

.expense-info {
  flex: 1;
  min-width: 0;
}

.expense-description {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-shop {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.expense-amount {
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.expense-amount.over-budget {
  color: var(--accent-gold);
}

.expense-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Donut chart container */
.chart-container {
  position: relative;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}

/* ==========================================================================
   Empty State
   ========================================================================== */

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

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state-subtext {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ==========================================================================
   Auth Pages (login / register)
   ========================================================================== */

.auth-page {
  min-height: 100vh;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 12px 40px var(--shadow);
}

.auth-logo {
  width: 48px;
  height: 48px;
  background: var(--accent-cyan);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #000;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  margin: 0 auto 24px;
}

.auth-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.auth-subtitle {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 28px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-footer a {
  color: var(--accent-cyan);
  text-decoration: none;
  font-weight: 500;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Flash Messages
   ========================================================================== */

.flash-container {
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  right: 16px;
  z-index: 1050;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flash-container.auth-flash {
  position: static;
  width: 100%;
  margin-bottom: 16px;
}

.flash-message {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 12px var(--shadow);
  animation: fadeIn 0.2s ease;
}

.flash-close {
  margin-left: auto;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.6;
  cursor: pointer;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.flash-close:hover { opacity: 1; }

/* ==========================================================================
   Manual Expense Form
   ========================================================================== */

.form-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 560px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.form-error-inline {
  background: rgba(255, 59, 48, 0.1);
  border: 1px solid rgba(255, 59, 48, 0.3);
  color: #ff6b6b;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

.form-error-inline.visible {
  display: block;
}

/* ==========================================================================
   Expenses Table
   ========================================================================== */

.expenses-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.table-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.table-card .table {
  margin-bottom: 0;
}

.table-card .table thead th:first-child,
.table-card .table tbody td:first-child {
  padding-left: 20px;
}

.table-card .table thead th:last-child,
.table-card .table tbody td:last-child {
  padding-right: 20px;
}

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

.cat-name {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Amount cell */
.amount-cell {
  text-align: right;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* Delete button in table */
.btn-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 16px;
  transition: color 0.15s ease, background 0.15s ease;
  line-height: 1;
}

.btn-delete:hover {
  color: var(--accent-red);
  background: rgba(255, 59, 48, 0.1);
}

/* ==========================================================================
   Mobile — Bottom Tab Bar
   ========================================================================== */

@media (max-width: 767.98px) {
  .sidebar {
    display: none;
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border);
    z-index: 100;
    align-items: stretch;
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 20px;
    gap: 2px;
    transition: color 0.15s ease;
    border-top: 2px solid transparent;
  }

  .bottom-nav-item.active {
    color: var(--accent-cyan);
    border-top-color: var(--accent-cyan);
  }

  .bottom-nav-item:hover {
    color: var(--text-primary);
    text-decoration: none;
  }

  .bottom-nav-label {
    font-size: 9px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .main-content {
    margin-left: 0;
    padding-bottom: 72px;
  }

  .topbar {
    left: 0;
  }

  .flash-container {
    right: 8px;
    left: 8px;
    width: auto;
  }
}

@media (min-width: 768px) {
  .bottom-nav {
    display: none;
  }
}

/* ==========================================================================
   Utilities
   ========================================================================== */

.text-cyan   { color: var(--accent-cyan) !important; }
.text-gold   { color: var(--accent-gold) !important; }
.text-muted-custom { color: var(--text-muted) !important; }
.text-secondary-custom { color: var(--text-secondary) !important; }

.section-title {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 14px;
}

hr.divider {
  border-color: var(--border);
  opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
