/* FinStack App — Dark Theme */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0b;
  --surface: #111113;
  --surface-2: #18181b;
  --surface-3: #1e1e21;
  --border: #27272a;
  --border-hover: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --accent: #f59e0b;
  --accent-dim: #92400e;
  --accent-glow: rgba(245, 158, 11, 0.15);
  --accent-hover: #fbbf24;
  --green: #22c55e;
  --green-dim: #166534;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-dim: #991b1b;
  --red-bg: rgba(239, 68, 68, 0.1);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.1);
  --purple: #8b5cf6;
  --sidebar-w: 240px;
  --radius: 10px;
  --radius-sm: 6px;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 50;
  transition: transform 0.3s;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.35rem;
  color: var(--text);
  text-decoration: none;
}

.sidebar-logo span { color: var(--accent); }

.sidebar-nav { flex: 1; padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.8rem;
}

.user-name { font-size: 0.85rem; font-weight: 500; }
.user-email { font-size: 0.7rem; color: var(--text-dim); }

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.page-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
}

.page-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.15rem; }

.page-body { padding: 1.5rem 2rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: 'DM Sans', sans-serif;
}

.btn:hover { border-color: var(--border-hover); background: var(--surface-3); }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}

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

.btn-danger { border-color: var(--red-dim); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }

.btn-ghost { border: none; background: none; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 0.95rem; }

.btn-group { display: flex; gap: 0.5rem; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
}

.card-body { padding: 1.25rem; }

/* Metric cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

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

.metric-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.metric-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.metric-value.positive { color: var(--green); }
.metric-value.negative { color: var(--red); }
.metric-value.accent { color: var(--accent); }

.metric-change {
  font-size: 0.75rem;
  margin-top: 0.25rem;
  color: var(--text-muted);
}

/* Tables */
.table-wrapper { overflow-x: auto; }

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

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

.td-amount {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  white-space: nowrap;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-draft { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-sent { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(59,130,246,0.3); }
.badge-paid { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.badge-overdue { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
.badge-cancelled { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }

.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  transition: border-color 0.15s;
  outline: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-dim); }

.form-select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23a1a1aa' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

.form-textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

.form-hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 3rem 1rem;
  overflow-y: auto;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  animation: modalIn 0.2s ease;
}

.modal-lg { max-width: 800px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 1.5rem; }

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Empty states */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.empty-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.empty-desc { font-size: 0.9rem; max-width: 400px; margin: 0 auto 1.5rem; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.55rem 0.85rem 0.55rem 2.25rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-family: 'DM Sans', sans-serif;
  outline: none;
  transition: border-color 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%2371717a' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='8' stroke='%2371717a' stroke-width='2' fill='none'/%3E%3Cpath d='m21 21-4.35-4.35' stroke='%2371717a' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.75rem center;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.filter-tabs { display: flex; gap: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }

.filter-tab {
  padding: 0.45rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
  border-right: 1px solid var(--border);
}

.filter-tab:last-child { border-right: none; }
.filter-tab:hover { color: var(--text); background: var(--surface-3); }
.filter-tab.active { color: var(--accent); background: var(--accent-glow); }

/* Two-column layout */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* Chart placeholder */
.chart-container {
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0;
  padding-top: 1rem;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  padding-bottom: 24px;
  position: relative;
}

.chart-bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar {
  width: 100%;
  max-width: 24px;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 0.3s;
}

.chart-bar.revenue { background: var(--accent); }
.chart-bar.expense { background: var(--red); opacity: 0.7; }

.chart-bar-inner {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  width: 100%;
  justify-content: center;
  flex: 1;
}

.chart-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-align: center;
  margin-top: 4px;
}

/* Action menu */
.action-menu { position: relative; }

.action-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 160px;
  z-index: 30;
  padding: 0.25rem;
  display: none;
}

.action-dropdown.show { display: block; }

.action-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  font-family: 'DM Sans', sans-serif;
}

.action-item:hover { background: var(--surface-2); color: var(--text); }
.action-item.danger { color: var(--red); }
.action-item.danger:hover { background: var(--red-bg); }

/* Invoice line items */
.line-items { margin: 1rem 0; }

.line-item-row {
  display: grid;
  grid-template-columns: 1fr 80px 120px 100px 36px;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 0.5rem;
}

.line-item-row .form-input { font-size: 0.85rem; padding: 0.5rem 0.65rem; }

.remove-item-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 1rem;
}

.remove-item-btn:hover { color: var(--red); background: var(--red-bg); }

.line-items-total {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 0.75rem;
}

.total-row {
  display: flex;
  align-items: center;
  gap: 2rem;
  font-size: 0.9rem;
}

.total-row .label { color: var(--text-muted); min-width: 100px; text-align: right; }
.total-row .value { font-family: 'Space Grotesk', sans-serif; font-weight: 600; min-width: 120px; text-align: right; }
.total-row.grand { font-size: 1.1rem; }
.total-row.grand .value { color: var(--accent); font-size: 1.2rem; }

/* Auth page */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.75rem;
  text-align: center;
  margin-bottom: 0.5rem;
}

.auth-logo span { color: var(--accent); }

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-footer a { color: var(--accent); text-decoration: none; cursor: pointer; }
.auth-footer a:hover { text-decoration: underline; }

.auth-error {
  background: var(--red-bg);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}

/* Toasts */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.error { border-color: rgba(239,68,68,0.4); }

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

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text-muted);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.75rem;
}

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

/* Mobile */
.mobile-header {
  display: none;
  padding: 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
}

.hamburger {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .mobile-header { display: flex; }
  .main-content { margin-left: 0; }
  .page-header { padding: 1rem 1.25rem; }
  .page-body { padding: 1rem 1.25rem; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .line-item-row { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .filter-tabs { overflow-x: auto; }
}

/* Transitions */
.page-view { animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* Category breakdown chart */
.category-list { display: flex; flex-direction: column; gap: 0.75rem; }

.category-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.category-bar-track {
  flex: 1;
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.category-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.category-name { font-size: 0.8rem; min-width: 100px; }
.category-amount { font-family: 'Space Grotesk', sans-serif; font-size: 0.8rem; font-weight: 600; min-width: 80px; text-align: right; }

/* Logout */
.logout-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: 'DM Sans', sans-serif;
  width: 100%;
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
}

.logout-btn:hover { background: var(--red-bg); color: var(--red); }
