/* =============================================================================
   ProjectDRIVE — Application Stylesheet

   Single source of visual truth for the dashboard, auth, and error pages.
   The file is organized in three layers:

     1. Design tokens         (--pd-*)
     2. Layout primitives     (.pd-shell, .pd-sidebar, .pd-topbar, .pd-content)
     3. Page components       (.pd-page, .pd-card, .pd-table, .pd-status, ...)

   All colors derive from Bootstrap semantic tokens so dark/light themes
   work automatically via `data-bs-theme="..."`. Never hardcode hex
   colors for surfaces — use the tokens defined here or a Bootstrap
   utility class.
   ========================================================================== */

/* -------------------------------------------------------------------------
   1. Design tokens
   ------------------------------------------------------------------------- */

:root {
  /* radii */
  --pd-radius:        0.75rem;   /* cards, panels */
  --pd-radius-sm:     0.5rem;    /* inputs, buttons, small surfaces */
  --pd-radius-pill:   999px;     /* badges, chips */

  /* spacing scale (use sparingly; Bootstrap utilities first) */
  --pd-gap-xs:        0.25rem;
  --pd-gap-sm:        0.5rem;
  --pd-gap-md:        0.75rem;
  --pd-gap-lg:        1rem;
  --pd-gap-xl:        1.5rem;

  /* layout dimensions */
  --pd-sidebar-w:           248px;
  --pd-sidebar-w-collapsed: 76px;
  --pd-topbar-h:            56px;
  --pd-topbar-gap:          0.75rem;   /* margin around the floating topbar */
  --pd-content-pad:         1.25rem;
  --pd-content-maxw:        1400px;

  /* Vertical chrome consumed above a page-internal scroll container.
     Tunable from one place so Explorer/Trash/etc stay in sync. */
  --pd-page-header-h:       9rem;

  /* motion */
  --pd-transition:    180ms ease;
  --pd-transition-fast: 120ms ease;

  /* elevation */
  --pd-shadow-sm:  0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --pd-shadow-md:  0 2px 4px rgba(15, 23, 42, 0.05), 0 8px 20px rgba(15, 23, 42, 0.06);
  --pd-shadow-lg:  0 4px 12px rgba(15, 23, 42, 0.08), 0 16px 40px rgba(15, 23, 42, 0.10);

  /* surface tints (light theme defaults) */
  --pd-surface:       var(--bs-body-bg);
  --pd-surface-alt:   var(--bs-tertiary-bg);
  --pd-surface-muted: var(--bs-secondary-bg);
  --pd-border-soft:   var(--bs-border-color-translucent);
  --pd-border:        var(--bs-border-color);
}

[data-bs-theme="dark"] {
  --pd-shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.30), 0 1px 1px rgba(0, 0, 0, 0.20);
  --pd-shadow-md:  0 2px 6px rgba(0, 0, 0, 0.35), 0 12px 28px rgba(0, 0, 0, 0.45);
  --pd-shadow-lg:  0 6px 16px rgba(0, 0, 0, 0.45), 0 20px 48px rgba(0, 0, 0, 0.55);
}

html, body { height: 100%; }
body.pd-app {
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  font-feature-settings: "ss01", "cv11";
}

/* -------------------------------------------------------------------------
   Auth layout
   ------------------------------------------------------------------------- */

.pd-auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(13, 110, 253, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(25, 135, 84, 0.08), transparent 60%),
    var(--bs-body-bg);
}

.pd-auth__panel {
  width: 100%;
  max-width: 420px;
  background-color: var(--pd-surface);
  border: 1px solid var(--pd-border);
  border-radius: var(--pd-radius);
  padding: 2rem 1.75rem;
  box-shadow: var(--pd-shadow-md);
}

.pd-auth__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--pd-gap-md);
  margin-bottom: 1.5rem;
}

.pd-auth__logo {
  display: inline-flex;
  width: auto;
  height: 44px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.pd-auth__logo img { height: 40px; width: auto; object-fit: contain; }
[data-bs-theme="dark"] .pd-auth__logo img {
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 2px;
}
.pd-auth__logo .bi { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--pd-radius-sm); background: var(--bs-primary-bg-subtle); color: var(--bs-primary); font-size: 1.25rem; }

.pd-auth__title { font-weight: 600; line-height: 1.2; }
.pd-auth__tagline { font-size: 0.85rem; }
.pd-auth__heading { font-weight: 600; }

