/* Midnight Travel — Invoice System
   Premium, minimal, Metronic-inspired */

:root {
  --mt-dark: #0f172a;
  --mt-accent: #85144b;
  --mt-gold: #c9a227;
  --mt-off-white: #f8fafc;
  --mt-white: #fff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  --sidebar-width: 260px;
}

/* Safari/iOS: prevent text resize in landscape, reliable full height */
html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
  min-height: 100%;
  min-height: -webkit-fill-available;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--mt-off-white);
  line-height: 1.5;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  position: relative;
}
a { color: var(--mt-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Tap highlight: subtle on iOS Safari */
button, .btn, .fab, .sidebar-link, input, select, textarea {
  -webkit-tap-highlight-color: transparent;
}

/* Layout — use dvh on Safari for correct viewport when UI shows/hides */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: var(--sidebar-width);
  background: var(--mt-white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
}
.sidebar-brand {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0.75rem;
}
.sidebar-logo {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--mt-accent), var(--mt-gold));
  color: var(--mt-white);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem; border-radius: var(--radius);
}
.sidebar-title { font-weight: 700; color: var(--mt-dark); }
.sidebar-subtitle { font-size: 0.75rem; color: var(--text-muted); display: block; }
.sidebar-nav { flex: 1; padding: 1rem 0; overflow-y: auto; }
.sidebar-link {
  display: block; padding: 0.6rem 1.5rem; color: var(--text);
  transition: background 0.15s, color 0.15s;
}
.sidebar-link:hover { background: var(--mt-off-white); color: var(--mt-accent); }
.sidebar-link.active { background: rgba(133, 20, 75, 0.08); color: var(--mt-accent); font-weight: 600; }
.sidebar-footer {
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
  font-size: 0.8rem; color: var(--text-muted);
}
.sidebar-user { display: block; margin-bottom: 0.25rem; }

.main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topbar {
  background: var(--mt-white); border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem; position: sticky; position: -webkit-sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 0.75rem;
}
.topbar-title { font-size: 1.25rem; font-weight: 700; color: var(--mt-dark); flex: 1; min-width: 0; }
.locale-switcher { flex-shrink: 0; font-size: 0.9rem; }
.locale-switcher .locale-link { color: var(--text-muted); text-decoration: none; }
.locale-switcher .locale-link:hover { color: var(--mt-accent); }
.locale-switcher .locale-link.active { font-weight: 700; color: var(--mt-accent); }
.locale-switcher .locale-sep { color: var(--border); margin: 0 0.25rem; }
.content { padding: 1.5rem; flex: 1; }

/* Login */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: linear-gradient(180deg, var(--mt-off-white) 0%, var(--mt-white) 100%);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--mt-white);
  border-radius: 12px; box-shadow: var(--shadow); padding: 2rem;
}
.locale-switcher-login {
  position: absolute;
  top: calc(1rem + env(safe-area-inset-top, 0));
  right: calc(1rem + env(safe-area-inset-right, 0));
  font-size: 0.9rem;
}
.locale-switcher-login .locale-link { color: var(--text-muted); text-decoration: none; }
.locale-switcher-login .locale-link:hover { color: var(--mt-accent); }
.locale-switcher-login .locale-link.active { font-weight: 700; color: var(--mt-accent); }
.locale-switcher-login .locale-sep { color: var(--border); margin: 0 0.25rem; }
[dir="rtl"] .locale-switcher-login { right: auto; left: calc(1rem + env(safe-area-inset-left, 0)); }
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 0.75rem;
  background: linear-gradient(135deg, var(--mt-accent), var(--mt-gold));
  color: var(--mt-white); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.5rem; border-radius: 12px;
}
.login-brand h1 { font-size: 1.5rem; color: var(--mt-dark); }
.login-brand p { font-size: 0.85rem; color: var(--text-muted); }
.login-form .form-group { margin-bottom: 1rem; }
.login-form label { display: block; margin-bottom: 0.35rem; font-weight: 500; }
.login-form input {
  width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius);
  -webkit-appearance: none; appearance: none; background-color: var(--mt-white);
}
.login-form .btn { margin-top: 0.5rem; }

