*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --text: #374151;
  --text-h: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #3b82f6;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);

  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

html, body.app-body {
  height: 100%;
  overflow: hidden;
}

.app-body {
  background: var(--bg);
}

.app-layout {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100%;
}

.content-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

#root {
  min-height: 100vh;
}

h1, h2, h3 {
  color: var(--text-h);
  margin: 0;
  font-weight: 600;
}

h2 { font-size: 1.5rem; }
h3 { font-size: 1.1rem; margin-bottom: 1rem; }

p { margin: 0; }

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.content-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.mobile-topbar {
  display: none;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  width: 250px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
  color: #fff;
  font-size: 1.25rem;
}

.sidebar-header p {
  font-size: 0.8rem;
  margin-top: 0.25rem;
  opacity: 0.7;
}

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

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user {
  color: #fff;
  font-size: 0.85rem;
  padding: 0.35rem 1rem 0.5rem;
  opacity: 0.85;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: left;
  transition: background 0.15s;
  text-decoration: none;
}

a.btn {
  text-decoration: none;
}

.filter-tab {
  text-decoration: none;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.flash.success {
  background: var(--success-light);
  color: var(--success);
}

.flash.error {
  background: var(--danger-light);
  color: var(--danger);
}

.install-wrap {
  max-width: 640px;
  margin: 4rem auto;
  padding: 0 1rem;
}

.hidden { display: none; }

/* Login page */
.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f172a;
  overflow: auto;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
  padding: 1rem;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
}

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

.login-brand h1 {
  font-size: 1.5rem;
}

.login-brand p {
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-btn {
  width: 100%;
  padding: 0.7rem 1rem;
  margin-top: 0.25rem;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.nav-icon {
  font-size: 1.1rem;
}

.main-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 2rem 2rem;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

.app-footer {
  margin-top: auto;
  padding: 0.9rem 1.25rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  background: #fff;
  border-top: 1px solid var(--border);
}

.app-footer a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* Page */
.page {
  width: 100%;
  max-width: none;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-header p {
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.page-header.row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}

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

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

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-h);
}

.stat-card.accent { border-left: 4px solid var(--primary); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.warning { border-left: 4px solid var(--warning); }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 1rem;
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.category-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.category-list li {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f9fafb;
}

.actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: #f9fafb;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.btn-secondary {
  background: #f3f4f6;
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-success:hover {
  background: #047857;
}

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

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

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

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid .full-width {
  grid-column: 1 / -1;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}

input, select, textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text-h);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary-light);
  border-color: var(--primary);
}

input:disabled {
  background: #f3f4f6;
  color: var(--text-muted);
}

textarea {
  resize: vertical;
}

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

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-wide {
  max-width: 640px;
}

.modal h3 {
  margin-bottom: 1.25rem;
}

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

.filter-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem;
}

.filter-tab {
  padding: 0.4rem 0.85rem;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.filter-tabs.wrap {
  flex-wrap: wrap;
}

/* Documents */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.doc-thumb {
  display: block;
  height: 160px;
  background: #eef2ff;
  overflow: hidden;
}

.doc-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.doc-pdf-icon {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #1d4ed8;
  background: linear-gradient(135deg, #dbeafe, #eff6ff);
}

.doc-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.doc-body h3 {
  font-size: 1rem;
  margin: 0;
}

.doc-notes {
  font-size: 0.85rem;
}

.preview-modal {
  max-width: min(960px, 96vw);
}

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

.preview-body {
  background: #111827;
  border-radius: 8px;
  min-height: 420px;
  max-height: 70vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-body img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
}

.preview-body iframe {
  width: 100%;
  height: 70vh;
  border: 0;
  background: #fff;
}

.login-support {
  text-align: center;
  color: #94a3b8;
  font-size: 0.85rem;
  margin-top: 1.25rem;
}

.login-support a {
  color: #93c5fd;
  font-weight: 600;
  text-decoration: none;
}

/* Tags & Status */
.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: #f3f4f6;
  border-radius: 4px;
  font-size: 0.8rem;
}

.tag-sadar {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.8rem;
}

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

.section-header-row h3 {
  margin-bottom: 0;
}

.work-select-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 360px;
  overflow-y: auto;
}

.work-select-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.work-select-item:hover {
  border-color: var(--primary);
  background: #f9fafb;
}

.work-select-item input {
  margin-top: 0.25rem;
  flex-shrink: 0;
}

.work-select-content {
  flex: 1;
}

.work-select-title {
  font-weight: 600;
  color: var(--text-h);
}

.work-select-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Sadar contract payments */
.contract-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.contract-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fafafa;
}

.contract-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  flex-wrap: wrap;
  background: var(--surface);
}

.contract-header:hover {
  background: #f9fafb;
}

.contract-info {
  flex: 1;
  min-width: 180px;
}

.contract-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-h);
}

.contract-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.contract-amounts {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.amount-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 90px;
}

.amount-col.success .amount-value {
  color: var(--success);
}

.amount-col.warning .amount-value {
  color: var(--warning);
}

.amount-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.amount-value {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-h);
}

.progress-bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.progress-bar {
  flex: 1;
  height: 8px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #34d399);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 60px;
  text-align: right;
}

