:root {
  /* Space Gray Premium Theme */
  --bg-app: #1c1c1e;
  /* Deep Space Gray */
  --bg-panel: #2c2c2e;
  /* Lighter Space Gray for Sidebar */
  --bg-card: #3a3a3c;
  /* Card Background */

  --text-main: #f2f2f7;
  /* Off-white for readability */
  --text-muted: #aeaeb2;
  /* Muted gray text */

  --primary: #f97316;
  /* Orange 500 */
  --primary-glow: rgba(249, 115, 22, 0.25);
  --accent: #ea580c;
  /* Orange 600 */

  --danger: #ff453a;
  /* Refined Red */
  --success: #30d158;
  /* Refined Green */

  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 12px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 25px var(--primary-glow);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-main);
  font-weight: 600;
  line-height: 1.5;
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* Layout */
.app-container {
  display: flex;
  width: 100%;
  height: 100%;
}

.sidebar {
  width: 260px;
  background-color: var(--bg-panel);
  /* border-right: 1px solid var(--bg-card); Removed for cleaner dark look */
  padding: 2rem;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
  position: relative;
}

/* Typography */
h1,
h2,
h3 {
  font-weight: 700;
  letter-spacing: -0.025em;
}

h1 {
  font-size: 2rem;
  margin-bottom: 1rem;
  background: linear-gradient(to right, var(--text-main), var(--text-muted));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* UI Elements */
button {
  cursor: pointer;
  border: none;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 0.75rem;
}

.btn-ghost:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
}

input,
select,
textarea {
  width: 100%;
  padding: 0.75rem;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  color: var(--text-main);
  margin-bottom: 1rem;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  background-color: rgba(255, 255, 255, 0.1);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.1);
}

/* Cards & Lists */
.card {
  background-color: var(--bg-panel);
  border: 1px solid var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  transition: transform 0.2s;
}

.card:hover {
  border-color: var(--primary);
}

.grid-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

/* Navigation */
.nav-links {
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary);
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo span {
  color: var(--primary);
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

.hidden {
  display: none !important;
}

/* Invoice Specifics */
.invoice-builder {
  max-width: 800px;
  margin: 0 auto;
}

.line-item-row {
  display: grid;
  grid-template-columns: 3fr 1fr 1fr 0.5fr;
  gap: 1rem;
  align-items: center;
}

/* Mobile & PWA Enhancements */
.mobile-top-bar {
  display: none !important;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  z-index: 1000;
  /* Extremely high to stay above everything */
}

.mobile-logo {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mobile-logo span {
  color: var(--primary);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1500;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-backdrop.active {
  display: block;
  opacity: 1;
}

@media (max-width: 900px) {
  body {
    flex-direction: column;
    overflow-x: hidden;
  }

  .mobile-top-bar {
    display: flex !important;
  }

  .sidebar {
    position: fixed !important;
    top: 0;
    left: -280px;
    bottom: 0;
    z-index: 2000;
    width: 280px;
    height: 100vh;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  }

  .sidebar.active {
    transform: translateX(280px);
  }

  .main-content {
    margin-top: 60px;
    padding: 1.5rem;
    overflow-y: visible;
  }

  .grid-list {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.5rem;
  }

  .line-item-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius);
    margin-bottom: 1rem;
  }

  .line-item-row>div:last-child {
    justify-self: end;
  }

  /* Settings Page Grid */
  #settings-form>div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Product Form Grid */
  #product-form>div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Customer Form Grid */
  #customer-form>div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Invoice Builder Header Grid */
  .invoice-builder .card>div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }
}

/* Fix for iOS momentum scrolling */
.main-content {
  -webkit-overflow-scrolling: touch;
}

/* Hide scrollbars for a cleaner app look */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-card);
  border-radius: 10px;
}