/**
 * SVK Accounting ERP - المحاسب الشامل A-Plus Pro
 * Corporate Financial Styling & High-Contrast Design System
 */

:root {
  --primary: #0f2b48;
  --primary-hover: #163e68;
  --primary-light: #e0f2fe;
  --accent: #10b981;
  --accent-hover: #059669;
  --gold: #f59e0b;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #0284c7;
  --sidebar-bg: #0b192c;
  --sidebar-hover: #1e3e62;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #ffffff;
  --font-base: 'Segoe UI', Tahoma, Cairo, Arial, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-base);
  background: #f1f5f9;
  color: var(--text-main);
  direction: rtl;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Layout */
.app-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - 46px);
}

/* Sidebar */
.sidebar {
  width: 270px;
  background: var(--sidebar-bg);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-left: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand {
  padding: 22px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.brand-icon {
  font-size: 28px;
  background: linear-gradient(135deg, #10b981, #0284c7);
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 10px rgba(16,185,129,0.3);
}

.brand-title h2 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: #fff;
}

.brand-title span {
  font-size: 11px;
  color: #94a3b8;
  display: block;
}

.sidebar-menu {
  flex: 1;
  padding: 16px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-header {
  font-size: 11px;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  padding: 10px 12px 4px 12px;
  letter-spacing: 0.5px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: transparent;
  color: #cbd5e1;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  text-align: right;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
}

.nav-btn:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.nav-btn.active {
  background: linear-gradient(90deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16,185,129,0.35);
}

.nav-btn .icon {
  font-size: 18px;
  width: 22px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  background: rgba(0,0,0,0.25);
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 11.5px;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
}

/* Header */
.top-header {
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.page-title h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-title p {
  font-size: 12.5px;
  color: var(--text-muted);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* License Pill */
.license-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s ease;
}

.license-pill.trial {
  background: #fef3c7;
  border-color: #fde047;
  color: #854d0e;
}

.license-pill.pro {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}

.license-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.license-btn-act {
  background: var(--gold);
  color: #fff;
  border: none;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

/* Button styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}
.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-warning {
  background: var(--gold);
  color: #fff;
}
.btn-warning:hover {
  background: #d97706;
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-main);
  border-color: var(--surface-border);
}
.btn-ghost:hover {
  background: #f1f5f9;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Content View */
.view-container {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
}

.view-section {
  display: none;
}
.view-section.active {
  display: block;
}

/* Metric KPI Cards Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
}
.kpi-card.blue::after { background: #0284c7; }
.kpi-card.green::after { background: #10b981; }
.kpi-card.gold::after { background: #f59e0b; }
.kpi-card.red::after { background: #ef4444; }

.kpi-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.kpi-val {
  font-size: 24px;
  font-weight: 900;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.kpi-sub {
  font-size: 11.5px;
  color: #10b981;
  margin-top: 4px;
  font-weight: 700;
}

.kpi-icon {
  font-size: 28px;
  background: var(--surface-alt);
  padding: 10px;
  border-radius: var(--radius-sm);
}

/* Dashboard Quick Shortcut Row */
.quick-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.quick-tile {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--primary);
}

.quick-tile:hover {
  transform: translateY(-2px);
  border-color: #10b981;
  box-shadow: var(--shadow-md);
  color: #059669;
}

.quick-tile .icon {
  font-size: 26px;
}

/* Panels & Cards */
.panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--surface-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h3 {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-body {
  padding: 20px;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: var(--surface-alt);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-border);
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.filter-group label {
  color: var(--text-muted);
}

.form-control, select, input[type="text"], input[type="date"], input[type="number"], textarea {
  padding: 8px 12px;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-control:focus, select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(15,43,72,0.15);
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: #f1f5f9;
  color: #334155;
  font-weight: 800;
  padding: 12px 14px;
  text-align: right;
  border-bottom: 2px solid #cbd5e1;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface-border);
  color: var(--text-main);
}

.data-table tr:hover {
  background: #f8fafc;
}

.data-table tfoot td {
  background: #f8fafc;
  font-weight: 800;
  border-top: 2px solid #cbd5e1;
  border-bottom: 2px solid #cbd5e1;
}

.text-center { text-align: center !important; }
.text-left { text-align: left !important; }
.text-right { text-align: right !important; }
.text-bold { font-weight: 800; }
.text-green { color: #10b981 !important; }
.text-red { color: #ef4444 !important; }
.text-blue { color: #0284c7 !important; }
.amount { font-family: 'Consolas', monospace; font-size: 13.5px; font-weight: 700; direction: ltr; font-variant-numeric: tabular-nums; }
.amount:not(td):not(th) { display: inline-block; }
td.amount, th.amount { display: table-cell; unicode-bidi: embed; white-space: nowrap; }

/* Tree View for Chart of Accounts */
.accounts-tree {
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
}

.tree-node {
  border-bottom: 1px solid var(--surface-border);
}

.tree-node-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.tree-node-row:hover {
  background: #f1f5f9;
}

.tree-node-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 14px;
}

.tree-code {
  font-family: 'Consolas', monospace;
  background: #e2e8f0;
  color: #0f172a;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
}

.tree-balance {
  font-family: 'Consolas', monospace;
  font-weight: 800;
  font-size: 13.5px;
}

.tree-children {
  padding-right: 28px;
  background: #fbfcfe;
  border-top: 1px dashed var(--surface-border);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: #fff;
  width: 100%;
  max-width: 800px;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 40px rgba(0,0,0,0.25);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.96); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 16px 20px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 800;
}

.btn-close-modal {
  background: transparent;
  color: #cbd5e1;
  border: none;
  font-size: 20px;
  cursor: pointer;
}
.btn-close-modal:hover { color: #fff; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 20px;
  background: var(--surface-alt);
  border-top: 1px solid var(--surface-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Form Grid */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 700;
  color: #334155;
}

/* Journal Entry Lines Table inside modal */
.entry-lines-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
}

.entry-lines-table th {
  background: #f1f5f9;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--surface-border);
}

.entry-lines-table td {
  padding: 6px 8px;
  border: 1px solid var(--surface-border);
}

.entry-lines-table input, .entry-lines-table select {
  width: 100%;
  padding: 6px 8px;
  font-size: 12.5px;
}

.entry-balance-indicator {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-top: 12px;
  font-weight: 800;
  font-size: 13.5px;
}

.entry-balance-indicator.balanced {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.entry-balance-indicator.unbalanced {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* Financial Statement Statement View (Income / Balance Sheet) */
.statement-sheet {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  padding: 30px;
  max-width: 900px;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
}

.statement-title-block {
  text-align: center;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.statement-title-block h2 {
  font-size: 22px;
  font-weight: 900;
  color: var(--primary);
}

.statement-title-block p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.statement-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}

.statement-row.header-row {
  background: #f8fafc;
  font-weight: 900;
  color: var(--primary);
  font-size: 15px;
  margin-top: 14px;
  border-top: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
}

.statement-row.total-row {
  background: #f1f5f9;
  font-weight: 900;
  font-size: 16px;
  border-top: 2px solid #334155;
  border-bottom: 2px double #334155;
  margin-top: 8px;
  margin-bottom: 16px;
}

.statement-row.grand-total {
  background: #e0f2fe;
  color: #0369a1;
  font-weight: 900;
  font-size: 18px;
  border-top: 2px solid #0284c7;
  border-bottom: 3px double #0284c7;
  margin-top: 16px;
}

/* Ratios Grid */
.ratios-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.ratio-card {
  background: #fff;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.ratio-card h4 {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  border-bottom: 2px solid #f1f5f9;
  padding-bottom: 10px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ratio-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--surface-border);
  font-size: 13.5px;
}

.ratio-val {
  font-family: 'Consolas', monospace;
  font-weight: 900;
  font-size: 15px;
}

/* Print Only */
@media print {
  body { background: #fff !important; }
  .sidebar, .top-header, .demo-live-banner, .filter-bar, .header-controls, .btn, .no-print { display: none !important; }
  .app-layout { display: block !important; }
  .main-wrapper { margin: 0 !important; width: 100% !important; }
  .view-container { padding: 0 !important; }
  .statement-sheet { box-shadow: none !important; border: none !important; width: 100% !important; max-width: 100% !important; padding: 0 !important; }
}
