/* ============================================================
   Design Tokens
   Single source of truth for color, type, radius, and shadow.
   Every page (including login.html) should reference these
   instead of hardcoding hex values, so a brand tweak only ever
   needs to happen in one place.
   ============================================================ */
:root {
  /* Brand */
  --color-primary: #0F766E;       /* Deep Teal */
  --color-primary-hover: #0B5F59; /* Darker Teal */
  --color-accent: #FACC15;        /* Golden Yellow */
  --color-danger: #EF4444;
  --color-danger-hover: #B91C1C;

  /* Surfaces */
  --color-bg: #F3F4F6;
  --color-surface: #FFFFFF;
  --color-border: #D1D5DB;

  /* Text */
  --color-text: #111827;
  --color-text-muted: #6B7280;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter,
    "Helvetica Neue", Arial, sans-serif;

  /* Shape */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.875rem;

  /* Elevation */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 10px 24px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 24px 48px rgba(15, 23, 42, 0.18);
}

body {
  font-family: var(--font-sans);
}

/* Accessible keyboard focus, consistent everywhere. Pages/inputs that
   already define their own visible focus treatment (e.g. Tailwind's
   focus:ring utility) are unaffected — this is a floor, not an override. */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Disabled controls need to *look* inert, not just behave that way.
   Buttons that go into a "processing…" state during an async action
   (see allocate-asset.js / asset-inventory.js) rely on this. */
button:disabled,
input:disabled,
select:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-logout:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* === Frozen page toolbar (title + filters) ===
   Sits above the table's own sticky thead. JS uses a ResizeObserver to
   keep the thead's `top` continuously matched to this toolbar's actual
   rendered height, so the two never overlap regardless of when styles
   finish applying or if the toolbar's height ever changes. */
.sticky-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--color-bg);
  padding-top: 0.25rem;
  padding-bottom: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

