/* ============================================================================
 *  INVOICE & AUTOMATED REMINDERS PWA — LIQUID GLASS DESIGN SYSTEM
 *  File: /css/style.css
 * ----------------------------------------------------------------------------
 *  "2026 Premium Liquid Glass" (Glassmorphic 2.0). Loaded AFTER Bootstrap so
 *  these rules override the framework defaults. Contents:
 *     1. Design tokens (:root custom properties)
 *     2. Global resets + native OS typography + tabular numerals
 *     3. Ambient gradient backdrop
 *     4. .glass-panel utility
 *     5. Form control + label overrides
 *     6. Buttons (primary / ghost / danger) + icon buttons
 *     7. Status pills (paid / overdue / draft / sent)
 *     8. Boot loader
 *     9. Auth gate
 *    10. App shell: sidebar, nav, user chip
 *    11. Main column: ticker bar + tickers
 *    12. View mount + generic cards / tables / bento grid
 *    13. Modals (glassified Bootstrap)
 *    14. Toasts
 *    15. Responsive (mobile sidebar drawer)
 * ==========================================================================*/

/* ============================================================================
 *  1. DESIGN TOKENS
 * ==========================================================================*/
:root {
  /* Native OS font stack — no web-font FOUT, instant premium feel. */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;

  /* Brand + accent palette */
  --blue:        #007aff;   /* iOS system blue — primary action + focus */
  --blue-strong: #0062cc;   /* pressed / hover */
  --blue-soft:   rgba(0, 122, 255, 0.10);
  --ice-100:     #eaf1fb;   /* translucent ice blue */
  --ice-200:     #dbe7f6;
  --slate-900:   #0b1b34;   /* deep slate — primary text */
  --slate-700:   #2b3b52;
  --slate-500:   #5b6b82;   /* secondary text */
  --slate-400:   #8494a8;   /* muted text */
  --white:       #ffffff;

  /* Status colours (soft translucent bg + dark readable text) */
  --paid-bg:     rgba(52, 199, 89, 0.15);   --paid-fg:    #0d7a3f;
  --overdue-bg:  rgba(255, 59, 48, 0.14);   --overdue-fg: #b3271e;
  --draft-bg:    rgba(120, 130, 148, 0.15); --draft-fg:   #48566b;
  --sent-bg:     rgba(0, 122, 255, 0.14);   --sent-fg:    #0056b3;

  /* Glass surface */
  --glass-bg:     rgba(255, 255, 255, 0.65);
  --glass-border: rgba(255, 255, 255, 0.40);
  --glass-blur:   20px;

  /* Squircle radii */
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 24px;
  --r-pill: 999px;

  /* Ultra-soft distributed depth (replaces harsh Bootstrap shadows) */
  --shadow-soft:  0 20px 40px rgba(0, 0, 0, 0.04);
  --shadow-card:  0 12px 30px rgba(11, 27, 52, 0.06);
  --shadow-float: 0 24px 60px rgba(11, 27, 52, 0.14);

  /* Layout dimensions */
  --sidebar-w: 264px;
  --ticker-h:  68px;
  --content-max: 1220px;

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur:  0.28s;
}

/* ============================================================================
 *  2. GLOBAL RESETS + TYPOGRAPHY
 * ==========================================================================*/
*,
*::before,
*::after { box-sizing: border-box; }

/* Ensure the HTML `hidden` attribute always wins over layout display rules. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--slate-900);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background: var(--ice-100);
  overflow-x: hidden;
}

/* Absolute vertical financial alignment for all numeric surfaces. */
table,
.app-view td,
.app-view th,
.kpi,
.kpi-value,
.currency,
.tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

h1, h2, h3, h4 { color: var(--slate-900); font-weight: 650; letter-spacing: -0.01em; }

a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-strong); }

:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

