:root {
  --primary: #0d7377;
  --primary-dark: #095b5e;
  --primary-light: #e6f4f4;
  --secondary: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --info: #3b82f6;
  --dark: #1f2937;
  --gray: #6b7280;
  --gray-light: #f3f4f6;
  --border: #e5e7eb;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  --sidebar-width: 260px;
  --header-height: 64px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #f8fafc;
  color: var(--dark);
  height: 100%;
}

a {
  text-decoration: none;
  color: inherit;
}

button {
  font-family: inherit;
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary) 0%, #14b8a6 100%);
}

.login-card {
  background: white;
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  margin: 1rem;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-brand .brand-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.75rem;
  color: var(--primary-dark);
}

.login-brand p {
  margin: 0.25rem 0 0;
  color: var(--gray);
}

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.login-form input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 115, 119, 0.15);
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 1rem;
  text-align: center;
  min-height: 1.2rem;
}

.login-hint {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.85rem;
  color: var(--gray);
}

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

.sidebar {
  width: var(--sidebar-width);
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-icon {
  font-size: 1.75rem;
}

.sidebar-brand .brand-text {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  color: var(--gray);
  transition: all 0.2s;
}

.nav-link i {
  width: 22px;
  text-align: center;
}

.nav-link:hover,
.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
}

.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--border);
}

.sidebar-footer .btn-link {
  width: 100%;
  justify-content: flex-start;
  color: var(--gray);
}

.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-header {
  height: var(--header-height);
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--dark);
  cursor: pointer;
  padding: 0.5rem;
}

.top-header h2 {
  margin: 0;
  font-size: 1.35rem;
  flex: 1;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--gray);
  font-size: 0.95rem;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logout {
  margin-left: 0.5rem;
}

.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-x: hidden;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-block {
  width: 100%;
}

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

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

.btn-secondary {
  background: var(--gray-light);
  color: var(--dark);
}

.btn-secondary:hover {
  background: var(--border);
}

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

.btn-danger:hover {
  background: #dc2626;
}

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

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

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

.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 0.5rem;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

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

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

.card-header h3 {
  margin: 0;
  font-size: 1.15rem;
}

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

.kpi-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.kpi-icon.staff { background: #dbeafe; color: var(--info); }
.kpi-icon.customers { background: #dcfce7; color: var(--success); }
.kpi-icon.invoices { background: #fef3c7; color: var(--warning); }
.kpi-icon.expenses { background: #fee2e2; color: var(--danger); }
.kpi-icon.payments { background: #e0e7ff; color: #6366f1; }
.kpi-icon.balance { background: var(--primary-light); color: var(--primary); }
.kpi-icon.profit { background: #f3e8ff; color: #9333ea; }

.kpi-info h4 {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
  color: var(--gray);
  font-weight: 500;
}

.kpi-info p {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--dark);
}

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

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

.data-table th,
.data-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  background: var(--gray-light);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:hover {
  background: #f9fafb;
}

.data-table td.actions {
  white-space: nowrap;
}

/* Compact invoice list to prevent broken/wrapping text */
#invoices-table .data-table {
  font-size: 0.75rem;
}

#invoices-table .data-table th,
#invoices-table .data-table td {
  padding: 0.5rem 0.5rem;
  white-space: nowrap;
}

#invoices-table .data-table td:nth-child(3) {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#invoices-table .btn-sm {
  padding: 0.3rem 0.5rem;
  font-size: 0.78rem;
}

#invoices-table .data-table tfoot .totals-row td {
  background: var(--gray-light);
  border-top: 2px solid var(--border);
  font-weight: 600;
  color: var(--dark);
}

/* Compact quotation / invoice-management list */
#quotations-table .data-table {
  font-size: 0.72rem;
}

#quotations-table .data-table th,
#quotations-table .data-table td {
  padding: 0.4rem 0.45rem;
  white-space: nowrap;
}

#quotations-table .data-table td:nth-child(3) {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#quotations-table .btn-sm {
  padding: 0.25rem 0.4rem;
  font-size: 0.7rem;
}

#quotations-table .data-table tfoot .totals-row td,
#expenses-table .data-table tfoot .totals-row td,
#staff-table .data-table tfoot .totals-row td {
  background: var(--gray-light);
  border-top: 2px solid var(--border);
  font-weight: 600;
  color: var(--dark);
}

.badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-paid { background: #d1fae5; color: #065f46; }
.badge-unpaid { background: #fee2e2; color: #991b1b; }
.badge-overdue { background: #fef3c7; color: #92400e; }
.badge-cancelled { background: #e5e7eb; color: #374151; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }

/* Forms */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

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

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 220px;
  max-width: 400px;
}

.search-box input {
  width: 100%;
  padding: 0.65rem 0.85rem 0.65rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.search-box i {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray);
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  padding: 1rem;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-20px);
  transition: transform 0.2s;
}

.modal-overlay.show .modal {
  transform: translateY(0);
}

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

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

.modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--gray);
  cursor: pointer;
}

.modal-body {
  padding: 1.25rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--gray);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  background: var(--dark);
  color: white;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

