/* ============================================================================
   TallyGST Pro Suite - Offline Tailwind-Compatible Enterprise Design System
   Amazon Seller Central Inspired Layout | Dynamic Brand Themes | Light & Dark
   Zero External CDN Dependencies
   ============================================================================ */

:root {
  --brand-primary: #131921;
  --brand-secondary: #232F3E;
  --brand-accent: #FF9900;
  --bg-body: #F3F5F8;
  --bg-surface: #FFFFFF;
  --bg-muted: #F8FAFC;
  --border-color: #E2E8F0;
  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.14);
}

html.dark {
  --bg-body: #0B1120;
  --bg-surface: #111827;
  --bg-muted: #1E293B;
  --border-color: #273449;
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #94A3B8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 32px rgba(0, 0, 0, 0.6);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: "Inter", "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
.tabular-nums { font-variant-numeric: tabular-nums; }

/* ---- Amazon-Style Dual-Tier Topbar ---- */
.amz-topbar {
  background: var(--brand-primary);
  color: #FFFFFF;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  gap: 0.75rem;
}

.amz-subbar {
  background: var(--brand-secondary);
  color: #E2E8F0;
  min-height: 40px;
  padding: 0.35rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.85rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.amz-accent-dot { background: var(--brand-accent); }
.amz-accent-text { color: var(--brand-accent); }

/* ---- App Shell & Collapsible Sidebar ---- */
.app-shell {
  display: flex;
  min-height: calc(100vh - 98px);
}

.app-sidebar {
  width: 252px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: transform 0.2s ease;
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 1.25rem 1.5rem 2.5rem;
}

.nav-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.85rem 0.75rem 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.58rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.nav-item:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.nav-item.active {
  background: color-mix(in srgb, var(--brand-accent) 14%, transparent);
  color: var(--text-primary);
  font-weight: 600;
  border-left: 3px solid var(--brand-accent);
  border-top-left-radius: 0.2rem;
  border-bottom-left-radius: 0.2rem;
}

.nav-item.disabled-phase {
  opacity: 0.55;
  cursor: default;
}

/* ---- Surfaces & Cards ---- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-body { padding: 1.25rem; }

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.15rem 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.kpi-icon {
  width: 42px;
  height: 42px;
  border-radius: 0.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.52rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.88rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand-accent);
  color: #111827;
}
.btn-primary:hover { filter: brightness(0.93); }

.btn-dark {
  background: var(--brand-secondary);
  color: #FFFFFF;
}
.btn-dark:hover { filter: brightness(1.12); }

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-muted); }

.btn-danger {
  background: #DC2626;
  color: #FFFFFF;
}
.btn-danger:hover { background: #B91C1C; }

.btn-sm { padding: 0.34rem 0.68rem; font-size: 0.8rem; }

/* ---- Forms ---- */
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.56rem 0.78rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 22%, transparent);
}

