:root {
  --md-primary: #1e3a8a;
  --md-primary-container: #dbeafe;
  --md-on-primary-container: #1e3a8a;
  --md-secondary: #0284c7;
  --md-surface: #ffffff;
  --md-surface-variant: #f1f5f9;
  --md-background: #f8fafc;
  --md-text: #0f172a;
  --md-text-muted: #64748b;
  --md-border: #e2e8f0;
  
  --omr-emerald: #059669;
  --omr-emerald-bg: #ecfdf5;
  --omr-crimson: #dc2626;
  --omr-crimson-bg: #fef2f2;
  --omr-amber: #d97706;
  --omr-amber-bg: #fffbeb;
  
  --omr-gold: #eab308;
  --omr-silver: #94a3b8;
  --omr-bronze: #b45309;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

[data-theme="dark"] {
  --md-primary: #3b82f6;
  --md-primary-container: #1e3a8a;
  --md-on-primary-container: #dbeafe;
  --md-surface: #1e293b;
  --md-surface-variant: #0f172a;
  --md-background: #0b1120;
  --md-text: #f8fafc;
  --md-text-muted: #94a3b8;
  --md-border: #334155;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--md-background);
  color: var(--md-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

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

/* Sidebar / Navigation Rail */
.nav-rail {
  width: 250px;
  background-color: var(--md-surface);
  border-right: 1px solid var(--md-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s ease;
  z-index: 50;
}

.brand-section {
  padding: 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--md-border);
}

.brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #1e3a8a, #0284c7);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 1.15rem;
  box-shadow: var(--shadow-sm);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--md-text);
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--md-text-muted);
  font-weight: 500;
}

.nav-links {
  list-style: none;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  color: var(--md-text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  border-radius: var(--radius-full);
  transition: background-color 0.15s, color 0.15s;
}

.nav-item a:hover {
  background-color: var(--md-surface-variant);
}

.nav-item.active a {
  background-color: var(--md-primary-container);
  color: var(--md-on-primary-container);
  font-weight: 600;
}

.nav-icon {
  font-size: 1.25rem;
  width: 24px;
  text-align: center;
}

/* User mini profile in nav footer */
.nav-footer {
  padding: 14px;
  border-top: 1px solid var(--md-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Top App Bar */
.top-bar {
  height: 64px;
  background-color: var(--md-surface);
  border-bottom: 1px solid var(--md-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 40;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--md-text);
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content-body {
  padding: 24px;
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Common Components */
.card {
  background-color: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-primary {
  background-color: var(--md-primary);
  color: #ffffff;
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--md-surface-variant);
  color: var(--md-text);
  border-color: var(--md-border);
}
.btn-secondary:hover {
  background-color: var(--md-border);
}

.btn-danger {
  background-color: var(--omr-crimson);
  color: #ffffff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

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

.stat-card {
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background-color: var(--md-surface);
  border: 1px solid var(--md-border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--md-text);
  line-height: 1.1;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--md-text-muted);
  font-weight: 500;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-gold {
  background: linear-gradient(135deg, #fef08a, #eab308);
  color: #713f12;
  box-shadow: 0 0 8px rgba(234, 179, 8, 0.4);
}

.badge-silver {
  background: linear-gradient(135deg, #f1f5f9, #cbd5e1);
  color: #334155;
}

.badge-bronze {
  background: linear-gradient(135deg, #fed7aa, #b45309);
  color: #ffffff;
}

.badge-green {
  background-color: var(--omr-emerald-bg);
  color: var(--omr-emerald);
  border: 1px solid var(--omr-emerald);
}

.badge-red {
  background-color: var(--omr-crimson-bg);
  color: var(--omr-crimson);
  border: 1px solid var(--omr-crimson);
}

.badge-amber {
  background-color: var(--omr-amber-bg);
  color: var(--omr-amber);
  border: 1px solid var(--omr-amber);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--md-text);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--md-border);
  background-color: var(--md-surface);
  color: var(--md-text);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  border-color: var(--md-primary);
  box-shadow: 0 0 0 3px var(--md-primary-container);
}

/* Modal Dialogs */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-dialog {
  background-color: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: var(--radius-lg);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--md-text-muted);
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--md-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .nav-rail {
    position: fixed;
    left: -250px;
    height: 100%;
  }
  .nav-rail.open {
    left: 0;
  }
  .content-body {
    padding: 16px;
  }
}
