:root {
  /* Material Design 3 Color Tokens (Seed: Blue) */
  --md-sys-color-primary: #0061a4;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #d1e4ff;
  --md-sys-color-on-primary-container: #001d36;
  --md-sys-color-secondary: #535f70;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #d7e3f7;
  --md-sys-color-on-secondary-container: #101c2b;
  --md-sys-color-tertiary: #6b5778;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #f2daff;
  --md-sys-color-on-tertiary-container: #251431;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;
  --md-sys-color-background: #fdfcff;
  --md-sys-color-on-background: #1a1c1e;
  --md-sys-color-surface: #fdfcff;
  --md-sys-color-on-surface: #1a1c1e;
  --md-sys-color-surface-variant: #dfe2eb;
  --md-sys-color-on-surface-variant: #43474e;
  --md-sys-color-outline: #73777f;
  --md-sys-color-outline-variant: #c3c7cf;
  --md-sys-color-inverse-surface: #2f3033;
  --md-sys-color-inverse-on-surface: #f1f0f4;
  
  /* Elevations */
  --md-sys-elevation-0: 0px 0px 0px 0px rgba(0,0,0,0);
  --md-sys-elevation-1: 0px 1px 2px 0px rgba(0,0,0,0.3), 0px 1px 3px 1px rgba(0,0,0,0.15);
  --md-sys-elevation-2: 0px 1px 2px 0px rgba(0,0,0,0.3), 0px 2px 6px 2px rgba(0,0,0,0.15);
  --md-sys-elevation-3: 0px 1px 3px 0px rgba(0,0,0,0.3), 0px 4px 8px 3px rgba(0,0,0,0.15);

  /* Shape */
  --md-sys-shape-corner-extra-small: 4px;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-shape-corner-full: 9999px;

  /* Typography */
  --md-sys-typescale-body-large-font: 'Roboto', sans-serif;
  --md-sys-typescale-body-large-size: 16px;
  --md-sys-typescale-body-large-weight: 400;
  
  --md-sys-typescale-title-large-font: 'Roboto', sans-serif;
  --md-sys-typescale-title-large-size: 22px;
  --md-sys-typescale-title-large-weight: 400;

  --md-sys-typescale-headline-small-font: 'Roboto', sans-serif;
  --md-sys-typescale-headline-small-size: 24px;
  --md-sys-typescale-headline-small-weight: 400;

  --transition-default: 200ms cubic-bezier(0.2, 0.0, 0, 1.0);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  font-family: var(--md-sys-typescale-body-large-font);
  font-size: var(--md-sys-typescale-body-large-size);
  color: var(--md-sys-color-on-background);
  background-color: var(--md-sys-color-background);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== LAYOUT: SAAS STRUCTURE ===== */

.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  background-color: var(--md-sys-color-background);
}

/* Navigation Rail / Drawer */
.nav-drawer {
  width: 280px;
  background-color: var(--md-sys-color-surface);
  /* contrast with main content slightly if needed, or surface-1 */
  background-color: #f0f4fa; /* slight tint */
  display: flex;
  flex-direction: column;
  padding: 12px;
  border-right: 1px solid var(--md-sys-color-outline-variant);
  transition: transform var(--transition-default);
  z-index: 10;
}

.brand {
  height: 56px;
  display: flex;
  align-items: center;
  padding-left: 16px;
  font-size: 18px;
  font-weight: 500;
  color: var(--md-sys-color-primary);
  margin-bottom: 24px;
}

.brand .material-symbols-rounded {
  margin-right: 12px;
  font-size: 24px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  height: 56px;
  padding: 0 16px 0 24px;
  border-radius: var(--md-sys-shape-corner-full);
  text-decoration: none;
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  transition: background-color var(--transition-default), color var(--transition-default);
  cursor: pointer;
  position: relative;
  overflow: hidden; /* for ripple */
}

.nav-item:hover {
  background-color: rgba(0, 0, 0, 0.04);
  color: var(--md-sys-color-on-surface);
}

.nav-item.active {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.nav-item .material-symbols-rounded {
  margin-right: 12px;
  font-size: 24px;
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  background-color: var(--md-sys-color-background);
}

.top-bar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-surface);
}

