/**
 * Neomorphic (Soft UI) Dual-Theme Design System
 * SaaS Subscription Management Platform
 * Themes: Classic (Soft Light) & Dark (Cyber Dark)
 */

/* ==============================================================================
   1. THEME DESIGN TOKENS (CSS Custom Properties)
   ============================================================================== */

/* THEME 1: CLASSIC (Soft Light Neomorphism) */
:root,
:root[data-theme="classic"] {
  --neo-bg: #e8edf5;
  --neo-surface: #e8edf5;
  --neo-surface-card: #eaf0f8;
  --neo-surface-inset: #e2e8f1;
  --neo-surface-header: rgba(232, 237, 245, 0.92);

  /* Shadows (Light specular top-left, dark ambient bottom-right) */
  --neo-shadow-dark: rgba(166, 178, 196, 0.62);
  --neo-shadow-light: rgba(255, 255, 255, 0.95);
  
  --neo-shadow-raised: 6px 6px 14px var(--neo-shadow-dark), -6px -6px 14px var(--neo-shadow-light);
  --neo-shadow-raised-hover: 8px 8px 18px var(--neo-shadow-dark), -8px -8px 18px var(--neo-shadow-light);
  --neo-shadow-inset: inset 3px 3px 6px var(--neo-shadow-dark), inset -3px -3px 6px var(--neo-shadow-light);
  --neo-shadow-sm: 3px 3px 8px var(--neo-shadow-dark), -3px -3px 8px var(--neo-shadow-light);
  --neo-shadow-modal: 12px 12px 28px var(--neo-shadow-dark), -10px -10px 24px var(--neo-shadow-light);

  /* Borders & Highlights */
  --neo-border: 1px solid rgba(255, 255, 255, 0.7);
  --neo-border-subtle: 1px solid rgba(203, 213, 225, 0.5);

  /* Typography */
  --neo-text-primary: #1e293b;
  --neo-text-secondary: #475569;
  --neo-text-muted: #64748b;
  --neo-text-heading: #0f172a;

  /* Accents */
  --neo-accent: #4f46e5;
  --neo-accent-glow: rgba(79, 70, 229, 0.35);
  --neo-accent-text: #ffffff;
}

/* THEME 2: DARK (Cyber Dark Neomorphism) */
:root[data-theme="dark"] {
  --neo-bg: #111522;
  --neo-surface: #161b2b;
  --neo-surface-card: #181f33;
  --neo-surface-inset: #0e121d;
  --neo-surface-header: rgba(22, 27, 43, 0.92);

  /* Shadows (Dark drop bottom-right, subtle neon/specular rim top-left) */
  --neo-shadow-dark: rgba(0, 0, 0, 0.65);
  --neo-shadow-light: rgba(255, 255, 255, 0.05);

  --neo-shadow-raised: 6px 6px 16px var(--neo-shadow-dark), -4px -4px 14px var(--neo-shadow-light);
  --neo-shadow-raised-hover: 8px 8px 20px var(--neo-shadow-dark), -6px -6px 16px var(--neo-shadow-light);
  --neo-shadow-inset: inset 3px 3px 6px var(--neo-shadow-dark), inset -2px -2px 5px var(--neo-shadow-light);
  --neo-shadow-sm: 3px 3px 8px var(--neo-shadow-dark), -2px -2px 6px var(--neo-shadow-light);
  --neo-shadow-modal: 14px 14px 32px var(--neo-shadow-dark), -8px -8px 24px var(--neo-shadow-light);

  /* Borders & Highlights */
  --neo-border: 1px solid rgba(255, 255, 255, 0.07);
  --neo-border-subtle: 1px solid rgba(255, 255, 255, 0.05);

  /* Typography */
  --neo-text-primary: #f8fafc;
  --neo-text-secondary: #cbd5e1;
  --neo-text-muted: #94a3b8;
  --neo-text-heading: #ffffff;

  /* Accents */
  --neo-accent: #6366f1;
  --neo-accent-glow: rgba(99, 102, 241, 0.4);
  --neo-accent-text: #ffffff;
}

/* ==============================================================================
   2. GLOBAL FOUNDATIONS & LAYOUT HARMONIZATION
   ============================================================================== */