/* === KPI dashboard cards (Asset Summary) === */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  max-width: 900px;
}
.kpi-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.kpi-icon {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}
.kpi-icon-total { background: #E0E7FF; color: #4338CA; }
.kpi-icon-available { background: #DCFCE7; color: #15803D; }
.kpi-icon-allocated { background: #FEE2E2; color: #B91C1C; }
.kpi-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}
.kpi-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* === Table action icons ===
   5 icon buttons (Edit, Allocate, Return, Delete, History) per row. Plain
   inline-block buttons wrap one-per-line in a narrow cell; flex-wrap lets
   them flow horizontally and wrap into centered rows instead (~3 over 2). */
.action-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.6rem;
}
.action-cell button {
  line-height: 1;
  font-size: 1rem;
}

/* === Sortable table headers === */
.sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.sortable-th:hover {
  background-color: rgba(15, 118, 110, 0.08);
}
.sortable-th .sort-icon {
  font-size: 0.7rem;
  margin-left: 0.15rem;
  color: #9CA3AF;
}
.sortable-th.sort-active .sort-icon {
  color: var(--color-primary);
}

/* === Table loading / empty states ===
   Reusable across Asset Inventory, Asset Summary, and User Asset Overview
   so a stalled fetch or a zero-result filter never just looks like a blank,
   broken page. */
.state-cell {
  padding: 3rem 1rem;
  text-align: center;
}
.loading-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text-muted);
}
.spinner {
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid #e5e7eb;
  border-top-color: var(--color-primary);
  border-radius: 9999px;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.empty-state-icon {
  font-size: 1.75rem;
  color: #cbd5e1;
  margin-bottom: 0.25rem;
}
.empty-state-title {
  font-weight: 600;
  color: var(--color-text);
}
.empty-state-message {
  font-size: 0.875rem;
}

/* === Backgrounds === */
.bg-body {
  background-color: var(--color-bg);
}

/* === Sidebar === */ 
.sidebar {
  background-color: var(--color-primary);
  color: white;
}
.sidebar-title {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 1.5rem;
  text-align: center;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.sidebar-nav a,
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  color: white;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.sidebar-nav a:hover,
.sidebar-link:hover {
  color: var(--color-accent);
  background-color: rgba(255, 255, 255, 0.08);
}
.sidebar-nav a.active,
.sidebar-link.active {
  background-color: rgba(255, 255, 255, 0.16);
  color: var(--color-accent);
  font-weight: 600;
}

/* === Cards === */
.card {
  background: white;
  border-radius: 0.5rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card-title {
  font-size: 1.125rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

/* === Page Titles === */
.page-title {
  font-size: 1.875rem;
  font-weight: 600;
  color: #1F2937; /* Dark gray text */
}

/* === Buttons === */
.btn-primary {
  background-color: var(--color-primary);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.3s ease;
}
.btn-primary:hover {
  background-color: var(--color-primary-hover);
}
.btn-logout {
  background-color: var(--color-danger);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.3s ease;
}
.btn-logout:hover {
  background-color: var(--color-danger-hover);
}
.btn-secondary {
  background-color: #E5E7EB; /* Light gray */
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
}
.btn-secondary:hover {
  background-color: #D1D5DB; /* Darker gray */
}

/* === Forms === */
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151; /* Dark gray text */
  margin-bottom: 0.25rem;
}
.form-input {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #D1D5DB;
  border-radius: 0.375rem;
}

/* === Modal === */
.modal {
  position: fixed;
  inset: 0;
  background-color: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-content {
  background: white;
  border-radius: 0.5rem;
  padding: 1.5rem;
  width: 24rem;
}
.modal-title {
  font-size: 1.125rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

/* === Toast Notifications === */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 420px;
  border-radius: 10px;
  padding: 12px 14px;
  color: #fff;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.9rem;
  line-height: 1.35;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  animation: toastSlideIn 220ms ease-out;
}

.toast-message {
  flex: 1;
  word-break: break-word;
}

.toast-close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.9;
}

.toast-close:hover {
  opacity: 1;
}

/* Types */
.toast-success { background: #16a34a; } /* green */
.toast-error   { background: #dc2626; } /* red */
.toast-warning { background: #d97706; } /* amber */
.toast-info    { background: #2563eb; } /* blue */

/* Exit animation */
.toast.fade-out {
  animation: toastFadeOut 220ms ease-in forwards;
}

@keyframes toastSlideIn {
  from { transform: translateY(-8px) translateX(6px); opacity: 0; }
  to   { transform: translateY(0) translateX(0); opacity: 1; }
}

@keyframes toastFadeOut {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

/* Mobile */
@media (max-width: 640px) {
  .toast-container {
    left: 12px;
    right: 12px;
    top: 12px;
  }

  .toast {
    min-width: 0;
    width: 100%;
    max-width: none;
  }
}

/* === Confirmation Modal === */
.confirm-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 80;
}

.confirm-modal.hidden {
  display: none;
}

.confirm-modal-card {
  width: min(100%, 420px);
  background: #ffffff;
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
}

.confirm-modal-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.confirm-modal-icon[data-type="warning"] { background: #fef3c7; color: #b45309; }
.confirm-modal-icon[data-type="error"] { background: #fee2e2; color: #b91c1c; }
.confirm-modal-icon[data-type="info"] { background: #dbeafe; color: #1d4ed8; }
.confirm-modal-icon[data-type="success"] { background: #dcfce7; color: #15803d; }

.confirm-modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.375rem;
}

.confirm-modal-message {
  color: #4b5563;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.confirm-modal-actions {
  display: flex;
  gap: 0.625rem;
  justify-content: flex-end;
}

/* === Premium Edit Modal === */
.edit-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 70;
}
.edit-modal-overlay.hidden {
  display: none;
}
.edit-modal-card {
  width: min(100%, 820px);
  max-height: 90vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.2);
}
.edit-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid #e5e7eb;
}
.edit-modal-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #111827;
}
.edit-modal-subtitle {
  margin-top: 0.2rem;
  font-size: 0.875rem;
  color: #6b7280;
}
.edit-modal-icon-btn {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  color: #6b7280;
  transition: background-color 0.2s ease, color 0.2s ease;
}
.edit-modal-icon-btn:hover {
  background: #f3f4f6;
  color: #111827;
}
.edit-modal-form {
  padding: 1.1rem 1.25rem 1.25rem;
}
.edit-modal-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.95rem;
}
@media (min-width: 768px) {
  .edit-modal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.edit-field-block {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0.8rem;
}
.edit-readonly-input {
  background: #f3f4f6;
  color: #4b5563;
}
.edit-modal-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}