/* ============================================================================
 *  3. AMBIENT GRADIENT BACKDROP
 *     Soft, premium light field behind the glass panels.
 * ==========================================================================*/
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1200px 700px at 12% -8%, #ffffff 0%, rgba(255, 255, 255, 0) 55%),
    radial-gradient(1000px 800px at 108% 8%, #cfe0f7 0%, rgba(207, 224, 247, 0) 60%),
    radial-gradient(900px 900px at 50% 120%, #e2ecfb 0%, rgba(226, 236, 251, 0) 60%),
    linear-gradient(160deg, #eef3fb 0%, #dde9f8 48%, #e9f0fb 100%);
}

/* ============================================================================
 *  4. .glass-panel UTILITY
 * ==========================================================================*/
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-soft);
  border-radius: var(--r-xl);
}

/* ============================================================================
 *  5. FORM CONTROLS
 *     No border, soft fill, 12px radius. Focus = crisp blue border, white bg,
 *     NO glowing halo ring.
 * ==========================================================================*/
.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--slate-500);
  margin-bottom: 0.35rem;
}

.req { color: var(--overdue-fg); }

.form-control,
.form-select {
  border: 1px solid transparent;
  background: rgba(0, 0, 0, 0.03);
  border-radius: var(--r-sm);
  color: var(--slate-900);
  padding: 0.62rem 0.85rem;
  font-size: 0.95rem;
  box-shadow: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.form-control::placeholder { color: var(--slate-400); }

.form-control:focus,
.form-select:focus {
  border-color: var(--blue);
  background: var(--white);
  box-shadow: none;          /* explicitly kill Bootstrap's focus glow ring */
  outline: none;
}

textarea.form-control { resize: vertical; min-height: 2.6rem; }

/* ============================================================================
 *  6. BUTTONS
 * ==========================================================================*/
.btn {
  border-radius: var(--r-sm);
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  box-shadow: none;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus { box-shadow: none; }

.btn-primary {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--white);
  box-shadow: 0 8px 20px rgba(0, 122, 255, 0.28);
}
.btn-primary:hover,
.btn-primary:focus {
  background: var(--blue-strong);
  border-color: var(--blue-strong);
  color: var(--white);
  box-shadow: 0 10px 24px rgba(0, 122, 255, 0.34);
}

.btn-danger {
  background: var(--overdue-fg);
  border-color: var(--overdue-fg);
  color: var(--white);
  box-shadow: 0 8px 20px rgba(179, 39, 30, 0.22);
}
.btn-danger:hover,
.btn-danger:focus { background: #9c211a; border-color: #9c211a; color: var(--white); }

/* Ghost: quiet, translucent — used for cancel / secondary / sign out. */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(11, 27, 52, 0.04);
  color: var(--slate-700);
}
.btn-ghost:hover { background: rgba(11, 27, 52, 0.08); color: var(--slate-900); }

/* Bare icon button (ticker menu, etc). */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border: none;
  border-radius: var(--r-sm);
  background: rgba(11, 27, 52, 0.04);
  color: var(--slate-700);
  font-size: 1.25rem;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.icon-btn:hover { background: rgba(11, 27, 52, 0.09); }

/* ============================================================================
 *  7. STATUS PILLS
 * ==========================================================================*/
.badge-paid,
.badge-overdue,
.badge-draft,
.badge-sent {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.65rem;
  border-radius: var(--r-pill);
  font-size: 0.76rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1;
}
.badge-paid    { background: var(--paid-bg);    color: var(--paid-fg); }
.badge-overdue { background: var(--overdue-bg); color: var(--overdue-fg); }
.badge-draft   { background: var(--draft-bg);   color: var(--draft-fg); }
.badge-sent    { background: var(--sent-bg);    color: var(--sent-fg); }

/* ============================================================================
 *  8. BOOT LOADER
 * ==========================================================================*/
.app-loader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.app-loader__glass {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2.2rem 2.6rem;
  border-radius: var(--r-lg);
}
.app-loader__spinner {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(0, 122, 255, 0.18);
  border-top-color: var(--blue);
  animation: spin 0.9s linear infinite;
}
.app-loader__label { margin: 0; color: var(--slate-500); font-weight: 600; }

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

/* ============================================================================
 *  9. AUTH GATE
 * ==========================================================================*/
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 2.2rem;
  border-radius: var(--r-xl);
}
.auth-card__brand { text-align: center; margin-bottom: 1.6rem; }
.auth-card__logo {
  width: 62px; height: 62px;
  border-radius: var(--r-md);
  object-fit: cover;
  box-shadow: var(--shadow-card);
}
.auth-card__title { margin: 0.8rem 0 0.2rem; font-size: 1.4rem; }
.auth-card__subtitle { margin: 0; color: var(--slate-500); font-size: 0.92rem; }