html, body {
  background-color: var(--neo-bg) !important;
  color: var(--neo-text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
  box-shadow: none !important;
  border: none !important;
  border-radius: 0 !important;
}

/* Header */
header,
.portal-header {
  background-color: var(--neo-surface-header) !important;
  backdrop-filter: blur(10px);
  border-bottom: var(--neo-border) !important;
  box-shadow: 0 4px 12px var(--neo-shadow-dark);
}

header h1, header .text-slate-900 {
  color: var(--neo-text-heading) !important;
}

/* ==============================================================================
   2.1. TACTILE NEOMORPHIC SIDEBAR (Classic & Dark)
   ============================================================================== */

aside#sidebar {
  background-color: var(--neo-surface) !important;
  color: var(--neo-text-primary) !important;
  border-right: var(--neo-border) !important;
  box-shadow: 5px 0 20px var(--neo-shadow-dark);
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/* Sidebar Top Brand Header */
aside#sidebar .sidebar-brand {
  background-color: var(--neo-surface) !important;
  border-bottom: var(--neo-border-subtle) !important;
  color: var(--neo-text-heading) !important;
}

/* Sidebar Navigation Items */
aside#sidebar .sidebar-nav-item {
  color: var(--neo-text-secondary) !important;
  border: 1px solid transparent !important;
  border-radius: 12px !important;
  margin-bottom: 4px;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

aside#sidebar .sidebar-nav-item:hover {
  background-color: var(--neo-surface-card) !important;
  color: var(--neo-text-heading) !important;
  box-shadow: var(--neo-shadow-sm) !important;
  border: var(--neo-border-subtle) !important;
  transform: translateX(3px);
}

/* Classic Active Nav Item - Tactile Raised / Pressed Neomorphism */
:root[data-theme="classic"] aside#sidebar .sidebar-nav-item.active,
:root:not([data-theme="dark"]) aside#sidebar .sidebar-nav-item.active {
  background: var(--neo-accent) !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  box-shadow: 4px 4px 10px rgba(79, 70, 229, 0.4), -2px -2px 6px rgba(255, 255, 255, 0.9), inset 1px 1px 2px rgba(255, 255, 255, 0.35) !important;
  border: 1px solid rgba(255, 255, 255, 0.4) !important;
  transform: translateX(3px);
}

/* Dark Active Nav Item - Luminous Cyber Neomorphism */
:root[data-theme="dark"] aside#sidebar .sidebar-nav-item.active {
  background: var(--neo-accent) !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  box-shadow: 4px 4px 14px rgba(0, 0, 0, 0.7), -2px -2px 8px rgba(255, 255, 255, 0.08), inset 0 0 10px rgba(99, 102, 241, 0.45) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  transform: translateX(3px);
}

/* Sidebar Footer */
aside#sidebar .sidebar-footer {
  background-color: var(--neo-surface-inset) !important;
  border-top: var(--neo-border-subtle) !important;
  box-shadow: var(--neo-shadow-inset) !important;
}

aside#sidebar .sidebar-footer span {
  color: var(--neo-text-muted) !important;
}

/* Sidebar Logout Button */
aside#sidebar .sidebar-logout-btn {
  color: #f43f5e !important;
  background-color: transparent !important;
  border: 1px solid transparent !important;
  border-radius: 10px !important;
  transition: all 0.15s ease;
}

aside#sidebar .sidebar-logout-btn:hover {
  background-color: rgba(244, 63, 94, 0.12) !important;
  color: #e11d48 !important;
  box-shadow: var(--neo-shadow-sm) !important;
  border: 1px solid rgba(244, 63, 94, 0.2) !important;
}

/* ==============================================================================
   3. NEOMORPHIC CARDS, CONTAINERS & TABLES
   ============================================================================== */

