/* ============================================
   BookKeeper - Simple Bookkeeping Application
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --accent: #10b981;
  --accent-light: #34d399;
  --accent-dark: #059669;
  --danger: #ef4444;
  --danger-light: #fca5a5;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-header: #1e40af;
  --text: #1e293b;
  --text-light: #64748b;
  --text-white: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: all 0.2s ease;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --max-width: 1200px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---------- RTL Support ---------- */
[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .transaction-amount {
  direction: ltr;
}

[dir="rtl"] .kpi-value {
  direction: ltr;
}

/* ---------- Typography ---------- */
h1, h2, h3, h4 {
  line-height: 1.3;
  font-weight: 600;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

/* ---------- Header / Nav ---------- */
.header {
  background: var(--bg-header);
  color: var(--text-white);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-white);
  text-decoration: none;
}

.logo img {
  width: 32px;
  height: 32px;
}

.nav-tabs {
  display: flex;
  gap: 0.25rem;
}

.nav-tab {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius);
  transition: var(--transition);
  font-family: var(--font);
}

.nav-tab:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-white);
}

.nav-tab.active {
  background: rgba(255,255,255,0.2);
  color: var(--text-white);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ---------- Profile / Administration Switcher ---------- */
.profile-switcher {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.profile-select {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--text-white);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  max-width: 160px;
}

.profile-select option {
  background: var(--bg-card);
  color: var(--text);
  font-weight: normal;
}

.btn-icon {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  color: var(--text-white);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.32);
}

.profile-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  background: var(--bg);
}

.profile-list-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.profile-list-title {
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.profile-list-meta {
  font-size: 0.75rem;
  color: var(--text-light);
}

.profile-list-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.profile-badge-active {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  border-radius: 9999px;
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.notice-box {
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  font-size: 0.8rem;
  color: var(--text);
  margin-top: 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

/* ---------- Language Selector ---------- */
.lang-select {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--text-white);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font);
  max-width: 140px;
}

.lang-select option {
  background: var(--bg-card);
  color: var(--text);
}

/* ---------- Currency Selector ---------- */
.currency-select {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: var(--text-white);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font);
  max-width: 90px;
}

.currency-select option {
  background: var(--bg-card);
  color: var(--text);
}

/* ---------- Main Content ---------- */
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

/* ---------- Tab Content ---------- */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

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

/* ---------- KPI Cards ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
  transition: var(--transition);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.kpi-card.income {
  border-left-color: var(--accent);
}

.kpi-card.expense {
  border-left-color: var(--danger);
}

.kpi-card.balance {
  border-left-color: var(--primary);
}

[dir="rtl"] .kpi-card {
  border-left: none;
  border-right: 4px solid var(--primary);
}
[dir="rtl"] .kpi-card.income { border-right-color: var(--accent); }
[dir="rtl"] .kpi-card.expense { border-right-color: var(--danger); }
[dir="rtl"] .kpi-card.balance { border-right-color: var(--primary); }

.kpi-label {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.kpi-value.income { color: var(--accent-dark); }
.kpi-value.expense { color: var(--danger); }
.kpi-value.positive { color: var(--accent-dark); }
.kpi-value.negative { color: var(--danger); }

.kpi-sub {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

/* ---------- Cards / Sections ---------- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

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

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
}

/* ---------- Form Styles ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-select {
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  transition: var(--transition);
  background: var(--bg-card);
  color: var(--text);
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-input::placeholder {
  color: var(--text-light);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  line-height: 1;
}

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

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
}

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

.btn-accent:hover {
  background: var(--accent-dark);
  box-shadow: var(--shadow-md);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  padding: 0.4rem 0.6rem;
}

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

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

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

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

/* ---------- Transaction Type Toggle ---------- */
.type-toggle {
  display: flex;
  gap: 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1.5px solid var(--border);
}

.type-toggle-btn {
  flex: 1;
  padding: 0.6rem 1rem;
  border: none;
  background: var(--bg);
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: var(--transition);
}

