/* ==========================================================================
   Cabinet UI — shared design system
   --------------------------------------------------------------------------
   Single source of truth for the visual language of the app.
   Reference design: project/project_create_stepper.html
   Loaded globally from master.html. Page-specific CSS stays in the page
   and must only add what cannot be expressed with these primitives.

   Tokens → primitives → page composition. Keep it calm: white surfaces,
   soft borders, one accent at a time, generous whitespace.
   ========================================================================== */

:root {
  /* Surfaces & lines */
  --app-surface: #f4f5f9;
  --app-card-bg: #ffffff;
  --app-border: #e9ecef;
  --app-line: #e2e8f0;
  --app-line-soft: #eef2f7;

  /* Ink */
  --app-ink: #0f172a;
  --app-ink-2: #334155;
  --app-muted: #64748b;
  --app-faint: #94a3b8;

  /* Shape */
  --app-radius: 0.9rem;
  --app-radius-sm: 0.7rem;

  /* Semantic status colors (used by .status-dot) */
  --app-success: #22c55e;
  --app-info: #3b82f6;
  --app-warning: #f59e0b;
  --app-danger: #ef4444;
  --app-neutral: #94a3b8;

  /* Focus */
  --app-focus: #1d4ed8;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

body {
  background-color: var(--app-surface);
  color: var(--app-ink-2);
}

/* Keyboard focus is always visible, never noisy. */
:focus-visible {
  outline: 2px solid var(--app-focus);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Layout helpers
   -------------------------------------------------------------------------- */

/* Prevent flex/grid children from blowing out their container. */
.app-minw {
  min-width: 0;
}

/* Single-line truncation for titles, names, paths. */
.app-truncate {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Desktop sidebar that follows the scroll (no effect on mobile). */
.app-sticky {
  position: relative;
}

@media (min-width: 992px) {
  .app-sticky {
    position: sticky;
    top: calc(var(--app-header-h, 0px) + 1rem);
  }
}

/* Horizontal scroller without a visible scrollbar (filter bars, toolbars). */
.app-scroll-x {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.app-scroll-x::-webkit-scrollbar {
  display: none;
}

/* --------------------------------------------------------------------------
   Status badge — pill with a colored dot, used in page headers and lists.
   Modifiers map an object status to a semantic color; the label stays ink.
   -------------------------------------------------------------------------- */

.status-badge {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--app-border);
  color: var(--app-ink-2);
  font-weight: 600;
  font-size: 12px;
  line-height: 1;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-inline-end: 6px; /* RTL-safe: dot leads the label */
  vertical-align: middle;
  background: var(--app-neutral);
  flex: none;
}

.status-badge--success .status-dot { background: var(--app-success); }
.status-badge--info    .status-dot { background: var(--app-info); }
.status-badge--warning .status-dot { background: var(--app-warning); }
.status-badge--danger  .status-dot { background: var(--app-danger); }
.status-badge--neutral .status-dot { background: var(--app-neutral); }

/* Soft variant for dense lists/tables (tinted background instead of card). */
.status-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  background: #f1f5f9;
  color: #475569;
}

.status-chip--success { background: #dcfce7; color: #166534; }
.status-chip--info    { background: #dbeafe; color: #1e40af; }
.status-chip--warning { background: #fef3c7; color: #92400e; }
.status-chip--danger  { background: #fee2e2; color: #991b1b; }
.status-chip--neutral { background: #f1f5f9; color: #475569; }

/* --------------------------------------------------------------------------
   Count pill — small numeric counter next to section titles.
   -------------------------------------------------------------------------- */

.count-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid var(--app-line);
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.count-pill--danger {
  background: #fee2e2;
  border-color: #fecaca;
  color: #b91c1c;
}

/* --------------------------------------------------------------------------
   Empty state — friendly placeholder when a list/collection is empty.
   -------------------------------------------------------------------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  border: 2px dashed var(--app-line);
  border-radius: 12px;
  background: #fff;
  min-height: 220px;
  flex: 1 1 auto;
  width: 100%;
}

.empty-state--compact {
  min-height: 160px;
  padding: 32px 20px;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 14px;
  border-radius: 50%;
  border: 2px dashed var(--app-line);
  background: #f8fafc;
  color: var(--app-faint);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

/* --------------------------------------------------------------------------
   Info tile — small labeled value card used in sidebars and summary grids.
   -------------------------------------------------------------------------- */

.info-tile {
  height: 100%;
  background: #fff;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius-sm);
  padding: 0.8rem 0.9rem;
  min-width: 0;
}

.info-tile__label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--app-muted);
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.info-tile__label i {
  color: var(--app-faint);
  line-height: 1;
}

.info-tile__value {
  color: var(--app-ink);
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.info-tile__value a {
  color: inherit;
  text-decoration: none;
}

.info-tile__value a:hover {
  color: var(--secondary-color, #38ce3c);
  text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Table — calm rows, quiet header, no heavy borders.
   -------------------------------------------------------------------------- */

.app-table {
  --bs-table-hover-bg: #f8fafc;
}

.app-table thead th {
  background: #f8fafc;
  color: var(--app-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--app-border);
  white-space: nowrap;
}

.app-table tbody td,
.app-table tbody th {
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--app-line-soft);
  vertical-align: middle;
  color: var(--app-ink-2);
}

.app-table tbody tr:last-child td,
.app-table tbody tr:last-child th {
  border-bottom: 0;
}

.app-table tbody tr {
  transition: background-color 0.15s ease;
}

.app-table tbody tr:hover {
  background: #f8fafc;
}

/* Phones: a wide table becomes one card per row (no sideways scrolling).
   Each cell names itself with data-label; the row's main cell carries
   .app-table__main and its action cell .app-table__action. */
@media (max-width: 767.98px) {
  .app-table--stack,
  .app-table--stack tbody { display: block; }

  .app-table--stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .app-table--stack tbody tr {
    display: grid;
    gap: 0.375rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--app-line-soft);
  }
  .app-table--stack tbody tr:last-child { border-bottom: 0; }

  .app-table--stack tbody td,
  .app-table--stack tbody th {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: none !important;
    padding: 0;
    border: 0;
    text-align: start !important;
    white-space: normal;
  }
  .app-table--stack tbody td[data-label]::before {
    content: attr(data-label);
    flex: none;
    color: var(--app-muted);
    font-size: 0.8125rem;
    font-weight: 600;
  }
  .app-table--stack tbody .app-table__main {
    color: var(--app-ink);
    font-size: 0.9375rem;
    font-weight: 700;
    overflow-wrap: anywhere;
  }
  .app-table--stack tbody .app-table__action { margin-top: 0.375rem; }
  .app-table--stack tbody .app-table__action > * { flex: 1 1 auto; }
}

/* --------------------------------------------------------------------------
   Filter bar — pill filters on one scrollable line (RTL-safe).
   -------------------------------------------------------------------------- */

.app-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem;
  background: #fff;
  border: 1px solid var(--app-border);
  border-radius: 0.75rem;
  width: 100%;
}

.app-filter-bar .filter-btn,
.app-filter-bar .nav-link {
  border: 0;
  border-radius: 999px;
  padding: 0.4rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--app-muted);
  background: transparent;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-filter-bar .filter-btn:hover,
.app-filter-bar .nav-link:hover {
  color: var(--app-ink);
  background: #f1f5f9;
}

.app-filter-bar .filter-btn.active,
.app-filter-bar .nav-link.active {
  background: var(--primary-color, #181824);
  color: #fff;
}

/* --------------------------------------------------------------------------
   Search shell — leading icon + quiet input, used in list toolbars.
   -------------------------------------------------------------------------- */

.app-search {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
  max-width: 420px;
}

.app-search__icon {
  position: absolute;
  inset-inline-start: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--app-faint);
  font-size: 0.95rem;
  pointer-events: none;
}

.app-search__input {
  padding-inline-start: 2.4rem;
  border-color: var(--app-line);
  border-radius: var(--app-radius-sm);
}

.app-search__input:focus {
  border-color: var(--primary-color, #181824);
  box-shadow: 0 0 0 0.2rem rgba(24, 24, 36, 0.08);
}

/* --------------------------------------------------------------------------
   Clickable tile — card-shaped link used in card grids.
   -------------------------------------------------------------------------- */

.app-tile {
  display: block;
  height: 100%;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  background: #fff;
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease,
    border-color 0.18s ease;
}

.app-tile:hover {
  transform: translateY(-3px);
  border-color: #dbe2ea;
  box-shadow: 0 0.6rem 1.4rem rgba(15, 23, 42, 0.08);
  color: inherit;
}

.app-tile:focus-visible {
  outline: 2px solid var(--app-focus);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Icon box — tinted square behind a feature/menu icon.
   -------------------------------------------------------------------------- */

.app-icon-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  flex: none;
}

/* --------------------------------------------------------------------------
   Loader — branded "form is loading" state, built by static/js/app-loader.js
   (appLoader()). The cabinet mark from the favicon sits on a dark tile; a
   light runs around its frame while the two knobs blink in turn.
   -------------------------------------------------------------------------- */

.app-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2.5rem 1rem;
  text-align: center;
}

.app-loader__mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px;
  height: 72px;
  border-radius: 22px;
  background:
    radial-gradient(80% 80% at 100% 0%, rgba(56, 206, 60, 0.28) 0%, transparent 60%),
    radial-gradient(70% 70% at 0% 100%, rgba(142, 50, 233, 0.26) 0%, transparent 60%),
    linear-gradient(160deg, #23233a 0%, #181824 100%);
  box-shadow: 0 14px 30px -14px rgba(24, 24, 36, 0.7);
  animation: app-loader-float 2.4s ease-in-out infinite;
}

/* Soft halo that breathes out from the tile. */
.app-loader__mark::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.35);
  animation: app-loader-halo 2.4s ease-out infinite;
}

.app-loader__mark svg { width: 46px; height: 46px; overflow: visible; }
.app-loader__track { stroke: rgba(255, 200, 61, 0.22); }
.app-loader__run {
  stroke: #ffc83d;
  stroke-dasharray: 28 72;
  filter: drop-shadow(0 0 3px rgba(255, 200, 61, 0.8));
  animation: app-loader-run 1.6s linear infinite;
}
.app-loader__knob { fill: #ffc83d; animation: app-loader-knob 1.6s ease-in-out infinite; }
.app-loader__knob--end { animation-delay: 0.8s; }

.app-loader__title {
  margin: 0;
  color: var(--app-ink);
  font-size: 0.9375rem;
  font-weight: 700;
}
.app-loader__hint {
  margin: -0.625rem 0 0;
  color: var(--app-muted);
  font-size: 0.8125rem;
}

@keyframes app-loader-run { to { stroke-dashoffset: -100; } }
@keyframes app-loader-knob { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@keyframes app-loader-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes app-loader-halo {
  0% { box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.35); }
  100% { box-shadow: 0 0 0 16px rgba(255, 200, 61, 0); }
}

/* --------------------------------------------------------------------------
   Motion — respect the user's preference, everywhere.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .app-tile,
  .app-filter-bar .filter-btn,
  .app-filter-bar .nav-link,
  .app-table tbody tr,
  .status-badge,
  .count-pill {
    transition: none !important;
  }

  .app-tile:hover {
    transform: none;
  }

  /* Loader: no travelling light or bobbing, just a slow knob blink. */
  .app-loader__mark,
  .app-loader__mark::before,
  .app-loader__run {
    animation: none;
  }
  .app-loader__run { stroke-dasharray: none; filter: none; }
  .app-loader__knob { animation-duration: 3s; }
}
