/* =============================================
   Backoffice CRM v2 — Modern Design
   Clean, professional, multi-language ready
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Core palette */
  --bg-page:      #f8fafc;
  --bg-sidebar:   #0f172a;
  --bg-card:      #ffffff;
  --bg-input:     #f1f5f9;
  --bg-hover:     #f8fafc;
  
  /* Borders */
  --border:       #e2e8f0;
  --border-light: #f1f5f9;
  --border-dark:  #cbd5e1;
  
  /* Text */
  --text:         #0f172a;
  --text-secondary: #64748b;
  --text-muted:   #94a3b8;
  --text-inverse: #f8fafc;
  
  /* Accent colors */
  --primary:      #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  
  --success:      #10b981;
  --success-light: #d1fae5;
  
  --warning:      #f59e0b;
  --warning-light: #fef3c7;
  
  --danger:       #ef4444;
  --danger-light: #fee2e2;
  
  --info:         #3b82f6;
  --info-light:   #dbeafe;
  
  /* Sidebar specific */
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: rgba(99,102,241,0.2);
  --sidebar-text: #94a3b8;
  --sidebar-text-active: #ffffff;
  
  /* Sizing */
  --sidebar-width: 260px;
  --radius-sm:    6px;
  --radius:       10px;
  --radius-lg:    16px;
  
  /* Shadows */
  --shadow-sm:    0 1px 2px rgba(0,0,0,0.04);
  --shadow:       0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg:    0 10px 25px rgba(0,0,0,0.08);
  
  /* Transitions */
  --transition:   0.15s ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-page);
  color: var(--text);
  line-height: 1.6;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* =============================================
   LAYOUT
   ============================================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-logo-icon svg {
  width: 20px;
  height: 20px;
  color: white;
}

.sidebar-logo-text {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-inverse);
  letter-spacing: -0.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-section-title {
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--sidebar-text);
  opacity: 0.6;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
}

.nav-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.nav-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-active);
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-link.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--primary);
  color: white;
  border-radius: 10px;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.sidebar-user:hover {
  background: var(--sidebar-hover);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: white;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-inverse);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--sidebar-text);
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

/* Top bar */
.topbar {
  height: 64px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Language selector */
.lang-select {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}

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

.lang-select select {
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  cursor: pointer;
  outline: none;
}

/* Page wrapper */
.page-wrapper {
  padding: 32px;
}

/* =============================================
   COMPONENTS
   ============================================= */

/* ---- Page Header ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.page-header-actions {
  display: flex;
  gap: 10px;
}

/* Breadcrumbs */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.breadcrumbs a { color: var(--text-secondary); }
.breadcrumbs a:hover { color: var(--primary); }
.breadcrumbs span { color: var(--text-muted); }

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.card-body {
  padding: 24px;
}

.card-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-input);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 24px;
  height: 24px;
}

.stat-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-icon.success { background: var(--success-light); color: var(--success); }
.stat-icon.warning { background: var(--warning-light); color: var(--warning); }
.stat-icon.danger  { background: var(--danger-light);  color: var(--danger); }
.stat-icon.info    { background: var(--info-light);    color: var(--info); }

.stat-content { flex: 1; }

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -1px;
  line-height: 1.2;
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  padding: 2px 8px;
  border-radius: 10px;
}

.stat-change.up { background: var(--success-light); color: var(--success); }
.stat-change.down { background: var(--danger-light); color: var(--danger); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-dark);
  color: white;
}

.btn-secondary {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-dark);
}

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

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-lg {
  padding: 14px 28px;
  font-size: 15px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

.btn-icon.sm {
  width: 28px;
  height: 28px;
}

/* ---- Tables ---- */
.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 14px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

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

tbody tr:hover {
  background: var(--bg-hover);
}

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 20px;
  text-transform: capitalize;
}

.badge-pending    { background: var(--warning-light); color: var(--warning); }
.badge-awaiting_payment { background: var(--info-light); color: var(--info); }
.badge-paid       { background: var(--success-light); color: var(--success); }
.badge-processing { background: var(--primary-light); color: var(--primary); }
.badge-completed  { background: var(--success-light); color: var(--success); }
.badge-cancelled  { background: var(--danger-light);  color: var(--danger); }
.badge-refunded   { background: #fae8ff; color: #a855f7; }

.badge-approved   { background: var(--success-light); color: var(--success); }
.badge-rejected   { background: var(--danger-light);  color: var(--danger); }

.badge-one_time   { background: var(--bg-input); color: var(--text-secondary); }
.badge-monthly    { background: var(--primary-light); color: var(--primary); }
.badge-quarterly  { background: var(--info-light); color: var(--info); }
.badge-yearly     { background: var(--success-light); color: var(--success); }

.badge-admin      { background: var(--primary-light); color: var(--primary); }
.badge-manager    { background: var(--info-light); color: var(--info); }
.badge-viewer     { background: var(--bg-input); color: var(--text-secondary); }

/* ---- Forms ---- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-group {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group label .required {
  color: var(--danger);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-muted);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.form-group input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.form-help {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* ---- Alerts ---- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 24px;
}

.alert svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-success {
  background: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-error {
  background: var(--danger-light);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-warning {
  background: var(--warning-light);
  color: #92400e;
  border: 1px solid #fde68a;
}

.alert-info {
  background: var(--info-light);
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 60px 24px;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--bg-input);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state-icon svg {
  width: 28px;
  height: 28px;
  color: var(--text-muted);
}

.empty-state-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.empty-state-text {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ---- Detail View ---- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}

.detail-section {
  margin-bottom: 24px;
}

.detail-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.detail-row:last-child {
  border-bottom: none;
}

.detail-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: right;
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: var(--transition);
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ---- Feature List ---- */
.feature-list {
  list-style: none;
}

.feature-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 14px;
}

.feature-item:last-child {
  border-bottom: none;
}

.feature-check {
  width: 22px;
  height: 22px;
  background: var(--success-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.feature-check svg {
  width: 12px;
  height: 12px;
  color: var(--success);
}

/* ---- Actions Cell ---- */
.actions-cell {
  display: flex;
  gap: 6px;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 20px 0;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
}

.pagination a:hover {
  background: var(--bg-input);
  color: var(--text);
}

.pagination .active {
  background: var(--primary);
  color: white;
}

.pagination .disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ---- Settings Sections ---- */
.settings-section {
  margin-bottom: 32px;
}

.settings-section-header {
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.settings-section-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---- Login Page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  padding: 24px;
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  padding: 40px;
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.login-logo svg {
  width: 28px;
  height: 28px;
  color: white;
}

.login-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
}

.login-form .form-group {
  margin-bottom: 20px;
}

.login-form .btn {
  width: 100%;
  margin-top: 8px;
}

.login-footer {
  text-align: center;
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* ---- Receipt / Invoice Print ---- */
@media print {
  body { background: white; }
  .sidebar, .topbar, .no-print { display: none !important; }
  .main-content { margin-left: 0; }
  .page-wrapper { padding: 0; }
  .card { box-shadow: none; border: none; }
}

/* ---- File Input ---- */
input[type="file"] {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

input[type="file"]:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

input[type="file"]:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---- Code/Pre ---- */
pre {
  font-family: 'JetBrains Mono', monospace;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .page-wrapper {
    padding: 20px;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .topbar {
    padding: 0 20px;
  }
}
