/* Shared admin UI theme inspired by PO master list for consistent styling */
:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #4a5568;
  --muted: #6f7a96;
  --border: #e3e7f2;
  --border-strong: #cdd6ed;
  --accent: #4b5dff;
  --accent-soft: #edf0ff;
  --success: #0f9d58;
  --success-bg: #e6f9f1;
  --error: #ff4d61;
  --error-bg: #ffecee;
  --warn: #f5a524;
  --shadow: 0 20px 40px rgba(28, 35, 51, 0.08);
  --radius-large: 24px;
  --radius: 12px;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* SaaS Dashboard Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--card);
  border-right: none;
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 100;
  transition: width 0.3s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 80px;
}

.sidebar-header {
  padding: 20px;
  border-bottom: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  justify-content: space-between;
}

.sidebar-logo {
  display: none;
}

.sidebar-logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s ease;
  flex: 1;
}

.sidebar.collapsed .sidebar-logo-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-toggle {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease;
  order: -1;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--accent-soft);
}

.sidebar-toggle-icon {
  font-size: 18px;
  color: var(--muted);
}

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

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.2s ease, color 0.2s ease;
  position: relative;
  white-space: nowrap;
  margin: 0 12px;
  border-radius: 8px;
  justify-content: flex-start;
}

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

.sidebar-nav-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.sidebar.collapsed .sidebar-nav-icon {
  width: 100%;
  margin: 0;
}

.sidebar-nav-text {
  opacity: 1;
  transition: opacity 0.2s ease;
  flex: 1;
}

.sidebar.collapsed .sidebar-nav-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

