/* ==========================================================================
   Mahdiyyah Book Portal Design System: Premium Glassmorphism & Dark Mode
   ========================================================================== */

:root {
  /* Curated Harmonious Palette: Clean White & Emerald Green Light Mode */
  --bg-app: #f8fafc; /* Very light slate gray */
  --bg-glass: rgba(255, 255, 255, 0.85); /* Frosted pure white */
  --bg-glass-hover: rgba(255, 255, 255, 0.95);
  --border-glass: rgba(16, 185, 129, 0.1); /* Soft emerald border tint */
  --border-glass-focus: rgba(16, 185, 129, 0.4);
  
  --primary: #059669; /* Rich Emerald Green */
  --primary-hover: #047857;
  --primary-glow: rgba(5, 150, 105, 0.12);
  
  --success: #10b981; /* Bright Emerald */
  --success-glow: rgba(16, 185, 129, 0.15);
  --warning: #d97706; /* Amber-600 for contrast */
  --danger: #dc2626; /* Red-600 */
  --info: #0284c7; /* Sky-600 */
  
  --text-main: #0f172a; /* Dark slate-900 */
  --text-muted: #475569; /* Slate-600 */
  --text-dim: #64748b; /* Slate-500 */
  
  --sidebar-width: 260px;
  --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-premium: 0 10px 30px -15px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  
  --font-family: 'Plus Jakarta Sans', 'Outfit', system-ui, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  overflow-x: hidden;
  height: 100vh;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
  background: var(--border-glass);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* Glassmorphism Utility */
.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  box-shadow: var(--shadow-premium);
}

/* App Container Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: radial-gradient(circle at 80% 20%, #ecfdf5 0%, #f8fafc 70%);
}

/* Sidebar Navigation */
.sidebar {
  width: var(--sidebar-width);
  background: rgba(255, 255, 255, 0.95);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
}

.sidebar-brand {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  background: linear-gradient(135deg, var(--primary), var(--info));
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.brand-logo i {
  color: #fff;
  width: 20px;
  height: 20px;
}

.brand-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: 0.5px;
  background: linear-gradient(to right, #0f172a, #059669);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-menu {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-grow: 1;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: var(--transition-smooth);
}

.menu-item i {
  width: 20px;
  height: 20px;
}

.menu-item:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

.menu-item.active {
  color: var(--primary);
  background: linear-gradient(135deg, rgba(5, 150, 105, 0.12) 0%, rgba(5, 150, 105, 0.04) 100%);
  border-left: 3px solid var(--primary);
  box-shadow: none;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--border-glass);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Main Content Area */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
}

/* Top Header Bar */
.top-header {
  padding: 20px 40px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(10px);
}

#view-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  border: 2px solid var(--border-glass);
}

.profile-info {
  display: flex;
  flex-direction: column;
}

.profile-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.profile-role {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* View Panel and Sections */
.view-panel {
  padding: 30px 40px;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.view-section {
  display: none;
  animation: fadeIn 0.4s ease;
  flex-grow: 1;
}

.view-section.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Dashboard KPIs */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.metric-card {
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  transition: var(--transition-smooth);
}

.metric-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-glass-focus);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.metric-icon i {
  width: 24px;
  height: 24px;
}

.metric-icon.blue { background: rgba(56, 189, 248, 0.1); color: var(--info); }
.metric-icon.purple { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.metric-icon.green { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.metric-icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning); }

.metric-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.metric-details h3 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

/* Charts Grid */
.charts-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 20px;
  margin-bottom: 30px;
}

@media (max-width: 1024px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.dashboard-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 10px;
}

@media (max-width: 1024px) {
  .dashboard-bottom-grid {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  padding: 24px;
}

.chart-card h4 {
  margin-bottom: 20px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
}

.chart-container {
  position: relative;
  height: 280px;
  width: 100%;
}

/* Action Bars */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 20px;
}