.pd-auth__footer {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--pd-border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* -------------------------------------------------------------------------
   2. Dashboard shell
   ------------------------------------------------------------------------- */

.pd-shell {
  display: grid;
  grid-template-columns: var(--pd-sidebar-w) 1fr;
  min-height: 100vh;
  transition: grid-template-columns var(--pd-transition);
  background-color: var(--bs-body-bg);
}

.pd-shell.is-collapsed {
  grid-template-columns: var(--pd-sidebar-w-collapsed) 1fr;
}

/* ----- Sidebar ----------------------------------------------------------- */

.pd-sidebar {
  background-color: var(--pd-surface-alt);
  border-right: 1px solid var(--pd-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden;
  z-index: 10;
}

.pd-sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--pd-gap-sm);
  padding: 0 1rem;
  height: calc(var(--pd-topbar-h) + var(--pd-topbar-gap));
  white-space: nowrap;
  flex-shrink: 0;
}

.pd-sidebar__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  height: 36px;
}
.pd-sidebar__logo img { height: 28px; width: auto; object-fit: contain; }
[data-bs-theme="dark"] .pd-sidebar__logo img {
  background: rgba(255,255,255,0.12);
  border-radius: 4px;
  padding: 2px;
}
.pd-sidebar__logo .bi { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--pd-radius-sm); background: var(--bs-primary); color: #fff; font-size: 1rem; box-shadow: var(--pd-shadow-sm); }

.pd-sidebar__title {
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.pd-nav {
  flex: 1;
  padding: 0.5rem 0.625rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.pd-nav__group-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.68rem;
  color: var(--bs-secondary-color);
  padding: 1rem 0.75rem 0.375rem;
  white-space: nowrap;
  font-weight: 600;
}

.pd-nav__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--pd-radius-sm);
  color: var(--bs-body-color);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background-color var(--pd-transition-fast), color var(--pd-transition-fast);
  position: relative;
}

.pd-nav__item i {
  width: 1.25rem;
  text-align: center;
  font-size: 1.05rem;
  flex-shrink: 0;
  color: var(--bs-secondary-color);
  transition: color var(--pd-transition-fast);
}

.pd-nav__item:hover {
  background-color: var(--pd-surface-muted);
  color: var(--bs-emphasis-color);
}
.pd-nav__item:hover i { color: var(--bs-emphasis-color); }

.pd-nav__item.is-active {
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
  font-weight: 500;
}
.pd-nav__item.is-active i { color: var(--bs-primary); }
.pd-nav__item.is-active::before {
  content: "";
  position: absolute;
  left: -0.625rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 3px;
  border-radius: 0 var(--pd-radius-pill) var(--pd-radius-pill) 0;
  background: var(--bs-primary);
}

.pd-nav__item.is-disabled {
  color: var(--bs-secondary-color);
  cursor: not-allowed;
  opacity: 0.55;
}
.pd-nav__item.is-disabled:hover { background-color: transparent; }

.pd-sidebar__foot {
  padding: 0.625rem 0.75rem 0.875rem;
  border-top: 1px solid var(--pd-border-soft);
  flex-shrink: 0;
}

/* Collapsed state (desktop): hide labels, show divider lines in place of
   group labels, center align nav items so icons sit in the middle. */
.pd-shell.is-collapsed .pd-sidebar__title,
.pd-shell.is-collapsed .pd-nav__item span,
.pd-shell.is-collapsed .pd-sidebar__label {
  display: none;
}

.pd-shell.is-collapsed .pd-sidebar__brand { justify-content: center; padding: 0; }
.pd-shell.is-collapsed .pd-nav__item { justify-content: center; padding: 0.55rem; gap: 0; }
.pd-shell.is-collapsed .pd-nav__item.is-active::before { left: -0.4rem; }

/* Group labels become horizontal dividers when collapsed. */
.pd-shell.is-collapsed .pd-nav__group-label {
  font-size: 0;
  padding: 0;
  margin: 0.625rem 0.75rem;
  height: 1px;
  background: var(--pd-border-soft);
  border-radius: 1px;
}

/* ----- Floating topbar --------------------------------------------------- */

.pd-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--pd-topbar-gap);
  gap: var(--pd-topbar-gap);
}

.pd-topbar {
  height: var(--pd-topbar-h);
  display: flex;
  align-items: center;
  gap: var(--pd-gap-md);
  padding: 0 1rem;
  background-color: color-mix(in srgb, var(--bs-body-bg) 88%, transparent);
  border: 1px solid var(--pd-border);
  border-radius: var(--pd-radius);
  box-shadow: var(--pd-shadow-md);
  position: sticky;
  top: var(--pd-topbar-gap);
  z-index: 50;
  backdrop-filter: saturate(150%) blur(8px);
  -webkit-backdrop-filter: saturate(150%) blur(8px);
}

.pd-topbar__title {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.pd-topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--pd-gap-sm);
}

.pd-topbar .btn {
  border-radius: var(--pd-radius-sm);
}

.pd-content {
  margin-top: 0.25rem;
  padding: 0 calc(var(--pd-content-pad) - var(--pd-topbar-gap));
  max-width: var(--pd-content-maxw);
  width: 100%;
}

