:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --line: #e2e8f0;
  --good: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --sidebar: #1e293b;
  --sidebar-hover: #334155;
  --sidebar-active: #3b82f6;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  line-height: 1.6;
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 100;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 20px;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  padding: 8px 12px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-item {
  padding: 12px 16px;
  border-radius: 12px;
  margin: 2px 0;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: all 0.2s ease;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 44px;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: white;
  transform: translateX(4px);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: white;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.nav-item span {
  flex-shrink: 0;
  display: inline-block;
  width: 24px;
  text-align: center;
}

.nav-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  padding: 16px 20px 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  text-align: center;
  background: rgba(0, 0, 0, 0.1);
}

/* Layout */
.layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.topbar .title {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.row.gap {
  gap: 16px;
}

.content {
  padding: 24px;
  display: block;
  background: var(--bg);
}

/* Controls */
.input {
  padding: 12px 16px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: white;
  color: var(--text);
  font-size: 14px;
  transition: all 0.2s ease;
  min-height: 44px;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input.lg {
  min-width: 400px;
}

.btn {
  padding: 12px 20px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn.ghost {
  background: transparent;
  border: 2px solid var(--line);
  color: var(--text);
}

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

.icon {
  padding: 8px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
  min-width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon.ghost {
  background: transparent;
  border: 2px solid var(--line);
  color: var(--text);
}

.icon.ghost:hover {
  background: var(--bg);
  border-color: var(--accent);
}

.icon.danger {
  background: var(--bad);
  border: none;
  color: white;
}

.icon.danger:hover {
  background: #dc2626;
  transform: scale(1.05);
}

/* Cards & grids */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--line);
  transition: all 0.2s ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.card-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.grid {
  display: grid;
  gap: 24px;
}

.grid.two {
  grid-template-columns: 1fr 1fr;
}

.grid.four {
  grid-template-columns: repeat(4, 1fr);
}

.cards-4 {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.kpi {
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  margin: 8px 0;
}

.kpi-card {
  text-align: center;
  padding: 20px;
}

.kpi-card .muted {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.mt {
  margin-top: 16px;
}

.small {
  font-size: 13px;
}

.muted {
  color: var(--muted);
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.table th, .table td {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.table tr:hover {
  background: #f8fafc;
}

.table tr:last-child td {
  border-bottom: none;
}

/* Modal */
dialog {
  border: none;
  padding: 0;
  border-radius: 16px;
}

.modal {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 16px;
  min-width: 700px;
  max-width: 80vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
}

.modal-title {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(250px, 1fr));
  gap: 20px;
  padding: 24px;
}

.form-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 0 0 16px 16px;
}

/* Toast */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: white;
  border: 1px solid var(--line);
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  opacity: 1;
  transition: all 0.3s ease;
  z-index: 1000;
  min-width: 300px;
  border-left: 4px solid var(--accent);
}

.toast.ok {
  border-left-color: var(--good);
}

.toast.warn {
  border-left-color: var(--warn);
}

.toast.hidden {
  opacity: 0;
  transform: translateY(20px);
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 20px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--line);
}

/* Responsive & sidebar collapse */
@media (max-width: 1024px) {
  .grid.two, .grid.four {
    grid-template-columns: 1fr;
  }
  
  .cards-4 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
  
  .modal {
    min-width: 0;
    max-width: 95vw;
  }
  
  .input.lg {
    min-width: 300px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: fixed;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
  }
  
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  
  .content {
    padding: 16px;
  }
  
  .topbar {
    padding: 12px 16px;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .input.lg {
    min-width: 250px;
  }
  
  /* Overlay background when sidebar is open */
  body.sidebar-open::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
}

body.sidebar-collapsed .sidebar {
  width: 80px;
  min-width: 80px;
}

body.sidebar-collapsed .nav-item {
  padding: 12px 8px;
  justify-content: center;
  gap: 0;
}

body.sidebar-collapsed .nav-item span:first-child {
  display: block;
}

body.sidebar-collapsed .nav-item span:not(:first-child) {
  display: none;
}

body.sidebar-collapsed .brand {
  padding: 16px 8px;
  font-size: 16px;
}

body.sidebar-collapsed .brand span:not(:first-child) {
  display: none;
}

body.sidebar-collapsed .nav-label, 
body.sidebar-collapsed .sidebar-footer {
  display: none;
}

/* Additional improvements */
select.input {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 40px;
  appearance: none;
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Status indicators */
.status-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--good);
}

.status-badge.warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warn);
}

.status-badge.error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--bad);
}