/* Cards */
.card { background: var(--mt-white); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.5rem; overflow: hidden; }
.card-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 1.1rem; font-weight: 700; }
.card-body { padding: 1.25rem; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--mt-white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem; border-left: 4px solid var(--mt-accent);
}
.stat-card.stat-success { border-left-color: #059669; }
.stat-card.stat-warning { border-left-color: #d97706; }
.stat-card.stat-revenue { border-left-color: var(--mt-gold); }
.stat-value { display: block; font-size: 1.5rem; font-weight: 700; color: var(--mt-dark); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.6rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.table th.num { text-align: right; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--mt-off-white); }
.actions { white-space: nowrap; }
.actions .btn { margin-right: 0.25rem; }
.actions-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; }
.actions-wrap .btn { margin-right: 0; }
.actions-wrap .inline-form { display: inline; }
.inline-form { display: inline; }

/* Table responsive wrapper (horizontal scroll on small screens) */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: -0.25rem 0; }
.table-responsive .table { min-width: 640px; }

/* Invoice list table columns */
.table-invoices .col-number { width: 120px; }
.table-invoices .col-customer { min-width: 120px; }
.table-invoices .col-date { width: 90px; white-space: nowrap; }
.table-invoices .col-status { width: 90px; }
.table-invoices .col-total { width: 100px; white-space: nowrap; }
.table-invoices .col-author { width: 90px; color: var(--text-muted); font-size: 0.875rem; }
.table-invoices .col-actions { width: 1%; white-space: nowrap; }
.invoice-number-link { font-weight: 600; color: var(--mt-accent); }
.invoice-number-link:hover { text-decoration: underline; }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.5rem; font-size: 0.75rem; font-weight: 600; border-radius: 4px; }
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }
.badge-admin { background: #e0e7ff; color: #3730a3; }
.badge-staff { background: #dbeafe; color: #1e40af; }
.badge-viewer { background: #f3f4f6; color: #4b5563; }

/* Buttons */
.btn { display: inline-block; padding: 0.5rem 1rem; font-size: 0.875rem; font-weight: 500; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; transition: background 0.15s, color 0.15s; }
.btn-primary { background: var(--mt-accent); color: var(--mt-white); border-color: var(--mt-accent); }
.btn-primary:hover { background: #6b0f3c; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--mt-off-white); }
.btn-text { background: none; border: none; color: var(--mt-accent); padding: 0.25rem 0.5rem; }
.btn-text:hover { text-decoration: underline; }
.btn-danger { color: #b91c1c; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-block { width: 100%; text-align: center; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: 0.9rem;
}
/* Safari: consistent form control appearance (avoid default shadows/radius) */
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group textarea {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--mt-white);
}
.form-group select {
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--mt-white);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}
[dir="rtl"] .form-group select {
  background-position: left 0.75rem center;
  padding-right: 0.75rem;
  padding-left: 2rem;
}
.form-group .readonly { background: var(--mt-off-white); color: var(--text-muted); }
.form-row { display: flex; flex-wrap: wrap; gap: 1rem; }
.form-row.two-cols .form-group { flex: 1; min-width: 140px; }
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #d1fae5; color: #065f46; }
.empty-state { color: var(--text-muted); }
.empty-state a { font-weight: 500; }

/* Invoice form line items */
.line-items-table .col-qty { width: 80px; }
.line-items-table .col-price { width: 110px; }
.line-items-table .col-total { width: 100px; }
.line-items-table input { width: 100%; padding: 0.4rem; font-size: 0.85rem; }
.line-items-table .input-desc { margin-top: 0.25rem; font-size: 0.8rem; color: var(--text-muted); }
.totals-row { margin-top: 1rem; }

/* Invoice view */
.invoice-view .invoice-meta-row { display: flex; flex-wrap: wrap; gap: 2rem; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.invoice-view .invoice-totals { margin-top: 1rem; text-align: right; }
.invoice-view .grand-total { font-size: 1.25rem; font-weight: 700; margin-top: 0.5rem; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content { position: relative; background: var(--mt-white); border-radius: var(--radius); box-shadow: 0 20px 40px rgba(0,0,0,0.15); padding: 1.5rem; max-width: 420px; width: 100%; }
.modal-content.modal-content--user { max-width: 500px; }
.modal-content h3 { margin-bottom: 1rem; }

/* User modal: password block (fieldset + legend — one heading, no duplicate “Password”) */
fieldset.modal-password-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1rem 0.75rem;
  margin: 0 0 1rem;
  min-width: 0;
  background: var(--mt-off-white, #f8fafc);
}
legend.modal-password-section-title {
  padding: 0;
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--mt-dark);
  float: none;
  width: 100%;
}
.modal-password-wrap .form-group:last-of-type { margin-bottom: 0.5rem; }
.modal-password-hint {
  margin: 0;
  padding-top: 0.25rem;
  font-size: 0.85rem;
  color: #64748b;
  line-height: 1.35;
}
[dir="rtl"] legend.modal-password-section-title { text-align: right; }

/* Misc */
.muted { color: var(--text-muted); font-size: 0.85rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; color: var(--mt-dark); }

/* Mobile menu button (hidden on desktop) */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0 0.5rem 0 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
}
.mobile-menu-icon {
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -6px 0 currentColor, 0 6px 0 currentColor;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 998;
  opacity: 0;
  transition: opacity 0.2s ease;
}
body.sidebar-open .sidebar-backdrop {
  display: block;
  opacity: 1;
}

/* Floating action button (mobile only) */
.fab {
  display: none;
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0));
  right: calc(16px + env(safe-area-inset-right, 0));
  z-index: 100;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--mt-accent);
  color: var(--mt-white);
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(133, 20, 75, 0.4);
  border: none;
  text-decoration: none;
  font-size: 1.75rem;
  line-height: 1;
  font-weight: 300;
}
.fab:hover { color: var(--mt-white); background: #6b0f3c; }
.fab-icon { display: block; }

/* Settings links (desktop) */
.settings-links { list-style: none; padding: 0; margin-top: 1rem; }
.settings-links li { margin-bottom: 0.5rem; }
.settings-link-desc { margin-left: 0.5rem; color: var(--text-muted); }

/* ========== Mobile & tablet responsive ========== */
@media (max-width: 992px) {
  .main { margin-left: 0 !important; }
  .sidebar {
    transform: translateX(-100%) !important;
    width: min(280px, 85vw);
    max-width: calc(100vw - env(safe-area-inset-left, 0) - env(safe-area-inset-right, 0));
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    height: 100%;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    transition: transform 0.25s ease;
    z-index: 999;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
    -webkit-overflow-scrolling: touch;
  }
  body.sidebar-open .sidebar { transform: translateX(0) !important; }
  body.sidebar-open { overflow: hidden; position: fixed; width: 100%; }
  .mobile-menu-btn { display: flex !important; }
}

/* Mobile: Safari / iOS — safe areas, overflow, touch scrolling */
@media (max-width: 768px) {
  html { overflow-x: hidden; }
  body { overflow-x: hidden; padding-bottom: env(safe-area-inset-bottom, 0); -webkit-overflow-scrolling: touch; }
  .app { overflow-x: hidden; min-width: 0; min-height: 100dvh; min-height: -webkit-fill-available; }
  .main { margin-left: 0 !important; min-width: 0; width: 100%; max-width: 100%; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
  .content {
    padding: 16px;
    padding-left: calc(16px + env(safe-area-inset-left, 0));
    padding-right: calc(16px + env(safe-area-inset-right, 0));
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0));
    min-width: 0;
    max-width: 100%;
  }
  .mobile-menu-btn { display: flex !important; }
  .topbar {
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0));
    padding-left: calc(1rem + env(safe-area-inset-left, 0));
    padding-right: calc(1rem + env(safe-area-inset-right, 0));
    display: flex;
    align-items: center;
    min-width: 0;
    width: 100%;
  }
  /* Prevent Safari zoom on input focus (16px minimum) */
  input[type="text"], input[type="email"], input[type="number"], input[type="tel"],
  input[type="date"], input[type="password"], input[type="search"], textarea {
    font-size: 16px;
    max-width: 100%;
  }
  select { font-size: 16px; max-width: 100%; }
  .topbar-title { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
  .sidebar {
    width: min(280px, 85vw);
    transform: translateX(-100%) !important;
    transition: transform 0.25s ease;
    z-index: 999;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.1);
  }
  body.sidebar-open .sidebar { transform: translateX(0) !important; }
  body.sidebar-open { overflow: hidden; }
  .fab { display: flex !important; z-index: 500; }
  .card { min-width: 0; margin-bottom: 18px; }
  .card:last-child { margin-bottom: 1.5rem; }
  .card-header {
    flex-direction: column;
    align-items: stretch;
    padding: 1rem 16px;
    gap: 0.5rem;
  }
  .card-header .btn { align-self: flex-start; }
  .card-body { padding: 1rem 16px; min-width: 0; }
  .header-actions { gap: 0.5rem; }
  /* Dashboard: single column, full width, 16–20px spacing */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 18px;
    margin-bottom: 1.5rem;
  }
  .stat-card { padding: 1.25rem 16px; min-width: 0; width: 100%; }
  .stat-value { font-size: 1.25rem; }
  /* Forms: single column, 12–16px spacing */
  .form-row { flex-direction: column !important; }
  .form-row .form-group { width: 100% !important; max-width: none !important; flex: none !important; min-width: 0 !important; }
  .form-group { margin-bottom: 14px; }
  #add-line { width: 100%; min-height: 44px; display: block; text-align: center; margin-top: 0.5rem; }
  .form-actions { gap: 12px; margin-top: 1.25rem; }
  .form-actions .btn { min-height: 44px; }
  .btn { min-height: 44px; padding: 0.6rem 1rem; }
  /* Table: card-style on mobile when .table-mobile-cards */
  .table-responsive.table-mobile-cards {
    overflow: visible;
    margin: 0;
    padding: 0;
    min-width: 0;
  }
  .table-responsive.table-mobile-cards .table {
    min-width: 0;
    font-size: 0.9rem;
  }
  .table-responsive.table-mobile-cards .table thead { display: none; }
  .table-responsive.table-mobile-cards .table tbody tr {
    display: block;
    background: var(--mt-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
  }
  .table-responsive.table-mobile-cards .table tbody tr:hover { background: var(--mt-white); }
  .table-responsive.table-mobile-cards .table tbody td {
    display: block;
    padding: 0.4rem 0;
    border: none;
    text-align: left;
  }
  .table-responsive.table-mobile-cards .table tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: block;
    margin-bottom: 0.2rem;
  }
  .table-responsive.table-mobile-cards .table tbody td[data-label=""]::before { display: none; }
  .table-responsive.table-mobile-cards .table tbody td.col-actions { padding-top: 0.75rem; margin-top: 0.5rem; border-top: 1px solid var(--border); }
  .table-responsive.table-mobile-cards .line-items-table tbody td input { width: 100%; box-sizing: border-box; }
  .table-responsive.table-mobile-cards .line-items-table tbody td button.remove-line { width: 100%; min-height: 44px; }
  .table-responsive.table-mobile-cards .actions-wrap { flex-direction: column; gap: 8px; }
  .table-responsive.table-mobile-cards .actions-wrap .btn { width: 100%; min-height: 44px; justify-content: center; }
  .table-responsive.table-mobile-cards .actions-wrap .inline-form { display: block; }
  .table-responsive.table-mobile-cards .actions-wrap .inline-form .btn { width: 100%; }
  /* Tables that stay horizontal (e.g. line items) */
  .table-responsive:not(.table-mobile-cards) {
    margin: 0;
    padding: 0;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-responsive:not(.table-mobile-cards) .table { min-width: 520px; font-size: 0.875rem; }
  .line-items-table { min-width: 480px; }
  .table th, .table td { padding: 0.5rem 0.5rem; }
  .actions-wrap { flex-direction: column; align-items: stretch; gap: 8px; }
  .actions-wrap .btn { min-height: 44px; width: 100%; }
  .modal { padding: 0.75rem; align-items: flex-start; -webkit-overflow-scrolling: touch; }
  .modal-content { max-height: 90vh; max-height: 90dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .login-page { padding: 1rem; padding-left: calc(1rem + env(safe-area-inset-left, 0)); padding-right: calc(1rem + env(safe-area-inset-right, 0)); }
  .login-card { padding: 1.5rem; max-width: 100%; }
  .invoice-view .invoice-meta-row { gap: 1rem; }
  .invoice-view .invoice-from-row { margin-bottom: 0.75rem; padding-bottom: 0.75rem; }
  .invoice-view p, .invoice-view .invoice-totals { word-wrap: break-word; overflow-wrap: break-word; }
  .settings-links li { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; margin-bottom: 0.75rem; }
  .settings-link-desc { margin-left: 0; margin-top: 0.15rem; font-size: 0.875rem; }
  .alert { overflow-wrap: break-word; word-wrap: break-word; }
  /* Typography: heading hierarchy, no overflow */
  .card-header h2 { font-size: 1.1rem; line-height: 1.3; word-wrap: break-word; }
  h3 { font-size: 1rem; margin: 1rem 0 0.5rem; line-height: 1.3; }
  .content { overflow-wrap: break-word; word-wrap: break-word; }
}

@media (max-width: 480px) {
  .content {
    padding: 12px;
    padding-left: calc(12px + env(safe-area-inset-left, 0));
    padding-right: calc(12px + env(safe-area-inset-right, 0));
    padding-bottom: calc(80px + env(safe-area-inset-bottom, 0));
  }
  .card-body { padding: 12px; }
  .card-header { padding: 12px; }
  .card-header h2 { font-size: 1rem; }
  .stat-card { padding: 1rem 12px; }
  .form-group { margin-bottom: 12px; }
  .modal { padding: 0.5rem; }
  .modal-content { padding: 1rem; }
  .form-actions { flex-direction: column; gap: 10px; }
  .form-actions .btn { width: 100%; }
  .table-responsive.table-mobile-cards .table tbody tr { padding: 12px; }
  .fab { bottom: calc(12px + env(safe-area-inset-bottom, 0)); right: calc(12px + env(safe-area-inset-right, 0)); }
}

/* ========== RTL (Arabic) ========== */
[dir="rtl"] .sidebar { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .main { margin-left: 0; margin-right: var(--sidebar-width); }
[dir="rtl"] .sidebar-nav { padding: 1rem 0; }
[dir="rtl"] .topbar-title { text-align: right; }
[dir="rtl"] .content { text-align: right; }
[dir="rtl"] .card-header { flex-direction: row-reverse; }
[dir="rtl"] .table th, [dir="rtl"] .table td { text-align: right; }
[dir="rtl"] .table th.num, [dir="rtl"] .table td.num { text-align: left; }
[dir="rtl"] .form-group label { text-align: right; }
[dir="rtl"] .locale-switcher { order: -1; }
[dir="rtl"] .fab { right: auto; left: calc(12px + env(safe-area-inset-left, 0)); }
@media (max-width: 992px) {
  [dir="rtl"] .sidebar { transform: translateX(100%) !important; right: 0; left: auto; }
  [dir="rtl"] body.sidebar-open .sidebar { transform: translateX(0) !important; }
  [dir="rtl"] .main { margin-right: 0 !important; }
}
@media (max-width: 768px) {
  [dir="rtl"] .fab { right: auto; left: calc(12px + env(safe-area-inset-left, 0)); }
}
@media (max-width: 480px) {
  [dir="rtl"] .fab { left: calc(12px + env(safe-area-inset-left, 0)); }
}

/* Pagination */
.pagination-nav { margin-top: 1rem; }
.pagination {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.35rem;
  list-style: none; margin: 0; padding: 0;
}
.pagination-item { display: inline-block; }
.pagination-link {
  display: inline-block; padding: 0.4rem 0.65rem; font-size: 0.9rem;
  color: var(--mt-accent); text-decoration: none; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--mt-white);
  transition: background 0.15s, color 0.15s;
}
.pagination-link:hover { background: var(--mt-off-white); color: var(--mt-dark); }
.pagination-item.active .pagination-link {
  background: var(--mt-accent); color: var(--mt-white); border-color: var(--mt-accent); cursor: default;
}
.pagination-item.disabled .pagination-link { color: var(--text-muted); cursor: not-allowed; pointer-events: none; }