/* Cards, White Sections & Stats */
:not(html):not(body):not(header):not(nav):not(aside).bg-white,
:not(html):not(body):not(header):not(nav):not(aside).bg-slate-50,
:not(html):not(body):not(header):not(nav):not(aside).bg-slate-800 {
  background-color: var(--neo-surface-card) !important;
  box-shadow: var(--neo-shadow-raised);
  border: var(--neo-border) !important;
  border-radius: 16px;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

:not(html):not(body):not(header):not(nav):not(aside).bg-white:hover {
  box-shadow: var(--neo-shadow-raised-hover);
}

/* Main Dashboard headings and text overrides */
h1, h2, h3, h4, .text-slate-900 {
  color: var(--neo-text-heading) !important;
}

p.text-slate-500, span.text-slate-500, td.text-slate-500, .text-slate-400 {
  color: var(--neo-text-muted) !important;
}

p.text-slate-600, span.text-slate-600, td.text-slate-600, .text-slate-700 {
  color: var(--neo-text-secondary) !important;
}

/* Tables */
table {
  background-color: transparent !important;
}

thead, thead tr, thead th {
  background-color: var(--neo-surface-inset) !important;
  color: var(--neo-text-muted) !important;
  border-bottom: var(--neo-border-subtle) !important;
}

tbody tr {
  border-bottom: var(--neo-border-subtle) !important;
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background-color: rgba(99, 102, 241, 0.05) !important;
}

/* Modals & Dialogs */
.fixed .bg-white,
.fixed .bg-slate-800,
.fixed .bg-slate-900 {
  background-color: var(--neo-surface) !important;
  box-shadow: var(--neo-shadow-modal) !important;
  border: var(--neo-border) !important;
  border-radius: 20px;
}

/* ==============================================================================
   4. TACTILE NEOMORPHIC FORM INPUTS & SEARCH BARS
   ============================================================================== */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
select,
textarea {
  background-color: var(--neo-surface-inset) !important;
  color: var(--neo-text-primary) !important;
  box-shadow: var(--neo-shadow-inset) !important;
  border: var(--neo-border-subtle) !important;
  border-radius: 12px !important;
  transition: all 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none !important;
  border-color: var(--neo-accent) !important;
  box-shadow: var(--neo-shadow-inset), 0 0 0 2px var(--neo-accent-glow) !important;
}

/* Filter pills & search container */
.c-filter,
.filter-btn {
  background-color: var(--neo-surface-inset) !important;
  box-shadow: var(--neo-shadow-sm) !important;
  border: var(--neo-border-subtle) !important;
  color: var(--neo-text-secondary) !important;
  border-radius: 10px !important;
  transition: all 0.15s ease;
}

.c-filter.bg-indigo-600,
.filter-btn.bg-white,
.filter-btn.bg-indigo-600 {
  background: var(--neo-accent) !important;
  color: #ffffff !important;
  box-shadow: var(--neo-shadow-inset), 0 0 8px var(--neo-accent-glow) !important;
}

/* ==============================================================================
   5. TACTILE BUTTONS & ACTIONS
   ============================================================================== */

button.bg-indigo-600,
a.bg-indigo-600,
.btn-primary {
  background: var(--neo-accent) !important;
  color: var(--neo-accent-text) !important;
  box-shadow: var(--neo-shadow-sm), 0 4px 12px var(--neo-accent-glow) !important;
  border: var(--neo-border) !important;
  border-radius: 12px !important;
  transition: all 0.15s ease-in-out;
}

button.bg-indigo-600:hover,
a.bg-indigo-600:hover {
  box-shadow: var(--neo-shadow-raised), 0 6px 16px var(--neo-accent-glow) !important;
  transform: translateY(-1px);
}

button.bg-indigo-600:active,
a.bg-indigo-600:active {
  box-shadow: var(--neo-shadow-inset) !important;
  transform: translateY(1px);
}

/* Secondary & Action buttons */
button.bg-slate-100,
button.bg-slate-200,
button.bg-slate-700,
button.bg-slate-700\/50,
button.bg-slate-800,
a.bg-slate-100 {
  background-color: var(--neo-surface-card) !important;
  color: var(--neo-text-primary) !important;
  box-shadow: var(--neo-shadow-sm) !important;
  border: var(--neo-border-subtle) !important;
  border-radius: 10px !important;
}

button.bg-slate-100:hover,
button.bg-slate-700:hover,
button.bg-slate-700\/50:hover,
button.bg-slate-800:hover,
a.bg-slate-100:hover {
  box-shadow: var(--neo-shadow-raised) !important;
}

button.bg-slate-100:active,
button.bg-slate-700:active,
button.bg-slate-800:active,
a.bg-slate-100:active {
  box-shadow: var(--neo-shadow-inset) !important;
}

/* Badges */
.rounded-full, .rounded-md, .rounded-lg {
  border: var(--neo-border-subtle);
}

/* ==============================================================================
   6. UTILITY CLASSES FOR DIRECT NEOMORPHIC COMPONENT CREATION
   ============================================================================== */

.neo-raised {
  background-color: var(--neo-surface-card) !important;
  box-shadow: var(--neo-shadow-raised) !important;
  border: var(--neo-border) !important;
}

.neo-raised:hover {
  box-shadow: var(--neo-shadow-raised-hover) !important;
}

.neo-inset {
  background-color: var(--neo-surface-inset) !important;
  box-shadow: var(--neo-shadow-inset) !important;
  border: var(--neo-border-subtle) !important;
}

.neo-pill {
  border-radius: 9999px !important;
  box-shadow: var(--neo-shadow-sm) !important;
}

.neo-flat {
  background-color: var(--neo-surface) !important;
  border: var(--neo-border-subtle) !important;
}

/* Custom Neomorphic Scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: var(--neo-surface-inset);
}
::-webkit-scrollbar-thumb {
  background: var(--neo-shadow-dark);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--neo-accent);
}

/* ==============================================================================
   7. NEOMORPHIC MODAL DIALOG SYSTEM (Classic & Dark Dual-Theme)
   ============================================================================== */

.neo-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background-color: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

[data-theme="dark"] .neo-dialog-backdrop {
  background-color: rgba(5, 8, 16, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.neo-dialog-backdrop.neo-dialog-visible {
  opacity: 1;
  pointer-events: auto;
}

.neo-dialog-backdrop.neo-dialog-closing {
  opacity: 0;
  pointer-events: none;
}

/* Modal Card with soft neomorphic clay elevation */
.neo-dialog-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  background-color: var(--neo-surface-card);
  border-radius: 1.5rem;
  padding: 1.75rem;
  border: var(--neo-border);
  box-shadow: var(--neo-shadow-modal);
  transform: scale(0.92) translateY(10px);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s ease;
}

.neo-dialog-backdrop.neo-dialog-visible .neo-dialog-card {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.neo-dialog-backdrop.neo-dialog-closing .neo-dialog-card {
  transform: scale(0.92) translateY(10px);
  opacity: 0;
}

/* Header & Close */
.neo-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.neo-dialog-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--neo-surface);
  border: var(--neo-border-subtle);
  color: var(--neo-text-muted);
  box-shadow: var(--neo-shadow-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
}

.neo-dialog-close:hover {
  color: var(--neo-text-primary);
  transform: scale(1.05);
}

.neo-dialog-close:active {
  box-shadow: var(--neo-shadow-inset);
  transform: scale(0.95);
}

/* Tactile Icon Badges with Dual-Theme Soft Glow */
.neo-dialog-icon-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 1rem;
  font-size: 1.5rem;
  transition: transform 0.2s ease;
}

/* Info Variant */
.neo-dialog-icon-badge.neo-dialog-info {
  background: var(--neo-surface);
  color: #4f46e5;
  box-shadow: var(--neo-shadow-inset);
  border: 1px solid rgba(79, 70, 229, 0.2);
}
[data-theme="dark"] .neo-dialog-icon-badge.neo-dialog-info {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  box-shadow: inset 0 0 12px rgba(99, 102, 241, 0.25), var(--neo-shadow-sm);
  border: 1px solid rgba(99, 102, 241, 0.35);
}

/* Warning / Pause Variant */
.neo-dialog-icon-badge.neo-dialog-warning {
  background: var(--neo-surface);
  color: #d97706;
  box-shadow: var(--neo-shadow-inset);
  border: 1px solid rgba(217, 119, 6, 0.25);
}
[data-theme="dark"] .neo-dialog-icon-badge.neo-dialog-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  box-shadow: inset 0 0 12px rgba(245, 158, 11, 0.25), var(--neo-shadow-sm);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Danger / Destructive Variant */
.neo-dialog-icon-badge.neo-dialog-danger {
  background: var(--neo-surface);
  color: #dc2626;
  box-shadow: var(--neo-shadow-inset);
  border: 1px solid rgba(220, 38, 38, 0.25);
}
[data-theme="dark"] .neo-dialog-icon-badge.neo-dialog-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  box-shadow: inset 0 0 12px rgba(239, 68, 68, 0.25), var(--neo-shadow-sm);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* Success Variant */
.neo-dialog-icon-badge.neo-dialog-success {
  background: var(--neo-surface);
  color: #059669;
  box-shadow: var(--neo-shadow-inset);
  border: 1px solid rgba(5, 150, 105, 0.25);
}
[data-theme="dark"] .neo-dialog-icon-badge.neo-dialog-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  box-shadow: inset 0 0 12px rgba(16, 185, 129, 0.25), var(--neo-shadow-sm);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

/* Dialog Body & Typography */
.neo-dialog-body {
  margin-bottom: 1.5rem;
}

.neo-dialog-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--neo-text-heading);
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.015em;
  line-height: 1.3;
}

