/*
 * BellSystems Control Panel v2 — Global Base Styles
 *
 * SCOPING STRATEGY:
 * All rules that could affect v1 are scoped under .app
 * The .app wrapper div is placed in V2Router, wrapping all v2 output.
 * Only truly safe globals (box-sizing, CSS tokens) are unscoped.
 */

@import "tailwindcss";
@import './tokens.css';
@import './components.css';

/* ==========================================================================
   SAFE GLOBALS — these do not affect v1 visually
   ========================================================================== */

/* Box sizing — safe, v1 likely already has this */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* CSS custom properties on :root — safe, tokens are inert until used */
/* (tokens.css is imported above and defines all --color-*, --space-*, etc.) */

/* ==========================================================================
   V2 SCOPED STYLES — only apply inside .app
   ========================================================================== */

.app {
  /* Base layout */
  display: flex;
  min-height: 100dvh;
  width: 100%;

  /* Typography */
  font-family: var(--font-family-base);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-base);
  color: var(--color-text-primary);
  background-color: var(--color-bg-base);

  /* Full-viewport background — extends behind sidebar and header */
  background-image: url('@/assets/images/background2.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;

  /* Rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Typography */
.app h1,
.app h2,
.app h3,
.app h4,
.app h5,
.app h6 {
  font-family: var(--font-family-base);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  margin: 0;
  padding: 0;
}

/* Display headings — Barlow Condensed gives an engineered, instrument-panel quality */
.app h1,
.app h2 {
  font-family: var(--font-family-display);
  font-weight: var(--font-weight-semibold);
  letter-spacing: var(--tracking-tight);
}

.app h1 { font-size: var(--font-size-xl); }
.app h2 { font-size: var(--font-size-xl); }
.app h3 { font-size: var(--font-size-md); }
.app h4 { font-size: var(--font-size-base); }
.app h5 { font-size: var(--font-size-sm); }
.app h6 { font-size: var(--font-size-xs); }

.app p {
  color: var(--color-text-primary);
  line-height: var(--line-height-base);
  margin: 0;
  padding: 0;
}

/* Links */
.app a {
  color: var(--color-text-accent);
  text-decoration: none;
  transition: color var(--transition-fast), opacity var(--transition-fast);
}

.app a:hover {
  color: var(--color-primary-hover);
}

.app a:focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Lists */
.app ul,
.app ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Media */
.app img,
.app video,
.app svg {
  display: block;
  max-width: 100%;
}

/* Form elements — exclude named component classes so their styles aren't overridden */
.app button:not(.btn):not(.select-trigger):not(.nav-group-btn):not(.header-hamburger):not(.header-signout):not(.drawer-close):not(.header-icon-btn):not(.header-profile):not(.profile-menu-item),
.app input:not(.input):not(.searchbar-input),
.app select:not(.input),
.app textarea:not(.input) {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  outline: none;
  margin: 0;
  padding: 0;
}

.app button:not(.btn):not(.select-trigger):not(.nav-group-btn):not(.header-hamburger):not(.header-signout):not(.drawer-close):not(.header-icon-btn):not(.header-profile):not(.profile-menu-item) {
  cursor: pointer;
  line-height: inherit;
}

.app button:not(.btn):not(.select-trigger):not(.nav-group-btn):not(.header-hamburger):not(.header-signout):not(.drawer-close):not(.header-icon-btn):not(.header-profile):not(.profile-menu-item):disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app textarea {
  resize: vertical;
}

.app select {
  appearance: none;
  -webkit-appearance: none;
}

/* Autofill */
.app input:-webkit-autofill,
.app input:-webkit-autofill:hover,
.app input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px var(--color-bg-abyss) inset;
  -webkit-text-fill-color: var(--color-text-primary);
  caret-color: var(--color-text-primary);
  transition: background-color 5000s ease-in-out 0s;
}

/* Tables */
.app table {
  border-collapse: collapse;
  width: 100%;
}

