/* ===== RESET & TOKENS ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0
}

:root {
  /* ── Brand ── */
  --brand-500: #0ea5e9;
  --brand-600: #0284c7;

  /* ── Typography ── */
  --font-sans: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font: var(--font-sans);

  /* ── Backgrounds ── */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --surface-hover: #f7f9fb;

  /* ── Text ── */
  --text: #0f172a;
  --text-secondary: #5a6376;
  --text-muted: #475569;
  --muted: #475569;
  --muted-2: #64748b;

  /* ── Borders ── */
  --border: #e5e7eb;
  --border-2: #eef2f7;
  --border-light: var(--border-2);

  /* ── Primary / accent palette (preserved for existing consumers) ── */
  --primary: #1976d2;
  --primary-light: #e3f0ff;
  --primary-dark: #0d47a1;
  --accent: #0097a7;
  --accent-light: #e0f7fa;

  /* ── Sidebar ── */
  --sidebar-bg: #000000;
  --sidebar-text: #c5cad4;
  --sidebar-active: var(--primary);
  --header-bg: var(--surface);

  /* ── Status ── */
  --success: #2e7d4f;
  --success-light: #e7f5ee;
  --warning: #e8a317;
  --warning-light: #fef9e7;
  --danger: #c0392b;

  /* ── Shadows ── */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, .08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, .12);

  /* ── Radii ── */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --r-lg: 14px;
  --r-xl: 18px;

  /* ── Motion ── */
  --transition: .2s ease;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
  overflow-x: hidden
}

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden
}

a {
  color: inherit;
  text-decoration: none
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none
}

input,
select {
  font-family: inherit
}

img {
  max-width: 100%;
  display: block
}

/* ===== UTILITY ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  overflow: hidden
}

.flex {
  display: flex
}

.flex-col {
  flex-direction: column
}

.items-center {
  align-items: center
}

.justify-between {
  justify-content: space-between
}

.gap-4 {
  gap: 1rem
}

.gap-2 {
  gap: .5rem
}

.gap-1 {
  gap: .25rem
}

/* ===== LOGIN PAGE ===== */
#login-page {
  display: none;
  min-height: 100vh;
  background: linear-gradient(135deg, #000000 0%, #000000 50%, #000000 100%)
}

#login-page.active {
  display: flex
}

.login-wrapper {
  display: flex;
  width: 100%;
  min-height: 100vh
}

.login-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 3rem 2rem;
  position: relative;
  z-index: 1
}

.login-brand {
  margin-bottom: 2.5rem;
  text-align: center
}

.login-right {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.login-hero-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.login-right::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.05) 100%);
  pointer-events: none;
}


.login-brand-logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--primary-dark);
  margin-bottom: .25rem
}

/* login.html — SVG logo variant */
.login-brand-img {
  height: 36px;
  width: auto;
  margin: 0 auto .5rem;
}

/* login.html — secondary "Continue" link for already-authed users */
.login-continue-link {
  display: block;
  margin-top: 1.1rem;
  text-align: center;
  font-size: .85rem;
  font-weight: 600;
  color: var(--primary);
  transition: color var(--transition);
}

.login-continue-link:hover {
  color: var(--primary-dark)
}

/* login.html — internal use note */
.login-internal-note {
  font-size: .75rem;
  color: #ffffff;
  opacity: .7;
}

.login-brand-sub {
  font-size: .8rem;
  color: #ffffff;
  letter-spacing: 1.5px;
  text-transform: uppercase
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2.2rem;
  max-width: 400px;
  width: 100%;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: .35rem;
  color: var(--text)
}

.login-card p {
  font-size: .9rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  line-height: 1.5
}

.btn-microsoft {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  width: 100%;
  padding: .85rem 1.2rem;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .95rem;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  box-shadow: 0 2px 8px rgba(25, 118, 210, .3);
}

.btn-microsoft:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(25, 118, 210, .35)
}

.btn-microsoft:active {
  transform: translateY(0)
}

.btn-microsoft svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0
}

.login-footer {
  margin-top: 3rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .2rem .35rem;
  text-align: center;
  font-size: .78rem;
  color: #ffffff;
}

.login-footer a {
  transition: color var(--transition)
}

.login-footer a:hover {
  color: var(--primary)
}

