:root {
  --primary: #6B46C1;
  --primary-dark: #553C9A;
  --bg-app: #F3F4F6;
  --bg-card: #FFFFFF;
  --text-main: #1F2937;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-size: 16px;
  line-height: 1.5;
}

/* App Layout */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar (Desktop) & Bottom Nav (Mobile) */
.sidebar {
  width: 260px;
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.brand {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 18px;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  color: var(--text-main);
}

.nav-items {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

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

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

.nav-item.danger {
  color: var(--danger);
}
.nav-item.danger:hover {
  background: #FEF2F2;
}

.nav-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.top-bar {
  height: 64px;
  padding: 0 24px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 10;
}

.top-bar h1 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.online { background: var(--success); }

#views {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  padding-bottom: 100px; /* Space for bottom nav on mobile */
}

.view.hidden {
  display: none !important;
}

/* Login */
.login-card {
  max-width: 400px;
  margin: 40px auto;
  background: white;
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}
.brand-logo.large {
  width: 60px;
  height: 60px;
  font-size: 24px;
  margin: 0 auto 20px;
}

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

.stat-card {
  background: white;
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-main);
}
.stat-card.warn .value { color: var(--warning); }

/* Charts */
.chart-container {
  height: 300px;
  position: relative;
  margin-bottom: 24px;
}

/* Common Components */
.card {
  background: white;
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.card h3 {
  margin-top: 0;
  font-size: 18px;
}

.input-group {
  margin-bottom: 16px;
  text-align: left;
}

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

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #F9FAFB;
  transition: border 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  font-size: 15px;
}

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

.btn.secondary {
  background: #EEF2FF;
  color: var(--primary);
}
.btn.icon-only {
  width: 40px;
  height: 40px;
  padding: 0;
  background: transparent;
  font-size: 20px;
}
.btn.full { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.mt-2 { margin-top: 16px; }

/* File Upload */
.file-drop-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  position: relative;
  cursor: pointer;
  background: #F9FAFB;
}
.file-drop-area:hover { border-color: var(--primary); }
.file-input {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Mobile List */
.mobile-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-item {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}
.list-item:active { background: #F9FAFB; }

.item-main { flex: 1; }
.item-title { font-weight: 600; font-size: 15px; display: block; }
.item-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; display: block; }
.item-status { font-size: 12px; padding: 4px 8px; border-radius: 99px; font-weight: 500; }
.status-active { background: #D1FAE5; color: #065F46; }
.status-past_due { background: #FEE2E2; color: #991B1B; }
.status-free { background: #DBEAFE; color: #1E40AF; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-content {
  background: white;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}
.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app-container { flex-direction: column; }
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    flex-direction: row;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 50;
    padding: 0;
  }
  .brand, .nav-footer { display: none; }
  .nav-items {
    flex-direction: row;
    justify-content: space-around;
    padding: 0;
  }
  .nav-item {
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    font-size: 10px;
    justify-content: center;
    border-radius: 0;
  }
  .nav-item .icon { font-size: 20px; }
  .nav-item.active { background: transparent; color: var(--primary); }

  .main-content {
    height: calc(100vh - 60px);
  }
  #views { padding: 16px; padding-bottom: 40px; }
}

.hidden { display: none !important; }
