:root {
  --primary-color: #6366f1;
  --primary-dark: #4f46e5;
  --secondary-color: #ec4899;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Outfit", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden; /* App-like feel */
}

/* Layout */
.app-container {
  display: flex;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  transition: transform 0.3s ease;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.75rem 1rem;
  text-align: left;
  cursor: pointer;
  border-radius: 0.5rem;
  transition: all 0.2s;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-item:hover {
  background-color: rgba(99, 102, 241, 0.1);
  color: var(--primary-color);
}

.nav-item.active {
  background-color: var(--primary-color);
  color: white;
}

.sidebar-footer {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 2rem;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.avatar {
  width: 40px;
  height: 40px;
  background-color: var(--border-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Views */
.view {
  display: none;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: block;
}

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

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background-color: var(--bg-card);
  padding: 1.5rem;
  border-radius: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
}

.icon-bg {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.blue {
  background: rgba(59, 130, 246, 0.2);
  color: var(--info);
}
.green {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
}
.red {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}
.purple {
  background: rgba(168, 85, 247, 0.2);
  color: #a855f7;
}

.kpi-info h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
}

.kpi-info p {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Charts & Lists */
.charts-container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
}

.chart-card {
  background-color: var(--bg-card);
  padding: 1.5rem;
  border-radius: 1rem;
  border: 1px solid var(--border-color);
}

.recent-list {
  list-style: none;
  margin-top: 1rem;
}

.recent-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.recent-list li:last-child {
  border-bottom: none;
}

/* Tables */
.table-container {
  background-color: var(--bg-card);
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

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

th,
td {
  padding: 1rem;
  text-align: left;
}

th {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-weight: 600;
}

td {
  border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

/* Buttons & Inputs */
.btn-primary {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.2s;
}

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

.btn-danger {
  background-color: var(--danger);
  color: white;
  border: none;
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.btn-edit {
  background-color: var(--warning);
  color: white;
  border: none;
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
  cursor: pointer;
  margin-right: 0.5rem;
  font-size: 0.8rem;
}

/* Forms */
.form-card {
  background-color: var(--bg-card);
  padding: 2rem;
  border-radius: 1rem;
  max-width: 600px;
  margin: 0 auto;
  border: 1px solid var(--border-color);
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.75rem;
  background-color: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  color: white;
  outline: none;
}

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

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 200;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--bg-card);
  padding: 2rem;
  border-radius: 1rem;
  width: 100%;
  max-width: 500px;
  border: 1px solid var(--border-color);
  position: relative;
  box-shadow:
    0 20px 25px -5px rgb(0 0 0 / 0.1),
    0 8px 10px -6px rgb(0 0 0 / 0.1);
}

.close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
    height: 100vh; /* Ensure full height */
    overflow: hidden;
  }

  /* Sidebar becomes TopBar/TabBar hybrid */
  .sidebar {
    width: 100%;
    height: auto;
    padding: 1rem;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0; /* Prevent shrinking */
    z-index: 10;
  }

  .logo {
    margin-bottom: 0;
    font-size: 1.2rem;
  }

  .logo span {
    display: inline-block; /* Keep logo text visible if space permits, or hide if very small */
  }

  .nav-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: var(--bg-card);
    border-top: 1px solid var(--border-color);
    flex-direction: row;
    justify-content: space-around;
    padding: 0.5rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom));
    z-index: 100;
  }

  .nav-item {
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.7rem;
    padding: 0.5rem;
    border-radius: 0;
    justify-content: center;
    flex: 1;
    text-align: center;
  }

  .nav-item i {
    font-size: 1.2rem;
    margin-bottom: 2px;
  }

  .nav-item:hover {
    background-color: transparent;
    color: var(--primary-color);
  }

  .nav-item.active {
    background-color: transparent;
    color: var(--primary-color);
    border-top: 2px solid var(--primary-color);
  }

  .nav-item span {
    display: block; /* Show text labels in bottom nav */
    font-size: 0.7rem;
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    padding: 1rem;
    padding-bottom: 80px; /* Space for bottom nav */
    overflow-y: auto;
    height: 100%;
  }

  .charts-container {
    grid-template-columns: 1fr;
  }

  /* Responsive Table */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 600px; /* Ensure table doesn't squash columns */
  }

  /* Modal Adjustments */
  .modal-content {
    width: 95%;
    margin: 20px;
    padding: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
  }

  .top-bar {
    margin-bottom: 1.5rem;
  }

  h2#page-title {
    font-size: 1.5rem;
  }
}