.type-toggle-btn.active-income {
  background: var(--accent);
  color: white;
}

.type-toggle-btn.active-expense {
  background: var(--danger);
  color: white;
}

/* ---------- Transaction List ---------- */
.transaction-filters {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  flex: 1;
  min-width: 200px;
}

.filter-select {
  min-width: 140px;
}

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

.transaction-table th {
  text-align: left;
  padding: 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
}

[dir="rtl"] .transaction-table th {
  text-align: right;
}

.transaction-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.transaction-table tr:hover td {
  background: rgba(59,130,246,0.03);
}

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

.amount-income {
  color: var(--accent-dark);
  font-weight: 600;
}

.amount-expense {
  color: var(--danger);
  font-weight: 600;
}

.category-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(59,130,246,0.1);
  color: var(--primary);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.empty-state-text {
  font-size: 1rem;
}

/* ---------- Report Styles ---------- */
.report-period-selector {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.period-btn {
  padding: 0.4rem 1rem;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  color: var(--text);
}

.period-btn.active {
  background: var(--primary);
  color: var(--text-white);
  border-color: var(--primary);
}

.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.report-bar-chart {
  margin-top: 1rem;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.bar-label {
  width: 80px;
  font-size: 0.8rem;
  color: var(--text-light);
  text-align: right;
  flex-shrink: 0;
}

[dir="rtl"] .bar-label {
  text-align: left;
}

.bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
}

.bar-fill-income {
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius) 0 0 var(--radius);
  transition: width 0.5s ease;
  min-width: 0;
}

.bar-fill-expense {
  height: 100%;
  background: var(--danger);
  transition: width 0.5s ease;
  min-width: 0;
}

[dir="rtl"] .bar-fill-income {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.bar-value {
  width: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}

/* ---------- Monthly Detail Table ---------- */
.report-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}

.report-table th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}

[dir="rtl"] .report-table th {
  text-align: right;
}

.report-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.report-table tfoot td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  background: var(--bg);
}

/* ---------- Export Buttons ---------- */
.export-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 500px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* ---------- Footer ---------- */
.footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-light);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

/* ---------- Toast / Notification ---------- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

[dir="rtl"] .toast-container {
  right: auto;
  left: 1.5rem;
}

.toast {
  background: var(--text);
  color: var(--text-white);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
  max-width: 360px;
}

.toast.success {
  background: var(--accent-dark);
}

.toast.error {
  background: var(--danger);
}

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

@keyframes fadeOut {
  to { opacity: 0; transform: translateY(10px); }
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.page-btn {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  color: var(--text);
}

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

.page-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .nav-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .nav-tab {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  .header-actions {
    gap: 0.5rem;
  }

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

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

  .kpi-value {
    font-size: 1.5rem;
  }

  .transaction-table {
    font-size: 0.85rem;
  }

  .transaction-table th:nth-child(4),
  .transaction-table td:nth-child(4) {
    display: none;
  }

  .bar-label {
    width: 50px;
    font-size: 0.7rem;
  }

  .bar-value {
    width: 70px;
    font-size: 0.7rem;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
  }

  .toast {
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .logo span {
    display: none;
  }

  .nav-tab {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
  }

  .main {
    padding: 1rem 0.5rem;
  }

  .card {
    padding: 1rem;
  }
}

/* ---------- Offline Badge ---------- */
.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(245, 158, 11, 0.25);
  border: 1px solid rgba(245, 158, 11, 0.5);
  color: #fef3c7;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.offline-dot {
  width: 8px;
  height: 8px;
  background: #f59e0b;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.8);
  animation: pulseDot 2s infinite ease-in-out;
}

@keyframes pulseDot {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- Print Styles ---------- */
@media print {
  .header, .footer, .nav-tabs, .header-actions,
  .btn, .form-grid, .transaction-filters,
  .modal-overlay, .toast-container {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
    break-inside: avoid;
  }

  .kpi-card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
