/* ==========================================================================
   PREMIUM DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
  /* Palette: Modern Luxury Neutral (Slate/Zinc) */
  --bg: #f8fafc;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  
  /* Brand: Deep Royal Amethyst / Velvet Blue */
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-light: #eef2ff;
  
  /* Contextual Semantic Colors */
  --good: #0d9488;
  --good-bg: #f0fdfa;
  --bad: #e11d48;
  --bad-bg: #fff1f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  
  /* Shadows & Depth */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.04), 0 4px 6px -4px rgba(15, 23, 42, 0.02);
  --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.06), 0 8px 10px -6px rgba(15, 23, 42, 0.03);
  
  /* Smooth Transitions */
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   GLOBAL RESET & TYPOGRAPHY
   ========================================================================== */
* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  letter-spacing: -0.01em;
}

/* ==========================================================================
   APP CORE LAYOUT
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  background: #090d16;
  color: #f8fafc;
  padding: 28px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.sidebar nav {
  display: grid;
  gap: 4px;
  flex: 1;
}

.content {
  flex: 1;
  padding: 40px 48px;
  overflow: auto;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Brand Identity Header */
.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 32px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #818cf8);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 500;
}

/* Navigation Links */
.sidebar a {
  color: #94a3b8;
  text-decoration: none;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  transition: var(--transition);
}

.sidebar a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.sidebar a.active {
  background: var(--brand);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.sidebar-logout {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: #cbd5e1;
  border-radius: 10px;
  padding: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.sidebar-logout:hover {
  background: #1e293b;
  color: #fff;
  border-color: transparent;
}

/* ==========================================================================
   PAGE HEADERS & UI CARDS
   ========================================================================== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
}

.page-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card h2 {
  margin: 0 0 20px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ==========================================================================
   GRIDS & LAYOUT STRUCTURING
   ========================================================================== */
.grid {
  display: grid;
  gap: 24px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Advanced Premium KPI Dashboard Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi b {
  display: block;
  font-size: 26px;
  font-weight: 700;
  margin-top: 10px;
  letter-spacing: -0.03em;
}

/* ==========================================================================
   PREMIUM DATA TABLES
   ========================================================================== */
.table-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 14px 16px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--line);
}

td {
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
}

tr:last-child td {
  border-bottom: 0;
}

tr:hover td {
  background: #f8fafc;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.void-row {
  opacity: 0.45;
  text-decoration: line-through;
  background: #f8fafc;
}

/* ==========================================================================
   INPUTS & PRESETS DECORATION
   ========================================================================== */
.form {
  display: grid;
  gap: 18px;
}

.form.wide {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
}

.field span {
  color: #334155;
}

input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  outline: none;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.15);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.readonly-input {
  background: #f8fafc;
  color: #334155;
  font-weight: 600;
  border-style: dashed;
  box-shadow: none;
  cursor: not-allowed;
}

/* ==========================================================================
   BUTTONS & ACTIONS
   ========================================================================== */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 20px;
  font-weight: 650;
  font-size: 14px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
  width: max-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}

.btn:hover {
  background: var(--brand-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.3);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn.secondary {
  background: #fff;
  color: #334155;
  border: 1px solid #cbd5e1;
  box-shadow: var(--shadow-sm);
}

.btn.secondary:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  box-shadow: var(--shadow-sm);
}

/* Table Actions Mini-Buttons */
.content table td .btn.secondary,
.content table td button.btn.secondary {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
}

.action-cell {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 170px;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

/* ==========================================================================
   INTERACTIVE REFINEMENTS (TABS & ALERTS)
   ========================================================================== */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 24px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 10px;
  width: max-content;
}

.tab {
  border: 0;
  background: transparent;
  color: #64748b;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.alert {
  padding: 14px 18px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-weight: 600;
  font-size: 14px;
  background: var(--good-bg);
  color: var(--good);
  border: 1px solid rgba(13, 148, 136, 0.15);
}

.alert.error {
  background: var(--bad-bg);
  color: var(--bad);
  border: 1px solid rgba(225, 29, 72, 0.15);
}

.card .alert {
  margin: 0 0 16px;
}

/* ==========================================================================
   FINANCIAL INVOICING SUMMARY ELEMENTS
   ========================================================================== */
.invoice-summary {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}

.invoice-summary span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invoice-summary b {
  display: block;
  margin-top: 6px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.balance-due { color: var(--warning); }
.balance-clear { color: var(--good); }
.balance-advance { color: var(--brand); }

.advance-input {
  border-color: #a5b4fc;
  background: #f5f7ff;
  color: var(--brand);
}

/* ==========================================================================
   AUTHENTICATION MODULE LAYOUT (PREMIUM CLEAN GRADIENT)
   ========================================================================== */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(100% 100% at top left, #f8fafc 0%, #eef2ff 100%);
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  background: #fff;
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 24px;
  padding: 40px;
  box-shadow: var(--shadow-xl);
}

.auth-logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), #818cf8);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  font-size: 24px;
  margin-bottom: 24px;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.25);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.auth-subtitle {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 15px;
}

.link-btn {
  background: none;
  border: 0;
  color: var(--brand);
  font-weight: 700;
  margin-top: 16px;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
}

.link-btn:hover {
  text-decoration: underline;
}

.auth-note {
  margin-top: 24px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.6;
}

/* ==========================================================================
   MISCELLANEOUS UTILITIES
   ========================================================================== */
.loading {
  padding: 24px;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
}

.loading.full {
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
}

.empty {
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: #fafafa;
}

.info-box {
  grid-column: 1 / -1;
  border: 1px dashed #cbd5e1;
  background: #f8fafc;
  border-radius: 12px;
  padding: 14px 16px;
  color: #475569;
  font-size: 13px;
  line-height: 1.6;
}

.info-box b {
  color: var(--ink);
}

.settings-preview {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.settings-preview h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
}

.settings-preview p {
  margin: 4px 0;
  color: #475569;
  font-size: 14px;
}

.nice-list {
  line-height: 1.8;
  color: #334155;
}

.good-text { color: var(--good); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
small { color: var(--muted); font-weight: 600; }
.field textarea { font-weight: 400; }

/* Numeric alignments formatting */
input[inputmode=decimal] { font-variant-numeric: tabular-nums; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -webkit-appearance: textfield; appearance: textfield; -moz-appearance: textfield; }

/* ==========================================================================
   RESPONSIVE DESIGN ADAPTATIONS
   ========================================================================== */
@media(max-width: 1100px) {
  .grid.three, .grid.two, .kpi-grid, .filter-row {
    grid-template-columns: 1fr;
  }
  .sidebar {
    width: 240px;
  }
  .content {
    padding: 32px;
  }
  .form.wide, .invoice-summary {
    grid-template-columns: 1fr;
  }
}

@media(max-width: 900px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 20px;
  }
  .sidebar nav {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }
  .content {
    padding: 24px 16px;
  }
  .action-cell {
    min-width: 0;
  }
}