.login-footer-links {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0 .5rem;
}

.idle-timeout-modal[hidden] {
  display: none;
}

.idle-timeout-modal {
  position: fixed;
  inset: 0;
  z-index: 1600;
}

.idle-timeout-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}

.idle-timeout-dialog {
  position: relative;
  width: min(92vw, 460px);
  margin: min(10vh, 6rem) auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 1.5rem;
  z-index: 1;
}

.idle-timeout-dialog h2 {
  font-size: 1.2rem;
  margin-bottom: 0.6rem;
}

.idle-timeout-dialog p {
  color: var(--text-secondary);
  line-height: 1.6;
}

.idle-timeout-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.idle-timeout-open {
  overflow: hidden;
}

.legal-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

.legal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem 1.5rem;
}

.legal-back {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--primary);
  font-weight: 600;
}

.legal-card h1 {
  font-size: 1.6rem;
  margin-bottom: 0.75rem;
}

.legal-card h2 {
  font-size: 1.05rem;
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.legal-card p,
.legal-card li {
  color: var(--text-secondary);
  line-height: 1.65;
}

.legal-card ul {
  padding-left: 1.2rem;
}

@media(max-width:860px) {
  .login-right {
    display: none
  }

  .login-left {
    padding: 2rem 1.2rem
  }

  .login-footer-divider {
    display: none;
  }
}

/* ===== APP SHELL ===== */
#app-shell {
  display: none;
  min-height: 100vh
}

#app-shell.active {
  display: flex
}

/* Sidebar */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  transition: transform .3s ease;
}

.sidebar-brand {
  padding: 1.3rem 1.2rem;
  display: flex;
  align-items: center;
  gap: .7rem;
  border-bottom: 1px solid rgba(255, 255, 255, .06)
}

.sidebar-brand-link {
  display: inline-flex;
  align-items: center;
}

.brand-logo {
  width: 140px;
  max-width: 100%;
  height: auto;
  display: block;
}

@media(min-width: 861px) {
  .brand-logo {
    width: 160px;
  }
}


.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto
}

.sidebar-section {
  padding: 0 .8rem;
  margin-bottom: .5rem
}

.sidebar-section-title {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, .3);
  padding: .5rem .6rem;
  font-weight: 600
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .6rem .9rem;
  margin: 2px .4rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: .88rem;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover {
  background: rgba(255, 255, 255, .06);
  color: #fff
}

.nav-item.active {
  background: rgba(25, 118, 210, .2);
  color: #fff;
  font-weight: 600
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: -0.4rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  border-radius: 2px;
  background: var(--primary)
}

.nav-item.disabled {
  opacity: .35;
  pointer-events: none
}

.nav-item .badge-soon {
  font-size: .6rem;
  background: rgba(255, 255, 255, .1);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: auto;
  color: rgba(255, 255, 255, .5)
}

.nav-icon {
  width: 20px;
  height: 20px;
  opacity: .7;
  flex-shrink: 0
}

.nav-item.active .nav-icon {
  opacity: 1
}

.sidebar-bottom {
  padding: .8rem;
  border-top: 1px solid rgba(255, 255, 255, .06)
}

/* Mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 99;
  opacity: 0;
  transition: opacity .3s
}


.sidebar-overlay.visible {
  display: block;
  opacity: 1
}

/* Mobile: ensure the sidebar/overlay always sit above page widgets (prevents KPI bar bleeding into the sidebar) */
@media (max-width: 860px) {

  /* Put the slide-in sidebar above everything */
  .sidebar {
    z-index: 5000;
  }

  /* Put the dim overlay above the page content */
  .sidebar-overlay {
    z-index: 4990;
  }

  /* Only when the sidebar is OPEN, force page widgets back under the overlay. */
  .sidebar.open~.main-area #pageContent,
  .sidebar.open~.main-area .page-container {
    z-index: auto !important;
  }
}

@media(max-width:860px) {
  .sidebar {
    transform: translateX(-100%)
  }

  .sidebar.open {
    transform: translateX(0)
  }
}

/* Main area */
.main-area {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;

  height: auto;
  min-height: 100vh;
}

@media(max-width:860px) {
  .main-area {
    margin-left: 0
  }
}

/* Header */
.top-header {
  height: 56px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .03);
}