/* Charts */
.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

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

/* Invoice print */
.invoice-print {
  max-width: 800px;
  margin: 0 auto;
  background: white;
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.invoice-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.invoice-total {
  text-align: right;
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 2rem;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-wrapper {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .top-header {
    padding: 0 1rem;
  }

  .main-content {
    padding: 1rem;
  }

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

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    max-width: 100%;
  }

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

@media (max-width: 480px) {
  .login-card {
    padding: 1.5rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-table th,
  .data-table td {
    padding: 0.65rem 0.5rem;
    font-size: 0.9rem;
  }
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border);
  background: white;
  color: var(--gray);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

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

/* Organization logo */
.sidebar-logo {
  text-align: center;
  margin-bottom: 0.75rem;
}

.sidebar-logo img {
  max-width: 120px;
  max-height: 80px;
  object-fit: contain;
  border-radius: var(--radius);
}

.login-brand img {
  display: block;
  margin: 0 auto 1rem;
  max-width: 120px;
  max-height: 120px;
  object-fit: contain;
  border-radius: var(--radius);
}

.link-text {
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}

/* Staff Profile Modal */
.modal-profile .modal-body {
  padding: 0;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--primary-light) 0%, #ffffff 100%);
  border-bottom: 1px solid var(--border);
}

.profile-photo {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid #ffffff;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.profile-photo-placeholder {
  background: var(--primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
}

.profile-photo-placeholder span {
  line-height: 1;
}

.profile-title h2 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  color: var(--dark);
}

.profile-title p {
  margin: 0 0 0.75rem;
  color: var(--gray);
  font-size: 0.95rem;
}

.profile-info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 1.5rem;
}

.profile-info-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: transform 0.15s, box-shadow 0.15s;
}

.profile-info-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.profile-info-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.profile-info-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.profile-info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--gray);
  margin-bottom: 0.2rem;
}

.profile-info-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--dark);
  word-break: break-word;
}

.profile-print-footer {
  display: none;
  text-align: center;
  padding: 1rem;
  color: var(--gray);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

@media print {
  body * {
    visibility: hidden;
  }

  #staff-profile-modal,
  #staff-profile-modal * {
    visibility: visible;
  }

  #staff-profile-modal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: auto;
    padding: 0;
    background: white;
    opacity: 1;
    visibility: visible;
    display: block;
  }

  #staff-profile-modal .modal {
    transform: none;
    box-shadow: none;
    max-width: 100%;
    max-height: none;
    width: 100%;
    margin: 0;
    border-radius: 0;
  }

  #staff-profile-modal .modal-header,
  #staff-profile-modal .modal-close,
  #staff-profile-modal #staff-profile-print {
    display: none !important;
  }

  #staff-profile-modal .modal-body {
    padding: 1.5rem;
  }

  #staff-profile-modal .profile-header {
    background: none;
    border-bottom: 2px solid #000;
    page-break-inside: avoid;
  }

  #staff-profile-modal .profile-photo {
    border: 2px solid #ddd;
    box-shadow: none;
  }

  #staff-profile-modal .profile-info-item {
    background: none;
    border: 1px solid #ddd;
    page-break-inside: avoid;
  }

  #staff-profile-modal .profile-info-icon {
    background: #f0f0f0;
    color: #333;
  }

  #staff-profile-modal .profile-print-footer {
    display: block;
  }

  @page {
    margin: 1.5cm;
  }
}

@media (max-width: 576px) {
  .profile-header {
    flex-direction: column;
    text-align: center;
  }

  .profile-info-grid {
    grid-template-columns: 1fr;
  }
}

/* Quotation form */
.quotation-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  margin: 1.25rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.quotation-items-table {
  margin-bottom: 0;
  min-width: 760px;
}

#quotation-modal .modal {
  max-width: 920px;
}

.quotation-items-table .qi-name,
.quotation-items-table .qi-desc {
  min-width: 160px;
}

.quotation-items-table .qi-qty,
.quotation-items-table .qi-price,
.quotation-items-table .qi-total {
  min-width: 100px;
  text-align: right;
}

.quotation-items-table .qi-qty {
  text-align: center !important;
}

.quotation-items-table input {
  width: 100%;
  min-height: 40px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.quotation-items-table input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 115, 119, 0.12);
}

.quotation-items-table td {
  vertical-align: middle;
  padding: 0.75rem 0.5rem;
}

.quotation-items-table th {
  white-space: nowrap;
}

@media (max-width: 768px) {
  #quotation-modal .modal {
    max-width: 100%;
    margin: 0.5rem;
  }
}

.quotation-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  margin: 1rem 0;
}

.quotation-total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 280px;
  padding: 0.5rem 0;
  font-size: 0.95rem;
  color: var(--gray);
}

.quotation-total-row.grand {
  border-top: 2px solid var(--primary);
  margin-top: 0.25rem;
  padding-top: 0.75rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.quotation-total-row.grand strong {
  font-size: 1.25rem;
}

@media (max-width: 576px) {
  .quotation-totals {
    align-items: stretch;
  }

  .quotation-total-row {
    width: 100%;
  }
}