.auth-form { margin-top: 0.5rem; }

.auth-error {
  background: var(--overdue-bg);
  color: var(--overdue-fg);
  border-radius: var(--r-sm);
  padding: 0.65rem 0.85rem;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.auth-switch {
  text-align: center;
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: var(--slate-500);
}
.auth-link {
  border: none;
  background: none;
  color: var(--blue);
  font-weight: 650;
  cursor: pointer;
  padding: 0;
}
.auth-link:hover { color: var(--blue-strong); text-decoration: underline; }

/* ============================================================================
 *  10. APP SHELL — SIDEBAR
 * ==========================================================================*/
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100dvh;
  gap: 0;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(11, 27, 52, 0.28);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  padding: 1.2rem 1rem;
  margin: 0.75rem 0 0.75rem 0.75rem;
  border-radius: var(--r-xl);
  z-index: 50;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.4rem 0.5rem 0.2rem;
}
.sidebar__logo {
  width: 38px; height: 38px;
  border-radius: 11px;
  object-fit: cover;
  box-shadow: var(--shadow-card);
}
.sidebar__brand-text { font-weight: 700; font-size: 1.12rem; letter-spacing: -0.02em; }

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1 1 auto;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-radius: var(--r-sm);
  color: var(--slate-700);
  font-weight: 600;
  font-size: 0.95rem;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item i { font-size: 1.1rem; width: 1.4rem; text-align: center; color: var(--slate-500); }
.nav-item:hover { background: rgba(11, 27, 52, 0.05); color: var(--slate-900); }
.nav-item:hover i { color: var(--slate-700); }

.nav-item.active {
  background: var(--blue);
  color: var(--white);
  box-shadow: 0 8px 20px rgba(0, 122, 255, 0.26);
}
.nav-item.active i { color: var(--white); }

.sidebar__footer {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding-top: 0.4rem;
  border-top: 1px solid rgba(11, 27, 52, 0.08);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.35rem 0.4rem;
}
.user-chip__avatar {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, var(--blue) 0%, #4aa3ff 100%);
  color: var(--white);
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
}
.user-chip__meta { display: flex; flex-direction: column; min-width: 0; }
.user-chip__name {
  font-weight: 650;
  font-size: 0.9rem;
  color: var(--slate-900);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-chip__role { font-size: 0.76rem; color: var(--slate-400); font-weight: 600; }

/* ============================================================================
 *  11. MAIN COLUMN — TICKER BAR
 * ==========================================================================*/
.main-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0.75rem 0.75rem 0.75rem 0.75rem;
  gap: 0.75rem;
}

.ticker-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--ticker-h);
  padding: 0 1.1rem;
  border-radius: var(--r-lg);
  position: sticky;
  top: 0.75rem;
  z-index: 30;
}
.ticker-bar__left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.ticker-bar__title {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ticker-bar__right { display: flex; align-items: center; gap: 0.6rem; }
.ticker-bar__menu { display: none; }   /* shown only on mobile */

.ticker-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.75rem;
  border-radius: var(--r-pill);
  font-size: 0.8rem;
  font-weight: 650;
  background: rgba(11, 27, 52, 0.05);
  color: var(--slate-700);
}
.ticker-pill__label { line-height: 1; }

.ticker-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.16);
}

/* Connectivity states (toggled by app.js). */
.ticker-pill--online  { color: var(--paid-fg);    background: var(--paid-bg); }
.ticker-pill--offline { color: var(--overdue-fg); background: var(--overdue-bg); }
.ticker-pill--offline .ticker-dot { box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.14); }

/* Sync ticker with a gently spinning icon while pending. */
.ticker-pill--sync { color: var(--sent-fg); background: var(--sent-bg); }
.ticker-pill--sync i { animation: spin 1.6s linear infinite; }

/* ============================================================================
 *  12. VIEW MOUNT + GENERIC CARDS / TABLES / BENTO
 * ==========================================================================*/