.neo-dialog-message {
  font-size: 0.9375rem;
  color: var(--neo-text-secondary);
  line-height: 1.55;
  margin: 0;
  word-break: break-word;
}

/* Input Wrapper & Inset Field for Prompt */
.neo-dialog-input-wrap {
  margin-top: 1.25rem;
}

.neo-dialog-input {
  width: 100%;
  background-color: var(--neo-surface-inset);
  border: var(--neo-border-subtle);
  border-radius: 0.875rem;
  padding: 0.8rem 1rem;
  font-size: 0.9375rem;
  color: var(--neo-text-primary);
  box-shadow: var(--neo-shadow-inset);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

.neo-dialog-input:focus {
  border-color: var(--neo-accent);
  box-shadow: var(--neo-shadow-inset), 0 0 0 2px var(--neo-accent-glow);
}

/* Action Buttons Grid / Row */
.neo-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.neo-dialog-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 0.875rem;
  cursor: pointer;
  outline: none;
  border: none;
  transition: all 0.15s ease;
  user-select: none;
}

/* Cancel Button: Raised Soft Clay */
.neo-dialog-btn-cancel {
  background-color: var(--neo-surface);
  color: var(--neo-text-secondary);
  border: var(--neo-border-subtle);
  box-shadow: var(--neo-shadow-raised);
}

