/* common.css */

/* Theme */
:root {
  /* Brand */
  --brand-900: #012f59;
  --brand-800: #023d72;
  --brand-700: #035696;
  --brand-650: #024a84;

  /* Semantic */
  --success-600: #27ae60;
  --success-700: #229954;
  --danger-600: #e74c3c;
  --danger-700: #c0392b;

  /* Neutrals */
  --white: #ffffff;
  --text-900: #2d3748;
  --text-700: #4a5568;
  --text-600: #718096;
  --text-800: #333333;
  --muted: rgba(0, 0, 0, 0.6);

  /* Surfaces / borders */
  --surface: #ffffff;
  --surface-50: #f8f9fa;
  --surface-100: #f1f3f5;
  --border-200: #e2e8f0;
  --border-300: #e0e0e0;

  /* Alerts */
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;

  /* Shadows */
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);

  /* Radii */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;

  /* Spacing */
  --p-2: 8px;
  --p-3: 12px;
  --p-4: 16px;
  --p-5: 20px;

  /* Background */
  --bg-gradient: linear-gradient(
    135deg,
    rgba(2, 61, 114, 0.95) 0%,
    rgba(2, 61, 114, 0.8) 100%
  );
}

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

/* Base */
body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #f3f4f6;
  min-height: 100vh;
  padding: 0;
  color: var(--text-900);
}

/* If any admin pages still use .container, prevent centering/constraining in the new layout */
.layout .container {
  max-width: none;
  margin: 0;
}

/* --- Layout --- */
.layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 280px;
  flex: 0 0 280px;
  background: #f7f7f7;
  border-right: 1px solid var(--border-200);
  display: flex;
  flex-direction: column;
}

/* Brand block at top of sidebar */
.sidebar-brand {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-200);
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 10px;
}

.sidebar-brand h1 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-900);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-brand .heading-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-brand .heading-icon svg {
  width: 18px;
  height: 18px;
}

.sidebar-brand p {
  font-size: 12px;
  color: var(--text-600);
  margin-top: 2px;
}

/* Logo badge */
.logo-badge {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: center;

}

.logo-badge img {
  height: 32px;
  width: auto;
  display: block;
}

/* Nav scroll area */
.sidebar-nav {
  padding: 10px 10px 14px 10px;
  overflow-y: auto;
  flex: 1 1 auto;
}

/* Section title */
.nav-section-title {
  padding: 10px 10px 6px 10px;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-600);
  font-weight: 700;
  letter-spacing: 0.7px;
}

/* Nav items */
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  margin: 2px 0;
  color: var(--text-800);
  text-decoration: none;
  font-size: 13px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-left-color 0.15s;
}

.nav-locked .sidebar-nav {
  display: none;
}

.nav-item--hidden {
  display: none !important;
}

.nav-item:hover {
  background: #eceff3;
  border-left-color: color-mix(in srgb, var(--brand-800) 55%, #ffffff);
}

.nav-item.active {
  background: #ffe9df;
  border-left-color: #ff8a5c;
  color: var(--text-900);
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 0;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.inline-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
  vertical-align: middle;
}

.inline-icon svg {
  width: 18px;
  height: 18px;
}

.btn-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 6px;
}

.btn-icon svg {
  width: 16px;
  height: 16px;
}

.nav-divider {
  height: 1px;
  background: var(--border-200);
  margin: 10px 8px;
}

.nav-item--danger {
  color: var(--danger-600);
}

.nav-item--danger:hover {
  background: var(--danger-bg);
  border-left-color: var(--danger-600);
}

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

/* --- Topbar: make center title actually center, actions fixed width --- */
.topbar {
  height: 56px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-200);
  display: grid;
  grid-template-columns: auto 1fr auto; /* burger | title | actions */
  align-items: center;
  padding: 0 18px;
  gap: 10px;
}

.topbar-title {
  min-width: 0;               /* critical for ellipsis inside grid */
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.topbar .nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.topbar .nav-btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
}

.topbar .nav-btn-icon svg {
  width: 16px;
  height: 16px;
}

.topbar .nav-btn-text {
  display: inline-flex;
  align-items: center;
}

/* Mobile: keep one row, make actions compact and hide text */
@media (max-width: 768px) {
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .topbar-actions {
    gap: 8px;
  }

  /* Make buttons icon-sized */
  .topbar .nav-btn.btn {
    padding: 8px 10px;
    border-radius: 10px;
  }

  .topbar .nav-btn-text {
    display: none; /* icon-only on mobile */
  }

  .topbar .nav-btn-icon {
    display: inline-flex;
    line-height: 1;
    font-size: 16px;
  }
}

