/* ═══════════════════════════════════════════════════════════════
   ReconAssure – Base Layout & Typography
═══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
               'Ubuntu', 'Cantarell', sans-serif;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  transition: background-color 0.2s ease, color 0.2s ease;
  min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img, svg { display: block; }

/* ── App Shell ────────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
  width: 240px;
  min-width: 240px;
  background-color: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

#sidebar.collapsed {
  width: 64px;
  min-width: 64px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  min-height: 64px;
  position: relative;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
}

.sidebar-brand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--sidebar-logo-text);
  white-space: nowrap;
  overflow: hidden;
  max-width: 140px;
  opacity: 1;
  transition: opacity 0.2s ease, max-width 0.2s ease;
}

#sidebar.collapsed .sidebar-brand {
  opacity: 0;
  pointer-events: none;
  max-width: 0;
}

#sidebar.collapsed .sidebar-header {
  padding: 12px 8px;
  justify-content: center;
}

#sidebar.collapsed .sidebar-logo {
  width: 28px;
  height: 28px;
  min-width: 28px;
}

.sidebar-toggle {
  margin-left: auto;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  color: var(--sidebar-text);
  background: transparent;
  border: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar-toggle:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-hover); }
#sidebar.collapsed .sidebar-toggle {
  margin-left: 0;
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  background: var(--sidebar-bg);
}

/* ── Navigation ───────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-text);
  padding: 8px 8px 4px;
  white-space: nowrap;
  opacity: 0.6;
  transition: opacity 0.2s;
}
#sidebar.collapsed .nav-section-label { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  position: relative;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-hover);
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
}

.nav-item .nav-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  flex-shrink: 0;
}

.nav-item .nav-label {
  transition: opacity 0.2s;
  flex: 1;
}
#sidebar.collapsed .nav-item .nav-label { opacity: 0; pointer-events: none; }

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-danger);
  color: white;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
  transition: opacity 0.2s;
}
.nav-badge:empty, .nav-badge[data-count="0"] { display: none; }
#sidebar.collapsed .nav-badge { opacity: 0; }

/* ── Sidebar Footer ───────────────────────────────────────── */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--sidebar-border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: default;
}

.user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  flex-shrink: 0;
}

.user-info { overflow: hidden; transition: opacity 0.2s; }
.user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--sidebar-text-hover);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 0.6875rem;
  color: var(--sidebar-text);
  text-transform: capitalize;
}
#sidebar.collapsed .user-info { opacity: 0; pointer-events: none; }

.logout-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  margin-top: 4px;
  transition: background 0.15s, color 0.15s;
}
.logout-btn:hover {
  background: var(--color-danger-subtle);
  color: var(--color-danger);
}
.logout-btn .nav-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  flex-shrink: 0;
}
#sidebar.collapsed .logout-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  margin: 4px auto 0;
  justify-content: center;
}
#sidebar.collapsed .logout-btn .nav-label {
  display: none;
}

/* ── Version Info ─────────────────────────────────────────── */
.version-info {
  padding: 8px 10px;
  font-size: 0.75rem;
  color: var(--sidebar-text);
  text-align: center;
  border-top: 1px solid var(--sidebar-border);
  margin-top: 8px;
}

.version-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active);
  font-weight: 500;
}

.version-label {
  font-weight: 600;
  font-family: 'Monaco', 'Courier New', monospace;
  font-size: 0.7rem;
}

#sidebar.collapsed .version-info {
  padding: 4px 8px;
}

#sidebar.collapsed .version-badge {
  padding: 2px 4px;
}

#sidebar.collapsed .version-label {
  font-size: 0.65rem;
}

/* ── Main Wrapper ─────────────────────────────────────────── */
#main-wrapper {
  flex: 1;
  min-width: 0;   /* prevent wide descendant content (e.g. tables) from forcing this flex item wider than the available viewport */
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed #main-wrapper { margin-left: 64px; }

/* ── Top Header ───────────────────────────────────────────── */
#header {
  height: 56px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--color-text);
  flex: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-user-info {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
}

.header-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.header-icon-btn:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.alert-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-danger);
  border: 2px solid var(--color-surface);
  display: none;
}
.alert-badge.visible { display: block; }

/* ── Page Content ─────────────────────────────────────────── */
#page-content {
  flex: 1;
  padding: 24px;
  overflow: auto;
}

/* Recon/Reversals page: lock the entire viewport chain so only the table scrolls.
   min-height:100vh on the wrappers must be overridden to pin layout to exactly 100vh. */
body.recon-page,
body.recon-page #app {
  height: 100vh;
  overflow: hidden;
}

body.recon-page #main-wrapper {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

body.recon-page #page-content {
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Page Header ──────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* ── Loading Overlay ──────────────────────────────────────── */
#page-loading {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}

#page-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner-ring {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utility ──────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success{ color: var(--color-success); }
.text-sm     { font-size: 0.8125rem; }
.text-xs     { font-size: 0.75rem; }
.font-mono   { font-family: 'Cascadia Code', 'Consolas', monospace; font-size: 0.875em; }

.flex        { display: flex; }
.flex-col    { display: flex; flex-direction: column; }
.items-center{ align-items: center; }
.gap-2       { gap: 8px; }
.gap-4       { gap: 16px; }
.mt-4        { margin-top: 16px; }
.mb-4        { margin-bottom: 16px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { width: 64px; min-width: 64px; }
  #sidebar .sidebar-brand,
  #sidebar .nav-label,
  #sidebar .user-info { opacity: 0; pointer-events: none; }
  #main-wrapper { margin-left: 64px; }
}