.search-box {
  position: relative;
  max-width: 400px;
  width: 100%;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  width: 18px;
  height: 18px;
}

.search-box input {
  width: 100%;
  padding: 11px 16px 11px 44px;
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-smooth);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* Premium Form Elements */
.form-group {
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border-glass);
  border-radius: 10px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-smooth);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

textarea.form-control {
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-help {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

.btn-large {
  width: 100%;
  padding: 14px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid var(--border-glass);
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-muted);
  transition: var(--transition-smooth);
}

.btn-icon:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.06);
}

.btn-icon.delete:hover {
  color: white;
  background: var(--danger);
  border-color: var(--danger);
}

.btn-text {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
}

.btn-text:hover {
  text-decoration: underline;
}

/* Card Tables */
.table-card {
  padding: 20px;
  margin-top: 10px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.table-container {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  padding: 12px 16px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-glass);
}

td {
  padding: 14px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border-glass);
  color: var(--text-main);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(5, 150, 105, 0.02);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-info { background: rgba(14, 165, 233, 0.15); color: #38bdf8; }

/* POS Billing Terminals */
.billing-grid {
  display: grid;
  grid-template-columns: 7fr 4fr;
  gap: 20px;
  flex-grow: 1;
}

@media (max-width: 900px) {
  .billing-grid {
    grid-template-columns: 1fr;
  }
}

.billing-left-panel, .billing-right-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.billing-header {
  margin-bottom: 16px;
}

.billing-inputs {
  margin-bottom: 20px;
}

.discount-display-container {
  display: flex;
  margin-top: -6px;
}

.customer-discount-tag {
  background: var(--primary-glow);
  color: #c7d2fe;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px dashed var(--border-glass-focus);
}

.divider {
  border: 0;
  height: 1px;
  background: var(--border-glass);
  margin: 16px 0;
}

.billing-book-add-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1.2fr auto;
  gap: 12px;
  align-items: flex-end;
}

.add-item-btn {
  height: 38px;
  margin-bottom: 2px;
}

.cart-table-container {
  margin-top: 10px;
  max-height: 300px;
  overflow-y: auto;
}

.summary-breakdown {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.summary-row.grand-total-row {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  padding: 10px 0;
}

.payment-collection-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.balance-due-display {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.15);
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.balance-due-display span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.balance-due-display strong {
  font-size: 1.15rem;
  color: var(--danger);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.3s ease;
}

.modal {
  width: 90%;
  max-width: 520px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  animation: modalScaleUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal.small-modal {
  max-width: 400px;
}

.modal.medium-modal {
  max-width: 700px;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalScaleUp {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h4 {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-smooth);
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.payment-target-info {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
}

.danger-text {
  color: var(--danger);
}

/* Settings Forms */
.settings-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

@media (max-width: 800px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

.settings-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-card h4 {
  font-size: 1.05rem;
  font-weight: 600;
  border-bottom: 1px solid var(--border-glass);
  padding-bottom: 10px;
}

/* Toast System */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}

.toast {
  padding: 12px 20px;
  border-radius: 10px;
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 250px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  animation: slideInRight 0.3s cubic-bezier(0.68, -0.6, 0.32, 1.6);
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-success { background: #065f46; border-left: 4px solid var(--success); }
.toast-error { background: #991b1b; border-left: 4px solid var(--danger); }
.toast-info { background: #075985; border-left: 4px solid var(--info); }

/* Responsive Mobile Adjustments */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.98);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.15);
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  #btn-sidebar-close {
    display: flex !important;
  }
  
  #btn-sidebar-toggle {
    display: flex !important;
  }
  
  .top-header {
    padding: 15px 20px;
  }
  
  .view-panel {
    padding: 15px 20px;
  }
  
  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 20px;
  }
  
  .charts-grid {
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 20px;
  }
  
  .dashboard-bottom-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .billing-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .settings-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .form-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .action-bar {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px;
  }
  
  .search-box {
    max-width: 100%;
  }
}
