/* ============================================================
   Tadawi Healthcare ERP - Billing & Financial Modules CSS
   ============================================================ */

/* ==========================================================
   BILLING MODULE (bill- prefix)
   ========================================================== */

/* ---- Layout ---- */
.bill-container {
  padding: 0;
}

.bill-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.bill-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bill-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

.bill-stat-card {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: all 0.2s ease;
}

.bill-stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.bill-stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #fff;
}

.bill-stat-info {
  flex: 1;
}

.bill-stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text, #1e293b);
}

.bill-stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary, #94a3b8);
}

/* ---- Filter Bar ---- */
.bill-filter-bar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  align-items: center;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1rem;
}

.bill-filter-bar input,
.bill-filter-bar select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  background: var(--card-bg, #fff);
  color: var(--text, #1e293b);
}

.bill-filter-bar input:focus,
.bill-filter-bar select:focus {
  outline: none;
  border-color: var(--primary, #28B8D6);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* ---- Table ---- */
.bill-table-wrap {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

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

.bill-table th {
  padding: 0.75rem 1rem;
  text-align: right;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border, #e2e8f0);
  background: var(--bg-secondary, #f1f5f9);
}

.bill-table td {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.bill-table tr:hover td {
  background: var(--hover-bg, #f8fafc);
}

.bill-table .bill-row-actions {
  display: flex;
  gap: 0.25rem;
}

.bill-table .bill-row-actions button {
  padding: 0.3rem 0.5rem;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 0.375rem;
  color: var(--text-secondary, #94a3b8);
}

.bill-table .bill-row-actions button:hover {
  background: var(--bg-secondary, #f1f5f9);
  color: var(--text, #1e293b);
}

/* ---- Invoice Detail ---- */
.bill-invoice-detail {
  max-width: 900px;
  margin: 0 auto;
}

.bill-invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.bill-invoice-number {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary, #28B8D6);
}

.bill-invoice-meta {
  text-align: left;
}

.bill-invoice-section {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.bill-invoice-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bill-totals {
  display: flex;
  justify-content: flex-end;
}

.bill-totals-table {
  min-width: 300px;
}

.bill-totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.bill-totals-row.bill-grand-total {
  font-size: 1.2rem;
  font-weight: 700;
  border-bottom: none;
  color: var(--primary, #28B8D6);
}

.bill-totals-row .bill-label {
  color: var(--text-secondary, #94a3b8);
}

.bill-totals-row .bill-value {
  font-weight: 600;
}

/* ---- Items Section ---- */
.bill-items-table {
  width: 100%;
  border-collapse: collapse;
}

.bill-items-table th {
  padding: 0.75rem;
  text-align: right;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  background: var(--bg-secondary, #f1f5f9);
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.bill-items-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
  font-size: 0.85rem;
}

.bill-items-add {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.bill-items-add select,
.bill-items-add input {
  padding: 0.5rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.5rem;
  font-size: 0.85rem;
}

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

.bill-modal {
  background: var(--card-bg, #fff);
  border-radius: 0.75rem;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.bill-modal h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bill-modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-secondary, #94a3b8);
}

.bill-form-group {
  margin-bottom: 1rem;
}

.bill-form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text-secondary, #94a3b8);
}

.bill-form-group input,
.bill-form-group select,
.bill-form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  background: var(--card-bg, #fff);
  color: var(--text, #1e293b);
}

.bill-form-group input:focus,
.bill-form-group select:focus,
.bill-form-group textarea:focus {
  outline: none;
  border-color: var(--primary, #28B8D6);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.bill-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.bill-form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ---- Buttons ---- */
.bill-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.bill-btn-primary {
  background: var(--primary, #28B8D6);
  color: #fff;
}

.bill-btn-primary:hover {
  opacity: 0.9;
}

.bill-btn-success {
  background: #22c55e;
  color: #fff;
}

.bill-btn-danger {
  background: #ef4444;
  color: #fff;
}

.bill-btn-outline {
  background: transparent;
  border-color: var(--border, #e2e8f0);
  color: var(--text, #1e293b);
}

.bill-btn-outline:hover {
  background: var(--bg-secondary, #f1f5f9);
}

.bill-btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
}

/* ---- Badges ---- */
.bill-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.bill-badge-draft {
  background: #94a3b815;
  color: #94a3b8;
}

.bill-badge-pending {
  background: #f59e0b15;
  color: #f59e0b;
}

.bill-badge-partially_paid {
  background: #3b82f615;
  color: #3b82f6;
}

.bill-badge-paid {
  background: #22c55e15;
  color: #22c55e;
}

.bill-badge-cancelled {
  background: #ef444415;
  color: #ef4444;
}

.bill-badge-refunded {
  background: #8b5cf615;
  color: #8b5cf6;
}

.bill-badge-void {
  background: #6b728015;
  color: #6b7280;
}

/* ---- Cashier ---- */
.bill-cashier-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.bill-register-card {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.bill-register-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.bill-register-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.bill-register-dot.open {
  background: #22c55e;
}

.bill-register-dot.closed {
  background: #ef4444;
}

.bill-quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-top: 1rem;
}

.bill-quick-action {
  padding: 1rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--card-bg, #fff);
}

.bill-quick-action:hover {
  background: var(--bg-secondary, #f1f5f9);
  border-color: var(--primary, #28B8D6);
}

.bill-quick-action i {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  display: block;
}

.bill-quick-action span {
  font-size: 0.8rem;
  font-weight: 600;
}


/* ==========================================================
   FINANCIAL DASHBOARD (fd- prefix)
   ========================================================== */

/* ---- Layout ---- */
.fd-dashboard {
  padding: 0;
}

.fd-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.fd-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.fd-date-range {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.fd-date-range input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.5rem;
  font-size: 0.85rem;
  background: var(--card-bg, #fff);
  color: var(--text, #1e293b);
}

/* ---- Stats Grid ---- */
.fd-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1200px) {
  .fd-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .fd-stats-grid {
    grid-template-columns: 1fr;
  }
}

.fd-stat-card {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: all 0.2s ease;
}

.fd-stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

.fd-stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 0.75rem;
}

.fd-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text, #1e293b);
}

.fd-stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary, #94a3b8);
  margin-top: 0.25rem;
}

.fd-stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.fd-stat-trend.up {
  color: #22c55e;
  background: #22c55e15;
}

.fd-stat-trend.down {
  color: #ef4444;
  background: #ef444415;
}

/* ---- Chart Containers ---- */
.fd-charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

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

.fd-chart-card {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.fd-chart-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.fd-chart-card h3 i {
  color: var(--primary, #28B8D6);
}

/* ---- Bar Chart (CSS-only) ---- */
.fd-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 150px;
  padding: 0.5rem 0;
}

.fd-bar {
  flex: 1;
  background: var(--primary, #28B8D6);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  position: relative;
  transition: all 0.3s ease;
  cursor: pointer;
}

.fd-bar:hover {
  opacity: 0.8;
}

.fd-bar-label {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--text-secondary, #94a3b8);
  white-space: nowrap;
}

.fd-bar-value {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text, #1e293b);
  white-space: nowrap;
}

/* ---- Horizontal Bar ---- */
.fd-hbar {
  margin-bottom: 0.75rem;
}

.fd-hbar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-bottom: 0.25rem;
}

.fd-hbar-label span:first-child {
  color: var(--text-secondary, #94a3b8);
}

.fd-hbar-label span:last-child {
  font-weight: 600;
}

.fd-hbar-track {
  height: 8px;
  background: var(--bg-secondary, #f1f5f9);
  border-radius: 4px;
  overflow: hidden;
}

.fd-hbar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

/* ---- Lists ---- */
.fd-list {
  max-height: 300px;
  overflow-y: auto;
}

.fd-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

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

.fd-list-item-info {
  flex: 1;
}

.fd-list-item-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.fd-list-item-meta {
  font-size: 0.75rem;
  color: var(--text-secondary, #94a3b8);
}

.fd-list-item-value {
  font-weight: 600;
  font-size: 0.9rem;
}

/* ---- Tables ---- */
.fd-table {
  width: 100%;
  border-collapse: collapse;
}

.fd-table th {
  padding: 0.75rem;
  text-align: right;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary, #94a3b8);
  background: var(--bg-secondary, #f1f5f9);
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.fd-table td {
  padding: 0.75rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
}

.fd-table tr:hover td {
  background: var(--hover-bg, #f8fafc);
}


/* ==========================================================
   DARK MODE
   ========================================================== */

[data-theme="dark"] .bill-stat-card,
[data-theme="dark"] .bill-invoice-section,
[data-theme="dark"] .bill-invoice-header,
[data-theme="dark"] .bill-table-wrap,
[data-theme="dark"] .bill-modal,
[data-theme="dark"] .bill-register-card,
[data-theme="dark"] .bill-cashier-grid,
[data-theme="dark"] .fd-stat-card,
[data-theme="dark"] .fd-chart-card {
  background: var(--tdl-card);
  border-color: var(--tdl-border);
}

[data-theme="dark"] .bill-table th,
[data-theme="dark"] .fd-table th {
  background: var(--tdl-surface);
}

[data-theme="dark"] .bill-filter-bar input,
[data-theme="dark"] .bill-filter-bar select,
[data-theme="dark"] .bill-form-group input,
[data-theme="dark"] .bill-form-group select,
[data-theme="dark"] .fd-date-range input {
  background: var(--tdl-card);
  border-color: var(--tdl-border);
  color: var(--tdl-text-primary);
}

[data-theme="dark"] .fd-hbar-track {
  background: var(--tdl-border);
}


/* ==========================================================
   RTL SUPPORT
   ========================================================== */

[dir="rtl"] .bill-invoice-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .fd-header {
  flex-direction: row-reverse;
}

/* ---- Bill Dropdown Menu ---- */
.bill-more-menu {
  position: relative;
  display: inline-block;
}
.bill-dropdown {
  display: none;
  position: absolute;
  left: 0;
  top: 100%;
  min-width: 180px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  z-index: 50;
  padding: 4px;
  overflow: hidden;
}
.bill-dropdown.open {
  display: block;
}
.bill-dropdown button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  color: #334155;
  border-radius: 8px;
  margin: 2px 0;
  transition: background 0.15s;
  text-align: right;
}
.bill-dropdown button:hover {
  background: #f1f5f9;
}