/* Code */
.app code,
.app kbd,
.app samp,
.app pre {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

.app code {
  background-color: var(--color-bg-elevated);
  color: var(--color-primary);
  padding: 1px var(--space-1);
  border-radius: var(--radius-sm);
}

.app pre {
  background-color: var(--color-bg-abyss);
  color: var(--color-text-primary);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.app pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Focus */
.app :focus {
  outline: none;
}

.app :focus-visible {
  outline: 2px solid var(--color-border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Selection */
.app ::selection {
  background-color: rgba(192, 193, 255, 0.20);
  color: var(--color-text-primary);
}

/* HR */
.app hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-6) 0;
}

/* Page wrapper utility */
.app .page-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-8);
  gap: var(--space-6);
  min-width: 0;
}

@media (max-width: 768px) {
  .app .page-wrapper {
    padding: var(--space-8);
    gap: var(--space-4);
  }
}

/*
 * Centered content mode
 * Use on pages where content has a bounded width and should be centered in
 * the available area regardless of viewport size (e.g. settings forms,
 * login, simple detail pages).
 *
 * Usage:
 *   <div className="page-wrapper page-wrapper--centered">
 *
 * By default centers at --content-max-width-sm (640px).
 * Override by adding a custom max-width inline only when truly needed:
 *   style={{ '--page-content-max-width': 'var(--content-max-width-md)' }}
 */
.app .page-wrapper--centered {
  align-items: center;
}

.app .page-wrapper--centered > * {
  width: 100%;
  max-width: var(--page-content-max-width, var(--content-max-width-sm));
}

/*
 * Masonry column layout
 * Sections flow top-to-bottom then left-to-right, automatically filling
 * the shortest column first (true CSS column masonry).
 *
 * Usage — wrap sections inside .page-wrapper with:
 *   <div className="masonry-grid masonry-grid--2">   ← 2 columns
 *   <div className="masonry-grid masonry-grid--3">   ← 3 columns
 *
 * Direct children must opt out of column breaks:
 *   Every Card / panel inside a .masonry-grid must have break-inside: avoid.
 *   The Card component already sets this via the .v2-card rule in components.css.
 *
 * On mobile (< 768px) all grids collapse to a single column automatically.
 *
 * Rules:
 * - Use this for ALL content pages with multiple variable-height sections
 * - Do NOT use fixed grid (grid-template-columns) for variable-height sections
 * - Do NOT use this for DataTable pages — tables should span full width
 */
.app .masonry-grid {
  columns: 1;
  column-gap: var(--space-6);
}

.app .masonry-grid > * {
  break-inside: avoid;
  margin-bottom: var(--space-6);
}

.app .masonry-grid--2 { columns: 2; }
.app .masonry-grid--3 { columns: 3; }
.app .masonry-grid--4 { columns: 4; }

@media (max-width: 1024px) {
  .app .masonry-grid--4 { columns: 3; }
  .app .masonry-grid--3 { columns: 2; }
}

@media (max-width: 768px) {
  .app .masonry-grid--2,
  .app .masonry-grid--3,
  .app .masonry-grid--4 { columns: 1; }
}

/*
 * Ultrawide cap mode
 * Prevents content from spanning absurdly wide on 2000px+ displays.
 * The wrapper itself is capped and centered — children fill it normally.
 *
 * Usage:
 *   <div className="page-wrapper page-wrapper--capped">
 *
 * The cap is token-driven — change --content-max-width-ultrawide in tokens.css
 * to adjust for all capped pages at once.
 */
.app .page-wrapper--capped {
  max-width: var(--content-max-width-ultrawide);
  margin-inline: auto;
  width: 100%;
}

/* Scrollbars — scoped to app */
.app {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

.app ::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: var(--scrollbar-width);
}

.app ::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

.app ::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: var(--scrollbar-radius);
}

.app ::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-border-strong);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .app *,
  .app *::before,
  .app *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