/* Welcome header */
.welcome-header {
  background: linear-gradient(135deg, var(--accent), #1d4ed8);
  color: white;
  padding: 32px;
  border-radius: 20px;
  margin-bottom: 24px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.3);
}

.welcome-header h1 {
  color: white !important;
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.welcome-header p {
  color: rgba(255, 255, 255, 0.9) !important;
  margin: 12px 0 0 0;
  font-size: 18px;
  font-weight: 400;
}

/* Enhanced KPI cards */
.kpi-card {
  text-align: center;
  padding: 24px 20px;
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--good));
}

.kpi-card .kpi {
  font-size: 36px;
  font-weight: 700;
  color: var(--accent);
  margin: 12px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

/* Enhanced table styling */
.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--line);
}

.table th {
  color: var(--muted);
  font-weight: 600;
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 20px 16px;
}

.table td {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  transition: background 0.2s ease;
}

.table tr:hover td {
  background: #f8fafc;
}

/* Enhanced form styling */
.form-item input,
.form-item select {
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: white;
  color: var(--text);
  font-size: 14px;
  transition: all 0.2s ease;
  min-height: 48px;
  width: 100%;
}

.form-item input:focus,
.form-item select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Enhanced button styling */
.btn {
  padding: 14px 24px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 48px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.btn:hover {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
}

.btn:active {
  transform: translateY(0);
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
}

/* Ensure all interactive elements are clickable */
.nav-item {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  position: relative;
}

.nav-item:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Sidebar scrollbar styling */
.sidebar nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar nav::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.sidebar nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
}

.sidebar nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* Firefox scrollbar */
.sidebar nav {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1);
}

/* Icon buttons */
.icon {
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.icon:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Loading animation */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.loading {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Quick actions */
.quick-actions {
  margin-top: 32px;
  padding: 24px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.quick-actions h3 {
  margin-bottom: 20px;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
}

/* Stats chart */
.stats-chart {
  margin-top: 32px;
  padding: 24px;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.stats-chart h3 {
  margin-bottom: 20px;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

/* Search and filter */
.search-filter {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-filter .input {
  min-width: 200px;
}

/* Report cards */
.report-card {
  padding: 16px;
  text-align: center;
}

.report-card p {
  margin-bottom: 16px;
  color: var(--muted);
}

/* Date range picker */
.date-range {
  margin: 16px 0;
  padding: 16px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.date-range .label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text);
}

.date-range .row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-range input[type="date"] {
  flex: 1;
  min-width: 150px;
}

/* Validation messages */
.validation-msg {
  color: var(--bad);
  font-size: 12px;
  margin-top: 4px;
  display: none;
}

.form-item input:invalid,
.form-item select:invalid,
.form-item textarea:invalid {
  border-color: var(--bad);
}

/* Enhanced form styling */
.form-item textarea {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

.form-item input[type="date"] {
  font-family: inherit;
}

.form-item input[type="number"] {
  font-family: inherit;
}

/* Result count */
.result-count {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--bg);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* Enhanced toolbar */
.toolbar {
  background: var(--panel);
  padding: 20px;
  border-radius: 16px;
  margin-bottom: 24px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.toolbar .row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar .card-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

/* Enhanced table styling */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.table th {
  background: var(--bg);
  padding: 16px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  border-bottom: 2px solid var(--line);
}

.table td {
  padding: 16px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

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

/* Enhanced button variations */
.btn.ghost {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn.ghost:hover {
  background: var(--accent);
  color: white;
}

.btn.danger {
  background: var(--bad);
}

.btn.danger:hover {
  background: #dc2626;
}

.btn.success {
  background: var(--good);
}

.btn.success:hover {
  background: #059669;
}

/* Responsive improvements */
@media (max-width: 768px) {
  .search-filter {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-filter .input {
    min-width: auto;
  }
  
  .toolbar .row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .chart-container {
    height: 200px;
  }
  
  .quick-actions .row {
    flex-direction: column;
  }
}