.topbar-select {
  background: rgba(255,255,255,0.1);
  color: #FFFFFF;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 0.45rem;
  padding: 0.38rem 0.65rem;
  font-size: 0.84rem;
  outline: none;
  max-width: 280px;
}
.topbar-select option { color: #0F172A; background: #FFFFFF; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; width: 100%; }
.pro-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.pro-table th {
  text-align: left;
  padding: 0.72rem 0.9rem;
  background: var(--bg-muted);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}
.pro-table td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}
.pro-table tbody tr:hover { background: var(--bg-muted); }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-filed      { background: #DCFCE7; color: #166534; }
.badge-nil        { background: #E0F2FE; color: #075985; }
.badge-reconciled { background: #FEF3C7; color: #92400E; }
.badge-pending    { background: #FEE2E2; color: #991B1B; }
.badge-neutral    { background: var(--bg-muted); color: var(--text-secondary); border: 1px solid var(--border-color); }
.badge-role       { background: #EEF2FF; color: #3730A3; }

html.dark .badge-filed      { background: rgba(22, 163, 74, 0.22); color: #86EFAC; }
html.dark .badge-nil        { background: rgba(2, 132, 199, 0.22); color: #7DD3FC; }
html.dark .badge-reconciled { background: rgba(217, 119, 6, 0.24); color: #FDE68A; }
html.dark .badge-pending    { background: rgba(220, 38, 38, 0.24); color: #FCA5A5; }
html.dark .badge-role       { background: rgba(99, 102, 241, 0.22); color: #C7D2FE; }

/* ---- Modals ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

/* ---- Alerts & Toasts ---- */
.alert {
  padding: 0.8rem 1rem;
  border-radius: 0.55rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid transparent;
}
.alert-success { background: #ECFDF5; color: #065F46; border-color: #A7F3D0; }
.alert-error   { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
html.dark .alert-success { background: rgba(6, 95, 70, 0.3); color: #6EE7B7; border-color: #065F46; }
html.dark .alert-error   { background: rgba(153, 27, 27, 0.3); color: #FCA5A5; border-color: #991B1B; }

#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* ---- Utility Classes (Tailwind-Compatible Subset) ---- */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.hidden { display: none; }
.block { display: block; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1 1 0%; }
.shrink-0 { flex-shrink: 0; }
.gap-1 { gap: 0.25rem; } .gap-2 { gap: 0.5rem; } .gap-3 { gap: 0.75rem; } .gap-4 { gap: 1rem; } .gap-5 { gap: 1.25rem; } .gap-6 { gap: 1.5rem; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.w-full { width: 100%; } .w-4 { width: 1rem; } .w-5 { width: 1.25rem; } .w-6 { width: 1.5rem; } .w-8 { width: 2rem; } .w-10 { width: 2.5rem; }
.h-4 { height: 1rem; } .h-5 { height: 1.25rem; } .h-6 { height: 1.5rem; } .h-8 { height: 2rem; } .h-10 { height: 2.5rem; }
.p-2 { padding: 0.5rem; } .p-3 { padding: 0.75rem; } .p-4 { padding: 1rem; } .p-5 { padding: 1.25rem; } .p-6 { padding: 1.5rem; }
.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; } .px-3 { padding-left: 0.75rem; padding-right: 0.75rem; } .px-4 { padding-left: 1rem; padding-right: 1rem; }
.py-1 { padding-top: 0.25rem; padding-bottom: 0.25rem; } .py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; } .py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.mb-1 { margin-bottom: 0.25rem; } .mb-2 { margin-bottom: 0.5rem; } .mb-3 { margin-bottom: 0.75rem; } .mb-4 { margin-bottom: 1rem; } .mb-6 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.25rem; } .mt-2 { margin-top: 0.5rem; } .mt-3 { margin-top: 0.75rem; } .mt-4 { margin-top: 1rem; } .mt-6 { margin-top: 1.5rem; }
.text-xs { font-size: 0.76rem; } .text-sm { font-size: 0.86rem; } .text-base { font-size: 0.96rem; } .text-lg { font-size: 1.12rem; } .text-xl { font-size: 1.32rem; } .text-2xl { font-size: 1.65rem; }
.font-medium { font-weight: 500; } .font-semibold { font-weight: 600; } .font-bold { font-weight: 700; } .font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.text-muted { color: var(--text-muted); } .text-secondary { color: var(--text-secondary); } .text-right { text-align: right; } .text-center { text-align: center; }
.rounded { border-radius: 0.375rem; } .rounded-lg { border-radius: 0.65rem; } .rounded-full { border-radius: 9999px; }
.border { border: 1px solid var(--border-color); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Matrix Cell Button ---- */
.matrix-cell-btn {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  width: 100%;
  padding: 0.32rem 0.38rem;
  border-radius: 0.45rem;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.matrix-cell-btn:hover {
  border-color: var(--brand-accent);
  transform: translateY(-1px);
}

/* ---- Responsive Breakpoints ---- */
.mobile-only { display: none; }

@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }
  .grid-cols-4, .grid-cols-3, .grid-cols-2 { grid-template-columns: 1fr; }
  .app-sidebar {
    position: fixed;
    top: 58px;
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { padding: 1rem; }
}
