/* PayGfad ERP - Styles v2.0 Multi-tenant */
:root {
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-light: #d1fae5;
  --secondary: #1e293b;
  --accent: #f59e0b;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --white: #ffffff;
  --sidebar-w: 260px;
  --header-h: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
}

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

/* ============================================================
   SPLASH SCREEN
   ============================================================ */
.splash-screen {
  position: fixed; inset: 0; background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 50%, #a7f3d0 100%);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
  transition: opacity .4s ease;
}
.splash-screen.hidden { opacity: 0; pointer-events: none; }
.splash-content { text-align: center; }
.splash-logo { height: 80px; width: 80px; border-radius: 20px; object-fit: cover; box-shadow: var(--shadow-lg); margin-bottom: 1.5rem; }
.splash-title { font-size: 2rem; font-weight: 800; color: var(--secondary); margin-bottom: .25rem; }
.splash-title span { color: var(--primary); }
.splash-subtitle { color: var(--text-muted); margin-bottom: 2rem; font-size: .9rem; }
.splash-loader { display: flex; gap: .5rem; justify-content: center; }
.loader-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); animation: bounce .6s infinite alternate; }
.loader-dot:nth-child(2) { animation-delay: .2s; }
.loader-dot:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { to { transform: translateY(-10px); opacity: .5; } }

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

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-w); min-height: 100vh; background: var(--secondary);
  display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 100; transition: transform .3s ease;
  box-shadow: 2px 0 20px rgba(0,0,0,.15);
}
.sidebar-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; }
.sidebar-logo { height: 36px; width: 36px; border-radius: 8px; object-fit: cover; }
.sidebar-brand-text { color: white; }
.sidebar-brand-name { font-size: 1.1rem; font-weight: 700; display: block; }
.sidebar-brand-module { font-size: .7rem; color: var(--primary); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-company { padding: .75rem 1.5rem; background: rgba(255,255,255,.05); border-bottom: 1px solid rgba(255,255,255,.08); }
.company-badge { display: flex; align-items: center; gap: .5rem; }
.company-avatar { width: 28px; height: 28px; border-radius: 6px; background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 700; color: white; flex-shrink: 0; }
.company-name { font-size: .8rem; color: rgba(255,255,255,.8); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-plan { font-size: .65rem; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0; }
.nav-section { margin-bottom: .5rem; }
.nav-section-title { font-size: .65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.35); padding: .5rem 1.5rem; margin-bottom: .25rem; }
.nav-item { display: flex; align-items: center; gap: .75rem; padding: .65rem 1.5rem; color: rgba(255,255,255,.65); cursor: pointer; transition: all .2s; font-size: .875rem; border-left: 3px solid transparent; }
.nav-item:hover { color: white; background: rgba(255,255,255,.08); border-left-color: rgba(255,255,255,.2); }
.nav-item.active { color: var(--primary); background: rgba(16,185,129,.12); border-left-color: var(--primary); font-weight: 600; }
.nav-item i { width: 18px; text-align: center; font-size: .9rem; }

.sidebar-footer { padding: 1rem 1.5rem; border-top: 1px solid rgba(255,255,255,.08); }
.user-info { display: flex; align-items: center; gap: .75rem; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: .875rem; font-weight: 700; color: white; flex-shrink: 0; }
.user-details { flex: 1; min-width: 0; }
.user-name { font-size: .8rem; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: rgba(255,255,255,.5); text-transform: capitalize; }
.logout-btn { background: none; border: none; color: rgba(255,255,255,.5); cursor: pointer; padding: .25rem; border-radius: 4px; transition: color .2s; }
.logout-btn:hover { color: var(--danger); }

/* MAIN CONTENT */
.main-content { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }

/* HEADER */
.top-header {
  height: var(--header-h); background: white; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 1rem; }
.page-title { font-size: 1.25rem; font-weight: 700; color: var(--secondary); }
.breadcrumb { font-size: .8rem; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: .75rem; }
.header-btn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; cursor: pointer; font-size: .875rem; color: var(--text-muted); transition: all .2s; display: flex; align-items: center; gap: .5rem; }
.header-btn:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.alert-badge { background: var(--danger); color: white; font-size: .65rem; font-weight: 700; padding: .1rem .35rem; border-radius: 999px; }

/* PAGE CONTENT */
.page-content { flex: 1; padding: 1.5rem; }

/* ============================================================
   CARDS
   ============================================================ */
.card { background: white; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 1rem; font-weight: 600; color: var(--secondary); }
.card-body { padding: 1.25rem; }
.card-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border); background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); }

/* ============================================================
   KPI GRID
   ============================================================ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: white; border-radius: var(--radius); padding: 1.25rem; border: 1px solid var(--border); box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 1rem; transition: transform .2s, box-shadow .2s; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.kpi-icon.green { background: #d1fae5; color: var(--primary); }
.kpi-icon.blue { background: #dbeafe; color: var(--info); }
.kpi-icon.yellow { background: #fef3c7; color: var(--warning); }
.kpi-icon.red { background: #fee2e2; color: var(--danger); }
.kpi-icon.purple { background: #ede9fe; color: #7c3aed; }
.kpi-info { flex: 1; }
.kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--secondary); line-height: 1; }
.kpi-label { font-size: .8rem; color: var(--text-muted); margin-top: .25rem; }
.kpi-delta { font-size: .75rem; font-weight: 600; margin-top: .5rem; }
.kpi-delta.up { color: var(--primary); }
.kpi-delta.down { color: var(--danger); }

/* ============================================================
   TABLES
   ============================================================ */