.neo-dialog-btn-cancel:hover {
  color: var(--neo-text-primary);
  box-shadow: var(--neo-shadow-raised-hover);
  transform: translateY(-1px);
}

.neo-dialog-btn-cancel:active {
  box-shadow: var(--neo-shadow-inset) !important;
  transform: translateY(1px);
}

/* Primary Button: Vibrant Neomorphic Accent */
.neo-dialog-btn-primary {
  background-color: var(--neo-accent);
  color: var(--neo-accent-text);
  box-shadow: 0 4px 14px var(--neo-accent-glow), var(--neo-shadow-sm);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.neo-dialog-btn-primary:hover {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px var(--neo-accent-glow), var(--neo-shadow-raised-hover);
  transform: translateY(-1px);
}

.neo-dialog-btn-primary:active {
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4) !important;
  transform: translateY(1px);
}

/* Danger Button: Destructive Red */
.neo-dialog-btn-danger {
  background-color: #dc2626 !important;
  color: #ffffff !important;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4), var(--neo-shadow-sm) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.neo-dialog-btn-danger:hover {
  background-color: #b91c1c !important;
  box-shadow: 0 6px 18px rgba(220, 38, 38, 0.5) !important;
  transform: translateY(-1px);
}

.neo-dialog-btn-danger:active {
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5) !important;
  transform: translateY(1px);
}

/* Warning Button: Pause / Caution Amber */
.neo-dialog-btn-warning {
  background-color: #d97706 !important;
  color: #ffffff !important;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.4), var(--neo-shadow-sm) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
}

.neo-dialog-btn-warning:hover {
  background-color: #b45309 !important;
  box-shadow: 0 6px 18px rgba(217, 119, 6, 0.5) !important;
  transform: translateY(-1px);
}

.neo-dialog-btn-warning:active {
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5) !important;
  transform: translateY(1px);
}
