:root {
  --bg-dark: #121215;
  --bg-card: #1c1c21;
  --bg-card-hover: #26262d;
  --primary: #764af1;
  --primary-glow: rgba(118, 74, 241, 0.4);
  --text-main: #ffffff;
  --text-muted: #9a9aab;
  --success: #2ecc71;
  --danger: #ff4757;
  --warning: #ffa502;
  --border-color: #2a2a32;
  --font-family: 'Inter', sans-serif;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  color: var(--text-main);
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

a {
  text-decoration: none;
  color: inherit;
}

/* Layout */
.app-container {
  display: flex;
  width: 100%;
  height: 100%;
}

/* --- Left Sidebar --- */
.sidebar {
  width: 250px;
  background-color: var(--bg-dark);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  flex-shrink: 0;
  box-sizing: border-box;
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 3rem;
  padding-left: 0.5rem;
  color: var(--text-main);
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.2s;
}

.nav-item:hover {
  background-color: var(--bg-card);
  color: var(--text-main);
}

.nav-item.active {
  background-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.nav-bottom {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-dark);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2rem 2.5rem;
  box-sizing: border-box;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.page-title h1 {
  font-size: 1.5rem;
  margin: 0 0 0.25rem 0;
}

.page-title p {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.875rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-box {
  background-color: var(--bg-card);
  border-radius: 20px;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid transparent;
  transition: border-color 0.2s;
}

.search-box:focus-within {
  border-color: var(--primary);
}

.search-box input {
  background: transparent;
  border: none;
  color: var(--text-main);
  outline: none;
  font-size: 0.875rem;
  width: 100%;
  min-width: 0;
}

.search-box input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

.icon-btn {
  background-color: var(--bg-card);
  border: none;
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-main);
}

.user-avatar {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  background-color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 0.875rem;
  flex-shrink: 0;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background-color: var(--bg-card);
  border-radius: 20px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, background-color 0.2s;
  cursor: default;
}

.kpi-card:hover {
  transform: translateY(-2px);
  background-color: var(--bg-card-hover);
}

.kpi-icon-wrap {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.kpi-icon {
  font-size: 1.5rem;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.kpi-label {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Chart */
.chart-section {
  background-color: var(--bg-card);
  border-radius: 20px;
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 300px;
}

.chart-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
}

/* --- Bill Table --- */
.bill-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  color: #fff;
}

.bill-table th {
  padding: 1rem 0.5rem;
  font-weight: 500;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.bill-table td {
  padding: 1rem 0.5rem;
}

.bill-table tbody tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.15s;
}

.bill-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.bill-icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Status Badges */
.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge-open {
  background: rgba(255, 165, 2, 0.1);
  color: var(--warning);
}

.badge-paid {
  background: rgba(46, 204, 113, 0.1);
  color: var(--success);
}

.badge-overdue {
  background: rgba(255, 71, 87, 0.1);
  color: var(--danger);
}

/* FAB Button */
.fab-btn {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  box-shadow: 0 4px 15px var(--primary-glow);
  z-index: 50;
  padding: 0;
}

/* --- Right Sidebar --- */
.right-sidebar {
  width: 320px;
  background-color: var(--bg-dark);
  border-left: 1px solid var(--border-color);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
  box-sizing: border-box;
}

.list-section {
  display: flex;
  flex-direction: column;
}

.list-header {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem 0;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
  text-decoration: none;
  border-radius: 12px;
  padding: 0.5rem;
  transition: background-color 0.2s;
  margin-right: -0.5rem;
  margin-left: -0.5rem;
}

.list-item:hover {
  background-color: var(--bg-card);
}

.item-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background-color: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  flex-shrink: 0;
}

.item-details {
  flex: 1;
  min-width: 0;
}

.item-title {
  font-weight: 600;
  font-size: 0.875rem;
  margin: 0 0 0.125rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-date {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin: 0;
}

.item-amount {
  font-weight: 600;
  font-size: 0.875rem;
  white-space: nowrap;
}

/* --- Standard Elements --- */
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }

.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: inherit;
}

.btn:hover {
  background: #5f3ac8;
}

.btn-block {
  width: 100%;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.875rem;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-card);
  border-radius: 20px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2rem;
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.modal-title {
  margin: 0;
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-main);
}

.file-dropzone {
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  display: block;
  transition: border-color 0.2s, background 0.2s;
}

.file-dropzone:hover {
  border-color: var(--primary);
  background: rgba(118, 74, 241, 0.05);
}

/* Loading Overlay */
.loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(28, 28, 33, 0.95);
  border-radius: 20px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  z-index: 10;
}

.loading-overlay.show {
  display: flex;
}

/* Settings Grid */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Hamburger Menu */
.hamburger-btn {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 1.25rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.hamburger-btn:hover {
  background: var(--bg-card-hover);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 89;
}

.sidebar-overlay.open {
  display: block;
}

/* History tab: hidden by default, shown when right sidebar disappears */
.tab-history-btn {
  display: none;
}

/* Mobile table helpers */
.bill-title-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  display: inline-block;
  vertical-align: middle;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
  .right-sidebar {
    display: none;
  }

  .tab-history-btn {
    display: inline-flex;
  }
}

@media (max-width: 900px) {
  .sidebar {
    width: 80px;
    padding: 1rem 0.5rem;
    align-items: center;
  }

  .brand span {
    display: none;
  }

  .nav-item span {
    display: none;
  }

  .nav-item {
    justify-content: center;
    padding: 1rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .main-content {
    padding: 1.5rem;
  }
}

@media (max-width: 600px) {
  body {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .app-container {
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
    align-items: flex-start;
  }

  .sidebar {
    display: flex;
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    z-index: 90;
    width: 250px;
    transition: left 0.3s ease;
    align-items: stretch;
    padding: 1.5rem 1rem;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar span {
    display: inline;
  }

  .nav-item {
    justify-content: flex-start;
    padding: 0.75rem 1rem;
  }

  .hamburger-btn {
    display: flex;
  }

  .main-content {
    padding: 1rem;
    padding-top: 4.5rem;
    overflow-y: visible;
    height: auto;
    width: 100%;
  }

  .chart-section {
    flex: none;
    height: auto;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 1rem;
  }

  .topbar-actions {
    width: 100%;
  }

  .search-box {
    flex: 1;
    min-width: 0;
  }

  .kpi-value {
    font-size: 1.25rem;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    width: 95%;
    padding: 1.5rem;
  }

  .hide-mobile {
    display: none;
  }

  .bill-title-cell {
    max-width: 120px;
  }

  .bill-table td,
  .bill-table th {
    padding: 0.75rem 0.25rem;
    font-size: 0.8rem;
  }

  .bill-icon-wrap {
    width: 32px;
    height: 32px;
  }

  .fab-btn {
    bottom: 1.5rem;
    right: 1.5rem;
    width: 52px;
    height: 52px;
  }
}

/* Flash Messages */
.alert {
  padding: 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.alert-success {
  background-color: rgba(46, 204, 113, 0.1);
  color: var(--success);
  border: 1px solid rgba(46, 204, 113, 0.2);
}

.alert-danger {
  background-color: rgba(255, 71, 87, 0.1);
  color: var(--danger);
  border: 1px solid rgba(255, 71, 87, 0.2);
}