.pd-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem var(--pd-content-pad);
  font-size: 0.8rem;
  color: var(--bs-secondary-color);
}

/* -------------------------------------------------------------------------
   3. Page primitives
   ------------------------------------------------------------------------- */

.pd-page { display: flex; flex-direction: column; gap: var(--pd-gap-lg); position: relative; }

/* Scrollable page variant — container capped at viewport, surface scrolls. */
.pd-page--scroll {
  max-height: calc(100vh - var(--pd-page-header-h));
  overflow: hidden;
}

.pd-page--scroll > .pd-surface {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.pd-page__sticky-header {
  background-color: var(--bs-body-bg);
  padding-bottom: 0.5rem;
  flex-shrink: 0;
}

.pd-page__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--pd-gap-lg);
  flex-wrap: wrap;
}

.pd-page__title {
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}

.pd-page__subtitle {
  color: var(--bs-secondary-color);
  font-size: 0.875rem;
  margin: 0.25rem 0 0;
}

.pd-page__actions {
  display: flex;
  align-items: center;
  gap: var(--pd-gap-sm);
  flex-wrap: wrap;
}

/* ----- Surface card (default container) --------------------------------- */

.pd-surface {
  background-color: var(--pd-surface);
  border: 1px solid var(--pd-border);
  border-radius: var(--pd-radius);
  box-shadow: var(--pd-shadow-sm);
}

.pd-surface__body { padding: 1rem 1.125rem; }
.pd-surface__head {
  padding: 0.75rem 1.125rem;
  border-bottom: 1px solid var(--pd-border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pd-gap-md);
  flex-wrap: wrap;
}
.pd-surface__foot {
  padding: 0.625rem 1.125rem;
  border-top: 1px solid var(--pd-border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--pd-gap-md);
  flex-wrap: wrap;
}

/* ----- Stat card -------------------------------------------------------- */

.pd-card {
  background-color: var(--pd-surface);
  border: 1px solid var(--pd-border);
  border-radius: var(--pd-radius);
  padding: 1rem 1.125rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--pd-gap-xs);
  transition: border-color var(--pd-transition-fast), box-shadow var(--pd-transition-fast), transform var(--pd-transition-fast);
  box-shadow: var(--pd-shadow-sm);
}

.pd-card:hover {
  border-color: var(--bs-primary-border-subtle);
  box-shadow: var(--pd-shadow-md);
}

.pd-card__icon {
  width: 38px;
  height: 38px;
  border-radius: var(--pd-radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
  background: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
}
.pd-card__icon--success { background: var(--bs-success-bg-subtle); color: var(--bs-success); }
.pd-card__icon--info    { background: var(--bs-info-bg-subtle);    color: var(--bs-info); }
.pd-card__icon--warning { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis, var(--bs-warning)); }

.pd-card__label { font-size: 0.82rem; color: var(--bs-secondary-color); }
.pd-card__value { font-size: 1.5rem; font-weight: 600; line-height: 1.2; letter-spacing: -0.015em; }
.pd-card__hint  { margin-top: auto; font-size: 0.78rem; color: var(--bs-secondary-color); }

/* ----- Filter bar pattern ---------------------------------------------- */

.pd-filter { display: flex; flex-wrap: wrap; gap: var(--pd-gap-md); align-items: flex-end; }
.pd-filter .form-label { font-size: 0.75rem; color: var(--bs-secondary-color); margin-bottom: 0.25rem; font-weight: 500; }
.pd-filter .pd-filter__actions { display: flex; gap: var(--pd-gap-sm); margin-left: auto; }

/* ----- Table pattern ---------------------------------------------------- */

.pd-table { width: 100%; margin-bottom: 0; }
.pd-table thead tr {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--bs-secondary-color);
  background-color: var(--pd-surface-muted);
}
.pd-table thead th { font-weight: 600; padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--pd-border-soft); }
.pd-table tbody td { padding: 0.75rem; vertical-align: middle; border-top: 1px solid var(--pd-border-soft); }
.pd-table tbody tr:first-child td { border-top: 0; }
.pd-table tbody tr:hover { background-color: var(--pd-surface-muted); }

.pd-table__empty { padding: 2.25rem 1rem; text-align: center; color: var(--bs-secondary-color); }

/* ----- Action button group --------------------------------------------- */

.pd-actions { display: inline-flex; gap: 0.25rem; }
.pd-actions .btn {
  --bs-btn-padding-y: 0.25rem;
  --bs-btn-padding-x: 0.5rem;
  --bs-btn-font-size: 0.875rem;
  border-radius: var(--pd-radius-sm);
}

/* ----- Status badges ---------------------------------------------------- */