.header-left {
  display: flex;
  align-items: center;
  gap: .8rem;
  min-width: 0;
  flex: 1;
}


.menu-btn {
  display: none;
  /* FIX: 44px tap target */
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  background: transparent;
  transition: background var(--transition);
  flex-shrink: 0;
}

.menu-btn:hover {
  background: var(--bg)
}

@media(max-width:860px) {
  .menu-btn {
    display: flex
  }

  /* FIX: hide user name on narrow headers to avoid crowding */
  .user-name {
    display: none;
  }
}

.breadcrumb {
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  display: flex;
  align-items: center;
  gap: .25rem;
}

.breadcrumb strong {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.env-badge {
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: 1px;
  background: var(--warning-light);
  color: var(--warning);
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  margin-left: .6rem
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  position: relative
}

.user-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .6rem;
  border-radius: var(--radius);
  transition: background var(--transition)
}

.user-btn:hover {
  background: var(--bg)
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0
}

.user-name {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text)
}

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: .4rem;
  z-index: 200;
}

.user-dropdown.open {
  display: block
}

.user-dropdown a {
  display: block;
  padding: .55rem .8rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  color: var(--text-secondary);
  transition: all var(--transition)
}

.user-dropdown a:hover {
  background: var(--bg);
  color: var(--text)
}

/* Page container */
.page-container {
  flex: 0 0 auto;
  /* content drives height */
  overflow: visible;
  /* normal document scroll */
  padding: 1.5rem;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  min-height: 1px;
}

@media(max-width:860px) {
  .page-container {
    padding: 1rem
  }
}

/* ===== COMING SOON ===== */
.coming-soon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
  text-align: center
}

.coming-soon-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  opacity: .22
}

.coming-soon h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: .4rem
}

.coming-soon p {
  color: var(--muted);
  font-size: .92rem
}

/* Drawer */
.drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  z-index: 200;
  opacity: 0;
  transition: opacity .25s;
}

.drawer-overlay.open {
  display: block;
  opacity: 1
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 520px;
  max-width: 100%;
  background: var(--surface);
  z-index: 210;
  transform: translateX(100%);
  transition: transform .3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0, 0, 0, .12);
  /* FIX: always full-height on mobile */
  height: 100%;
}

.drawer.open {
  transform: translateX(0)
}

/* FIX: lock page scroll when drawer is open */
body.drawer-open {
  overflow: hidden;
}

.drawer-header {
  padding: 1.2rem 1.4rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  /* FIX: prevent header shrink so close button stays visible */
  min-height: 56px;
}

.drawer-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  /* FIX: allow title to truncate rather than push close button off-screen */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: .5rem;
}

.drawer-close {
  /* FIX: 44px tap target */
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}

.drawer-close:hover {
  background: var(--bg)
}

.drawer-body {
  flex: 1;
  /* FIX: drawer body scrolls independently; page scroll locked via body.drawer-open */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1.2rem 1.4rem;
}

.drawer-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
  margin-bottom: 1.2rem
}

.drawer-meta-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: .6rem .8rem
}

.drawer-meta-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: .15rem
}

.drawer-meta-value {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text)
}

.drawer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
  margin-top: .6rem
}

.drawer-table thead th {
  padding: .5rem .6rem;
  text-align: left;
  font-weight: 700;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  border-bottom: 2px solid var(--border)
}

.drawer-table tbody td {
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary)
}

.drawer-table tbody td:nth-child(3) {
  font-weight: 700;
  color: var(--text)
}

.drawer-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  gap: .5rem
}

.btn {
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 600;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

.btn-outline {
  border: 1px solid var(--border);
  color: var(--text-secondary)
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light)
}

@media(max-width:600px) {
  .drawer {
    width: 100%;
    /* FIX: full-screen drawer on small phones */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 0;
  }

}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px)
  }

  to {
    opacity: 1;
    transform: translateY(0)
  }
}

.fade-in {
  animation: fadeInUp .4s ease both
}

.delay-1 {
  animation-delay: .08s
}

.delay-2 {
  animation-delay: .16s
}

.delay-3 {
  animation-delay: .24s
}

.delay-4 {
  animation-delay: .32s
}

.delay-5 {
  animation-delay: .40s
}