.contract-bills {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.contract-bills h4 {
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.contract-total-row td {
  background: #f3f4f6;
  border-top: 2px solid var(--border);
}

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

.status-badge.paid {
  background: var(--success-light);
  color: var(--success);
}

.status-badge.pending {
  background: var(--warning-light);
  color: var(--warning);
}

.text-success { color: var(--success); font-weight: 600; }
.text-warning { color: var(--warning); font-weight: 600; }
.text-right { text-align: right; }

.empty-text {
  color: var(--text-muted);
  text-align: center;
  padding: 2rem;
}

/* Info banner */
.info-banner {
  background: var(--primary-light);
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: #1e40af;
}

.highlight-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.highlight-card {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.highlight-title {
  font-weight: 600;
}

.highlight-rate {
  font-size: 1.25rem;
  font-weight: 700;
}

.highlight-desc {
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Bill form */
.bill-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.item-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #f9fafb;
  border-radius: var(--radius);
  margin: 1rem 0;
}

.bill-summary {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 2px solid var(--border);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
}

.summary-row.highlight {
  font-size: 1.1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.payment-info {
  background: #f9fafb;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.payment-info p {
  padding: 0.2rem 0;
}

/* Print */
.print-controls {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.bill-print {
  background: #fff;
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.bill-print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #111;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.bill-print-header h1 {
  font-size: 1.75rem;
}

.bill-print-meta p {
  text-align: right;
  font-size: 0.9rem;
}

.bill-print-client {
  margin-bottom: 1.5rem;
}

.bill-print-client p {
  padding: 0.15rem 0;
}

.bill-approval {
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  border: 1px dashed #9ca3af;
  border-radius: var(--radius);
}

.bill-print-table {
  width: 100%;
  margin-bottom: 1.5rem;
}

.bill-print-table th {
  background: #f3f4f6;
}

.bill-print-notes {
  margin-bottom: 1.5rem;
  padding: 0.75rem;
  background: #f9fafb;
  border-radius: var(--radius);
}

.bill-print-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

@media print {
  .mobile-topbar,
  .app-footer,
  .sidebar-backdrop {
    display: none !important;
  }

  body * {
    visibility: hidden;
  }

  .bill-print,
  .bill-print * {
    visibility: visible;
  }

  .bill-print {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    border: none;
    padding: 0;
  }

  .no-print {
    display: none !important;
  }

  .sidebar,
  .main-content > *:not(.print-page) {
    display: none;
  }
}

@media (min-width: 901px) {
  .mobile-topbar {
    display: none !important;
  }

  .sidebar {
    position: relative;
    transform: none;
  }

  .page,
  .content-wrap,
  .main-content {
    width: 100%;
    max-width: none;
  }

  .doc-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 1rem;
    padding-top: max(0.7rem, env(safe-area-inset-top));
    background: var(--sidebar-bg);
    color: #fff;
    flex-shrink: 0;
    z-index: 50;
  }

  .menu-toggle {
    border: 1px solid rgba(255,255,255,0.2);
    background: transparent;
    color: #fff;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 150;
  }

  body.menu-open .sidebar-backdrop {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    height: 100dvh;
    width: min(280px, 86vw);
    z-index: 200;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

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

  body.menu-open {
    overflow: hidden;
  }

  .sidebar-nav {
    flex-direction: column;
    overflow-y: auto;
  }

  .main-content {
    padding: 1rem;
    padding-bottom: 1.5rem;
  }

  .app-footer {
    font-size: 0.8rem;
    padding: 0.8rem 0.9rem;
    padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
  }

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

  .page-header.row {
    flex-direction: column;
    align-items: stretch;
  }

  .page-header.row .btn,
  .header-actions {
    width: 100%;
  }

  .header-actions .btn,
  .page-header.row > .btn {
    flex: 1;
    min-height: 42px;
  }

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

  .stat-value {
    font-size: 1.2rem;
    word-break: break-word;
  }

  .contract-header,
  .contract-amounts {
    flex-direction: column;
    align-items: flex-start;
  }

  .amount-col {
    align-items: flex-start;
  }

  input, select, textarea, .btn {
    font-size: 16px;
  }

  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }

  .modal,
  .modal-wide,
  .preview-modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .preview-body,
  .preview-body iframe {
    min-height: 50vh;
    height: 50vh;
    max-height: 50vh;
  }

  .bill-print {
    padding: 1rem;
  }

  .bill-print-header {
    flex-direction: column;
    gap: 0.75rem;
  }

  .bill-print-meta p {
    text-align: left;
  }

  .print-controls {
    flex-wrap: wrap;
  }

  .filter-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .toolbar label {
    width: 100%;
  }

  /* Stack tables as cards on phones */
  .table-wrap {
    overflow: visible;
  }

  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tfoot,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr {
    display: block;
    width: 100%;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tr {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 0.75rem;
    padding: 0.35rem 0.25rem;
    box-shadow: var(--shadow);
  }

  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    padding: 0.5rem 0.65rem;
    text-align: right;
  }

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

  .table-wrap td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    text-align: left;
    flex: 0 0 42%;
  }

  .table-wrap td:not([data-label])::before {
    display: none;
  }

  .table-wrap .actions,
  .table-wrap td.actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .login-wrap {
    padding: 1rem;
  }

  .login-card {
    padding: 1.4rem;
  }
}

@media (max-width: 520px) {
  h2 { font-size: 1.25rem; }

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

  .highlight-cards,
  .doc-grid {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 1rem;
  }
}