/* Very small phones: reduce title size slightly */
@media (max-width: 420px) {
  .topbar-title {
    font-size: 13px;
  }
}


/* Hide hamburger by default (desktop) */
.icon-btn {
  display: none;
}

@media (max-width: 768px) {
  .icon-btn {
    display: inline-flex;
  }
}
/* Hamburger */
.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-200);
  background: #ffffff;
  border-radius: 10px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--surface-100);
}

/* Backdrop for mobile drawer (exists in DOM always) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 999;
}

/* Page content area */
.page {
  padding: 18px;
  flex: 1 1 auto;
  min-width: 0;
  width: min(80rem, 100%);
  margin-inline: auto;
}

/* Shared button system */
.btn {
  appearance: none;
  border: 0;
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 10px 20px;
  transition: background 0.3s, color 0.3s, border-color 0.3s, box-shadow 0.3s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--brand-800);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--brand-900);
}

.btn-secondary {
  background: var(--brand-700);
  color: var(--white);
}

.btn-secondary:hover {
  background: var(--brand-650);
}

.btn-success {
  background: var(--success-600);
  color: var(--white);
}

.btn-success:hover {
  background: var(--success-700);
}

.btn-danger {
  background: var(--danger-600);
  color: var(--white);
}

.btn-danger:hover {
  background: var(--danger-700);
}

.btn-sm {
  padding: 8px 16px;
  border-radius: var(--r-sm);
}

.btn.readonly-disabled,
.btn.readonly-disabled:hover,
.btn.readonly-disabled:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(10%);
  box-shadow: none;
  pointer-events: none;
}

/* Status messages */
.status {
  padding: 10px;
  margin: 10px 0;
  border-radius: var(--r-sm);
  display: none;
  font-size: 14px;
  border: 1px solid transparent;
}

.status--info {
  background: color-mix(in srgb, var(--brand-800) 10%, var(--white));
  color: var(--brand-800);
  border-color: color-mix(in srgb, var(--brand-800) 25%, var(--white));
}


.status--success {
  background: color-mix(in srgb, var(--success-600) 18%, var(--white));
  color: var(--success-600);
  border-color: color-mix(in srgb, var(--success-600) 35%, var(--white));
}

.status--error {
  background: var(--danger-bg);
  color: var(--danger-600);
  border-color: var(--danger-border);
}

/* Card surface */
.card {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-200);
}

/* --- Mobile: OFF-CANVAS DRAWER (replaces stacked sidebar) --- */
@media (max-width: 768px) {
  .layout {
    min-height: 100vh;
  }

  /* Sidebar becomes a drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    max-width: 85vw;
    z-index: 1000;
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow-lg);
    border-right: 1px solid var(--border-200);
  }

  /* Open state: add class "sidebar-open" to .layout */
  .layout.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .layout.sidebar-open .sidebar-backdrop {
    display: block;
  }

  /* Main uses full width */
  .main {
    width: 100%;
  }

  /* Slightly tighter spacing */
  .topbar {
    padding: 0 14px;
  }

  .page {
    padding: 14px;
  }
}


/* Loading / error */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-600);
}


/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #000000 50%, transparent);
  z-index: 1100;
  padding: var(--p-5);
}

.show {
  display: block !important;
}

.hide {
  display: none !important;
}

.modal-content {
  background: var(--surface);
  margin: 50px auto;
  padding: 30px;
  width: min(800px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-200);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--p-4);
}

.modal-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-900);
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 28px;
  color: var(--text-600);
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-900);
}

/* Mobile */
@media (max-width: 768px) {
  .modal {
    padding: var(--p-3);
  }

  .modal-content {
    margin: 20px auto;
    padding: var(--p-4);
    max-height: 85vh;
  }

  .modal-title {
    font-size: 16px;
  }
}


/* loading spinner */
.loading-spinner {
  position: fixed;
  inset: 0;
  z-index: 2000;

  display: none;
  align-items: center;
  justify-content: center;

  background: rgba(243, 244, 246, 0.6);
  backdrop-filter: blur(1px);
}

.loading-spinner.is-visible {
  display: flex;
}

.loading-spinner::after {
  content: "";
  width: 32px;
  height: 32px;

  border-radius: 50%;
  border: 3px solid var(--border-200);
  border-top-color: var(--brand-800);

  animation: dashboard-spin 0.8s linear infinite;
}

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