.page-title {
  font-size: var(--md-sys-typescale-title-large-size);
  font-weight: 400;
}

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color var(--transition-default);
}

.icon-btn:hover {
  background-color: rgba(0,0,0,0.08);
}

/* Page Container with View Transitions */
#page-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

.page {
  display: none;
  animation: fadeScaleIn 0.3s cubic-bezier(0.2, 0, 0, 1);
  max-width: 1200px;
  margin: 0 auto;
}

.page.active {
  display: block;
}

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

/* ===== COMPONENTS ===== */

/* Cards (Outlined or Elevated) */
.card {
  background-color: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-medium);
  padding: 24px;
  margin-bottom: 16px;
  /* Outlined card style by default for cleaner look */
  border: 1px solid var(--md-sys-color-outline-variant);
}

.card.elevated {
  border: none;
  box-shadow: var(--md-sys-elevation-1);
  background-color: var(--md-sys-color-surface-container-low, #f7f9ff);
}

.card-title {
  font-size: var(--md-sys-typescale-title-large-size);
  margin-bottom: 8px;
  color: var(--md-sys-color-on-surface);
}

.card-subtitle {
  font-size: 14px;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 24px;
}

/* Buttons */
.btn {
  height: 40px;
  padding: 0 24px;
  border-radius: var(--md-sys-shape-corner-full);
  border: none;
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-default);
}

.btn-filled {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-1);
}
.btn-filled:hover {
  box-shadow: var(--md-sys-elevation-2);
  background-image: linear-gradient(rgba(255,255,255,0.08), rgba(255,255,255,0.08));
}

.btn-tonal {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}
.btn-tonal:hover {
  box-shadow: var(--md-sys-elevation-1);
  background-image: linear-gradient(rgba(0,0,0,0.05), rgba(0,0,0,0.05));
}

.btn-text {
  background-color: transparent;
  color: var(--md-sys-color-primary);
}
.btn-text:hover {
  background-color: rgba(0,97,164, 0.08); /* Primary color low opacity */
}

.btn-sm {
  height: 32px;
  padding: 0 16px;
  font-size: 13px;
}

/* Inputs */
.input-field {
  margin-bottom: 24px;
  position: relative;
}

.text-input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  border-radius: 4px 4px 0 0;
  border: none;
  border-bottom: 1px solid var(--md-sys-color-outline);
  background-color: var(--md-sys-color-surface-variant);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 16px;
  transition: all var(--transition-default);
}

.text-input:focus {
  outline: none;
  border-bottom: 2px solid var(--md-sys-color-primary);
  background-color: rgba(223, 226, 235, 0.8);
}

.input-label {
  position: absolute;
  top: 8px;
  left: 16px;
  font-size: 12px;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
}

/* Grid & Utilities */
.grid-zones {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.zone-item {
  background-color: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 12px;
  padding: 16px 24px;
  cursor: pointer;
  transition: all var(--transition-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.zone-item:hover {
  background-color: var(--md-sys-color-secondary-container);
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: var(--md-sys-elevation-1);
}

.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
}

.status-chip.ok { background-color: #d1e7dd; color: #0a3622; }
.status-chip.err { background-color: #f8d7da; color: #58151c; }

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
}

tr:hover td {
  background-color: rgba(0,0,0,0.02);
}

/* Mobile Responsive */
.menu-trigger {
  display: none;
  margin-right: 16px;
  color: var(--md-sys-color-on-surface);
  background: transparent;
  border: none;
  cursor: pointer;
}

@media (max-width: 768px) {
  .nav-drawer {
    position: fixed;
    left: -280px;
    height: 100%;
    box-shadow: var(--md-sys-elevation-2);
  }
  .nav-drawer.open {
    transform: translateX(280px);
  }
  .menu-trigger {
    display: block;
  }
  .app-layout {
    flex-direction: column;
  }
}

/* Toast/Snackbar */
#snackbar {
  visibility: hidden;
  min-width: 250px;
  background-color: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  text-align: center;
  border-radius: 4px;
  padding: 16px;
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s, bottom 0.3s;
}

#snackbar.show {
  visibility: visible;
  opacity: 1;
  bottom: 50px;
}