.pd-status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--pd-radius-pill);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: capitalize;
  line-height: 1.2;
}
.pd-status::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.pd-status--active    { color: var(--bs-success); background: var(--bs-success-bg-subtle); }
.pd-status--suspended { color: var(--bs-danger);  background: var(--bs-danger-bg-subtle); }
.pd-status--pending   { color: var(--bs-warning-text-emphasis, #997404); background: var(--bs-warning-bg-subtle); }
.pd-status--neutral   { color: var(--bs-secondary-color); background: var(--pd-surface-muted); }

/* ----- Avatar pill (used in user table) -------------------------------- */

.pd-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.pd-cell-user { display: flex; align-items: center; gap: 0.625rem; min-width: 0; }
.pd-cell-user__main { min-width: 0; }
.pd-cell-user__name { font-weight: 500; }
.pd-cell-user__sub  { font-size: 0.78rem; color: var(--bs-secondary-color); }

/* ----- Role chips ------------------------------------------------------- */

.pd-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: var(--pd-radius-pill);
  background: var(--pd-surface-muted);
  color: var(--bs-body-color);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.2;
}
.pd-chip i { font-size: 0.7rem; opacity: 0.75; }

/* -------------------------------------------------------------------------
   Error page
   ------------------------------------------------------------------------- */

.pd-error {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background-color: var(--bs-body-bg);
}

.pd-error__panel { text-align: center; max-width: 480px; }
.pd-error__code  { font-size: 4rem; font-weight: 700; color: var(--bs-primary); line-height: 1; }
.pd-error__title { margin-top: 0.5rem; font-weight: 600; }

/* -------------------------------------------------------------------------
   Loading overlay
   ------------------------------------------------------------------------- */

.pd-loading {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
  z-index: 9999;
}
[data-bs-theme="dark"] .pd-loading { background-color: rgba(0, 0, 0, 0.55); }

.pd-loading__inner {
  background-color: var(--pd-surface);
  border: 1px solid var(--pd-border);
  border-radius: var(--pd-radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
  min-width: 200px;
  box-shadow: var(--pd-shadow-lg);
}

.pd-loading__text { font-weight: 500; }

/* -------------------------------------------------------------------------
   Responsive: mobile sidebar drawer
   ------------------------------------------------------------------------- */

@media (max-width: 767.98px) {
  .pd-shell { grid-template-columns: 1fr; }
  .pd-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--pd-sidebar-w);
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform var(--pd-transition);
    box-shadow: var(--pd-shadow-lg);
  }
  .pd-shell.is-mobile-open .pd-sidebar { transform: translateX(0); }
  .pd-sidebar__foot { display: none; }
  .pd-main { padding: var(--pd-topbar-gap) 0.75rem; }
  .pd-content { padding: 0; }
}

/* -------------------------------------------------------------------------
   Required-field asterisk
   ------------------------------------------------------------------------- */

.required-asterisk { font-weight: 700; }

/* -------------------------------------------------------------------------
   Bulk selection
   ------------------------------------------------------------------------- */
.pd-select-col { width: 40px; text-align: center; }
.pd-select-col input[type="checkbox"] { margin: 0; accent-color: var(--bs-primary); }

.pd-bulk-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  background: var(--bs-warning-bg-subtle, #fff3cd);
  color: var(--bs-warning-text-emphasis, #664d03);
  border: 1px solid var(--bs-warning-border-subtle, #ffecb5);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem 0.5rem 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 -1px 4px rgba(0,0,0,0.08);
}
.pd-bulk-bar .btn { --bs-btn-color: var(--bs-warning-text-emphasis, #664d03); --bs-btn-border-color: var(--bs-warning-border-subtle, #e6c64a); }
.pd-bulk-bar .btn:hover { --bs-btn-bg: rgba(0,0,0,0.05); --bs-btn-color: var(--bs-warning-text-emphasis, #664d03); }
.pd-bulk-bar .btn-danger { --bs-btn-color: #fff; --bs-btn-bg: #dc3545; --bs-btn-border-color: #dc3545; }
.pd-bulk-bar .btn-danger:hover { --bs-btn-bg: #bb2d3b; --bs-btn-color: #fff; }
.pd-bulk-bar .btn-primary { --bs-btn-color: #fff; --bs-btn-bg: #0d6efd; --bs-btn-border-color: #0d6efd; }
.pd-bulk-bar .btn-primary:hover { --bs-btn-bg: #0b5ed7; --bs-btn-color: #fff; }
.pd-bulk-bar .btn-success { --bs-btn-color: #fff; --bs-btn-bg: #198754; --bs-btn-border-color: #198754; }
.pd-bulk-bar .btn-success:hover { --bs-btn-bg: #157347; --bs-btn-color: #fff; }
.pd-bulk-bar .btn-warning { --bs-btn-color: #000; --bs-btn-bg: var(--bs-warning); --bs-btn-border-color: var(--bs-warning); }
.pd-bulk-bar .btn-warning:hover { --bs-btn-bg: #e0a800; --bs-btn-color: #000; }