.app-view {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0.25rem 0.25rem 2rem;
}

/* Reusable content card (views compose these). */
.card-glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-card);
  border-radius: var(--r-xl);
  padding: 1.4rem 1.5rem;
}

/* Bento KPI grid for the dashboard. */
.bento-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.kpi-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-card);
  border-radius: var(--r-lg);
  padding: 1.3rem 1.4rem;
}
.kpi-label { font-size: 0.82rem; color: var(--slate-500); font-weight: 600; margin: 0 0 0.4rem; }
.kpi-value { font-size: 1.9rem; font-weight: 720; letter-spacing: -0.02em; color: var(--slate-900); }
.kpi-sub   { font-size: 0.8rem; color: var(--slate-400); margin-top: 0.25rem; }

/* Glass data table used across list views. */
.table-wrap {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-card);
  border-radius: var(--r-xl);
  overflow: hidden;
}
.app-view table { width: 100%; margin: 0; border-collapse: collapse; }
.app-view thead th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate-400);
  font-weight: 700;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid rgba(11, 27, 52, 0.08);
  background: rgba(255, 255, 255, 0.35);
}
.app-view tbody td {
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid rgba(11, 27, 52, 0.05);
  color: var(--slate-700);
  font-size: 0.92rem;
}
.app-view tbody tr:last-child td { border-bottom: none; }
.app-view tbody tr { transition: background var(--dur) var(--ease); }
.app-view tbody tr:hover { background: rgba(0, 122, 255, 0.04); }

/* Empty-state helper. */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--slate-400);
}
.empty-state i { font-size: 2.2rem; display: block; margin-bottom: 0.6rem; opacity: 0.7; }

/* ============================================================================
 *  13. MODALS (glassified Bootstrap)
 * ==========================================================================*/
.modal-content.glass-panel {
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-float);
  background: rgba(255, 255, 255, 0.82);
}
.modal-backdrop.show { opacity: 0.32; }
.modal-header {
  border-bottom: 1px solid rgba(11, 27, 52, 0.07);
  padding: 1.1rem 1.35rem;
}
.modal-title { font-weight: 680; letter-spacing: -0.01em; }
.modal-body { padding: 1.35rem; }
.modal-footer {
  border-top: 1px solid rgba(11, 27, 52, 0.07);
  padding: 0.9rem 1.35rem;
  gap: 0.5rem;
}
.btn-close:focus { box-shadow: none; }

/* ============================================================================
 *  14. TOASTS
 *     toast.js appends .toast-item nodes into #toast-container.
 * ==========================================================================*/
.toast-container {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2400;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: min(360px, calc(100vw - 2rem));
}
.toast-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-float);
  color: var(--slate-900);
  font-size: 0.9rem;
  font-weight: 550;
  animation: toast-in var(--dur) var(--ease);
}
.toast-item i { font-size: 1.15rem; line-height: 1.2; }
.toast-item.is-hiding { animation: toast-out var(--dur) var(--ease) forwards; }
.toast-item--success i { color: var(--paid-fg); }
.toast-item--error   i { color: var(--overdue-fg); }
.toast-item--info    i { color: var(--blue); }

@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(10px); } }

/* ============================================================================
 *  15. RESPONSIVE — MOBILE SIDEBAR DRAWER
 * ==========================================================================*/
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }

  /* Off-canvas drawer; app.js toggles .sidebar--open + the backdrop. */
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100dvh;
    width: min(84vw, var(--sidebar-w));
    margin: 0;
    border-radius: 0 var(--r-xl) var(--r-xl) 0;
    transform: translateX(-104%);
    transition: transform var(--dur) var(--ease);
  }
  .sidebar.sidebar--open { transform: translateX(0); }

  .ticker-bar__menu { display: inline-flex; }

  .main-column { padding: 0.6rem; }
  .app-view { padding: 0.25rem 0 2rem; }
}

@media (max-width: 480px) {
  .auth-card { padding: 1.6rem; }
  .kpi-value { font-size: 1.6rem; }
  .ticker-pill--sync .ticker-pill__label { display: none; }
}

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