.table-container { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th { padding: .75rem 1rem; text-align: left; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); background: var(--bg); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: .875rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background: #f8fafc; }
.data-table tr:last-child td { border-bottom: none; }

/* ============================================================
   BADGES & STATUS
   ============================================================ */
.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .25rem .625rem; border-radius: 999px; font-size: .7rem; font-weight: 600; white-space: nowrap; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn { display: inline-flex; align-items: center; gap: .5rem; padding: .5rem 1rem; border-radius: 8px; font-size: .875rem; font-weight: 500; cursor: pointer; transition: all .2s; border: none; white-space: nowrap; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: var(--warning); color: white; }
.btn-sm { padding: .375rem .75rem; font-size: .8rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: 6px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .875rem; font-weight: 500; color: var(--text); margin-bottom: .375rem; }
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-control { width: 100%; padding: .625rem .875rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: .875rem; color: var(--text); background: white; transition: border-color .2s, box-shadow .2s; outline: none; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(16,185,129,.1); }
.form-control:disabled { background: var(--bg); color: var(--text-muted); }
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .75rem center; background-size: 1rem; padding-right: 2.5rem; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.form-error { font-size: .75rem; color: var(--danger); margin-top: .25rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; opacity: 0; visibility: hidden; transition: all .2s; }
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal { background: white; border-radius: 16px; width: 100%; max-width: 540px; max-height: 90vh; display: flex; flex-direction: column; transform: scale(.95); transition: transform .2s; box-shadow: var(--shadow-lg); }
.modal-overlay.open .modal { transform: scale(1); }
.modal-lg { max-width: 780px; }
.modal-xl { max-width: 1000px; }
.modal-header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 1.1rem; font-weight: 700; color: var(--secondary); }
.modal-close { background: none; border: none; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; color: var(--text-muted); font-size: 1.1rem; display: flex; align-items: center; justify-content: center; transition: all .2s; }
.modal-close:hover { background: var(--bg); color: var(--danger); }
.modal-body { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: .75rem; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page { min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.login-card { background: white; border-radius: 20px; padding: 2.5rem; width: 100%; max-width: 420px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; align-items: center; gap: .75rem; margin-bottom: 2rem; }
.login-logo img { height: 44px; width: 44px; border-radius: 10px; object-fit: cover; }
.login-brand { font-size: 1.25rem; font-weight: 800; color: var(--secondary); }
.login-brand span { color: var(--primary); }
.login-title { font-size: 1.5rem; font-weight: 700; color: var(--secondary); margin-bottom: .5rem; }
.login-subtitle { font-size: .875rem; color: var(--text-muted); margin-bottom: 2rem; }
.login-error { background: #fee2e2; border: 1px solid #fecaca; color: #991b1b; padding: .75rem 1rem; border-radius: 8px; font-size: .875rem; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.login-btn { width: 100%; padding: .875rem; background: var(--primary); color: white; border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background .2s; margin-top: .5rem; }
.login-btn:hover { background: var(--primary-dark); }
.login-btn:disabled { opacity: .7; cursor: not-allowed; }
.login-footer { text-align: center; margin-top: 1.5rem; font-size: .8rem; color: var(--text-muted); }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-icon { font-size: 3rem; color: var(--border); margin-bottom: 1rem; }
.empty-title { font-size: 1rem; font-weight: 600; color: var(--text-muted); margin-bottom: .5rem; }
.empty-text { font-size: .875rem; color: var(--text-muted); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert { display: flex; align-items: flex-start; gap: .75rem; padding: .875rem 1rem; border-radius: 8px; font-size: .875rem; margin-bottom: 1rem; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ============================================================
   SEARCH & FILTERS
   ============================================================ */
.toolbar { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 200px; }
.search-box input { padding-left: 2.5rem; }
.search-icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: .9rem; pointer-events: none; }

/* ============================================================
   CHARTS
   ============================================================ */
.chart-container { position: relative; }

/* ============================================================
   SUPERADMIN SPECIFIC
   ============================================================ */
.superadmin-badge { background: linear-gradient(135deg, #7c3aed, #4f46e5); color: white; font-size: .7rem; padding: .2rem .5rem; border-radius: 999px; font-weight: 700; }
.company-card { background: white; border-radius: var(--radius); border: 1px solid var(--border); padding: 1.25rem; cursor: pointer; transition: all .2s; }
.company-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.company-card.active { border-color: var(--primary); background: var(--primary-light); }

/* ============================================================
   INVOICE SPECIFIC
   ============================================================ */
.invoice-status-draft { background: #f1f5f9; color: #475569; }
.invoice-status-sent { background: #dbeafe; color: #1e40af; }
.invoice-status-paid { background: #d1fae5; color: #065f46; }
.invoice-status-overdue { background: #fee2e2; color: #991b1b; }
.invoice-status-cancelled { background: #f1f5f9; color: #94a3b8; }

/* ============================================================
   STOCK INDICATOR
   ============================================================ */
.stock-level { display: flex; align-items: center; gap: .5rem; }
.stock-bar { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.stock-fill { height: 100%; border-radius: 3px; transition: width .3s; }
.stock-fill.high { background: var(--primary); }
.stock-fill.medium { background: var(--warning); }
.stock-fill.low { background: var(--danger); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .modal { max-height: 95vh; }
  .page-content { padding: 1rem; }
}

/* ============================================================
   UTILITIES
   ============================================================ */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.separator { height: 1px; background: var(--border); margin: 1.5rem 0; }

/* Loading spinner */
.spinner { width: 20px; height: 20px; border: 2px solid rgba(16,185,129,.2); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast notifications */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--secondary); color: white; padding: .875rem 1.25rem; border-radius: 10px; font-size: .875rem; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: .75rem; max-width: 360px; animation: slideIn .3s ease; }
.toast.success { background: var(--primary); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Number formatting */
.currency { font-variant-numeric: tabular-nums; }