.sidebar-nav-title {
  padding: 16px 16px 8px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-top: 8px;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar-nav-title:first-child {
  margin-top: 0;
}

.sidebar.collapsed .sidebar-nav-title {
  opacity: 0;
  height: 0;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

.sidebar-nav-count {
  background: var(--accent);
  color: white;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  margin-left: auto;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .sidebar-nav-count {
  opacity: 0;
  width: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
  text-align: left;
  margin: 0 12px;
  justify-content: flex-start;
}

.sidebar.collapsed .sidebar-footer-btn {
  justify-content: center;
  padding: 10px;
}

.sidebar-footer-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-footer-btn.logout {
  color: var(--error);
}

.sidebar-footer-btn.logout:hover {
  background: var(--error-bg);
  color: var(--error);
}

.sidebar-footer-btn-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  text-align: center;
}

.sidebar.collapsed .sidebar-footer-btn-icon {
  width: 100%;
  margin: 0;
}

.sidebar.collapsed .sidebar-footer-btn {
  gap: 0;
}

.sidebar.collapsed .sidebar-footer-btn-icon {
  margin: 0;
  width: 100%;
  justify-content: center;
}

.sidebar-footer-btn-text {
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .sidebar-footer-btn-text {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

/* Main Content Area */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding-top: 70px; /* Add padding for fixed topbar */
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s ease;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  min-width: 0;
  width: calc(100vw - 260px);
  max-width: calc(100vw - 260px);
}

.sidebar.collapsed ~ .main-content {
  margin-left: 80px;
  width: calc(100vw - 80px);
  max-width: calc(100vw - 80px);
  padding-top: 70px; /* Add padding for fixed topbar */
}

/* Top Bar */
.top-bar {
  background: var(--card);
  border-bottom: none;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin: 0;
  flex-shrink: 0;
  min-width: 0;
}

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

.top-bar-brand {
  display: none;
}

.top-bar-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

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

/* Compact Status Indicators */
.status-indicators-compact {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.status-badge.ok {
  background: rgba(15, 157, 88, 0.1);
  color: var(--success);
  border: 1px solid rgba(15, 157, 88, 0.2);
}

.status-badge.warn {
  background: rgba(245, 165, 36, 0.1);
  color: var(--warn);
  border: 1px solid rgba(245, 165, 36, 0.2);
}

.status-badge.error {
  background: rgba(255, 77, 97, 0.1);
  color: var(--error);
  border: 1px solid rgba(255, 77, 97, 0.2);
}

.status-badge-count {
  background: var(--accent);
  color: white;
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}

.status-badge.warn .status-badge-count {
  background: var(--warn);
}

.status-badge.error .status-badge-count {
  background: var(--error);
}

/* Content Wrapper */
.content-wrapper {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}

/* Mobile Menu Toggle - Hidden on desktop */
.mobile-menu-toggle {
  display: none;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 260px !important;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar.collapsed {
    width: 260px !important;
  }

  .main-content {
    margin-left: 0 !important;
  }

  .mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
  }

  .mobile-menu-overlay.active {
    display: block;
  }

  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    color: var(--text);
    border-radius: 8px;
    transition: background 0.2s ease;
  }

  .mobile-menu-toggle:hover {
    background: var(--accent-soft);
  }

  .sidebar-toggle {
    display: none;
  }
}

h1 {
  margin: 0 0 8px;
  font-size: 32px;
  font-weight: 600;
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 600;
}

p.lead {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

a {
  color: var(--accent);
}

header,
.wrap,
.page,
.page-body {
  max-width: 1200px;
  margin: 0 auto 24px;
  padding: 0;
}

/* Legacy nav - hidden by default, can be shown if needed */
.nav {
  display: none !important;
}

.nav a {
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.nav a:hover {
  background: var(--accent-soft);
  border-color: var(--border-strong);
}

.nav a.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(75, 93, 255, 0.2);
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.page-heading h1 {
  margin-bottom: 4px;
}

.status-cluster {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.status-indicator {
  min-width: 150px;
  background: #f7f8fe;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-indicator .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.status-indicator .value {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.status-indicator .detail {
  font-size: 12px;
  color: var(--muted);
}

.status-indicator.ok {
  background: rgba(15, 157, 88, 0.08);
  border-color: rgba(15, 157, 88, 0.35);
}

.status-indicator.warn {
  background: rgba(245, 165, 36, 0.12);
  border-color: rgba(245, 165, 36, 0.35);
}

.status-indicator.error {
  background: rgba(255, 77, 97, 0.12);
  border-color: rgba(255, 77, 97, 0.35);
}

.status-indicator.info,
.status-indicator.loading {
  background: rgba(75, 93, 255, 0.08);
  border-color: rgba(75, 93, 255, 0.3);
}

.card {
  width: 100%;
  background: var(--card);
  border-radius: var(--radius-large);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card--compact {
  border-radius: 18px;
  padding: 20px;
}

.card.narrow {
  border-radius: 20px;
  padding: 20px;
}

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

.grid.cols-2 {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

label {
  min-width: 110px;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="date"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fafbff;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(75, 93, 255, 0.18);
}

textarea {
  min-height: 100px;
  resize: vertical;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 500;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}

.btn.secondary {
  background: #edf0ff;
  color: var(--accent);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(75, 93, 255, 0.25);
}

.btn[aria-busy="true"] {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.btn[aria-busy="true"]::after {
  content: '';
  position: absolute;
  right: 16px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.pill {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.status-banner {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 500;
  display: none;
}

.status-banner.success {
  display: block;
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid rgba(15, 157, 88, 0.2);
}

.status-banner.error {
  display: block;
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(255, 77, 97, 0.25);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 14px 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  background: #f7f8fe;
}

tbody td {
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

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

.empty-state,
.loading,
.empty {
  text-align: center;
  padding: 40px 0;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 20px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-weight: 500;
  border-bottom: 3px solid transparent;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: #eef2ff;
  color: var(--accent);
}

.status-pill[data-status="approved"],
.status-pill.success {
  background: var(--success-bg);
  color: var(--success);
}

.status-pill[data-status="cancelled"],
.status-pill.error {
  background: var(--error-bg);
  color: var(--error);
}

.status-pill[data-status="pending"],
.status-pill.warning {
  background: rgba(245, 165, 36, 0.15);
  color: var(--warn);
}

pre,
.log,
.response {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 18px;
  padding: 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  overflow: auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.console-card h2 {
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.drag-area {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-large);
  padding: 32px;
  text-align: center;
  background: #fafbff;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.drag-area:hover,
.drag-area.is-dragover {
  border-color: var(--accent);
  background: rgba(75, 93, 255, 0.05);
}

.flex {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.right {
  margin-left: auto;
}

@media (max-width: 768px) {
  .content-wrapper {
    padding: 16px;
  }

  h1 {
    font-size: 26px;
  }

  .card {
    padding: 20px;
  }

  .page-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .status-cluster {
    justify-content: flex-start;
  }

  .status-indicators-compact {
    flex-wrap: wrap;
  }

  .tabs {
    flex-wrap: wrap;
  }

  thead {
    display: none;
  }

  tbody td {
    display: block;
    padding: 12px 0;
    border-bottom: none;
  }

  tbody tr {
    border-bottom: 1px solid var(--border);
  }
}

