/* ============================================================
   Business Control – Design System
   Palette: Warm off-white · Deep navy sidebar · Sage accent
   ============================================================ */

:root {
  /* Backgrounds */
  --bg-app:        #f0ebe4;
  --bg-card:       #ffffff;
  --bg-sidebar:    #1a2333;
  --bg-sidebar-h:  #22304a;
  --bg-sidebar-a:  #263a56;
  --bg-input:      #f7f3ee;
  --bg-hover:      #f5f0ea;

  /* Text */
  --text-primary:   #1e2a38;
  --text-secondary: #5a6578;
  --text-muted:     #8a95a3;
  --text-sidebar:   #b0bfce;
  --text-sidebar-a: #e4edf5;
  --text-white:     #ffffff;

  /* Accent – muted sage green */
  --accent:         #7a9e8e;
  --accent-dark:    #5f7d6e;
  --accent-light:   #e3eeea;
  --accent-hover:   #6b8f7f;

  /* Status */
  --s-success:     #6b8f7a;
  --s-success-bg:  #e8f2ec;
  --s-warning:     #b8883a;
  --s-warning-bg:  #faf0dc;
  --s-danger:      #a85858;
  --s-danger-bg:   #f5e8e8;
  --s-info:        #5a80a8;
  --s-info-bg:     #e5eef7;
  --s-gray:        #7a8899;
  --s-gray-bg:     #eaecf0;
  --s-blue:        #4a6fa5;
  --s-blue-bg:     #e2eaf7;
  --s-dark:        #3a4555;
  --s-dark-bg:     #dde0e8;
  --s-primary:     #7a9e8e;
  --s-primary-bg:  #e3eeea;

  /* Borders & Shadows */
  --border:       #c8bfb4;
  --border-light: #ddd8d0;
  --shadow-xs:    0 1px 2px rgba(26,35,51,.06);
  --shadow-sm:    0 2px 6px rgba(26,35,51,.08);
  --shadow-md:    0 4px 14px rgba(26,35,51,.10);
  --shadow-lg:    0 8px 28px rgba(26,35,51,.13);

  /* Dimensions */
  --sidebar-w:    248px;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;
  --radius-xl:    24px;

  /* Typography */
  --font:  'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); color: var(--text-primary); background: var(--bg-app); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }
img { max-width: 100%; }
ul { list-style: none; }

/* ── Auth Layout ── */
.auth-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2.5rem 1rem;
  background: var(--bg-app);
  background-image: radial-gradient(circle at 20% 80%, rgba(122,158,142,.12) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(26,35,51,.08) 0%, transparent 50%);
}
.auth-container { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-light);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo-mark {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--bg-sidebar) 0%, var(--bg-sidebar-a) 100%);
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; color: var(--text-white);
  letter-spacing: .05em;
  margin-bottom: .75rem;
}
.auth-logo h1 { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.auth-logo p  { font-size: .875rem; color: var(--text-secondary); margin-top: .2rem; }
.auth-footer  { text-align: center; margin-top: 1.5rem; font-size: .8rem; color: var(--text-muted); }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  border-right: 1px solid rgba(255,255,255,.05);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.4rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.logo-mark {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; color: #fff;
  letter-spacing: .05em;
  flex-shrink: 0;
}
.logo-title { display: block; font-size: .9rem; font-weight: 700; color: var(--text-white); line-height: 1.2; }
.logo-sub   { display: block; font-size: .7rem; color: var(--text-sidebar); line-height: 1.2; }

.sidebar-nav { flex: 1; padding: 1rem .75rem; overflow-y: auto; }
.nav-section-label {
  font-size: .65rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: .75rem .5rem .25rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  font-size: .875rem;
  font-weight: 450;
  transition: all .15s ease;
  margin-bottom: .1rem;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .8; }
.nav-item:hover { background: var(--bg-sidebar-h); color: var(--text-white); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active { background: var(--bg-sidebar-a); color: var(--text-sidebar-a); font-weight: 500; }
.nav-item.active svg { opacity: 1; color: var(--accent); }

.sidebar-footer {
  padding: 1rem .75rem;
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.user-info { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 600; color: #fff;
  flex-shrink: 0;
}
.user-details { min-width: 0; }
.user-name { font-size: .8rem; font-weight: 500; color: var(--text-white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .68rem; color: var(--text-muted); text-transform: capitalize; }
.logout-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all .15s;
  flex-shrink: 0;
}
.logout-btn svg { width: 15px; height: 15px; }
.logout-btn:hover { background: rgba(168,88,88,.2); color: var(--s-danger); }

/* ── Main Content ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  padding: 2rem;
}
.page-inner { max-width: 1280px; }

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); }
.page-subtitle { font-size: .875rem; color: var(--text-secondary); margin-top: .2rem; }
.page-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: .95rem; font-weight: 600; color: var(--text-primary); }
.card-body  { padding: 1.4rem; }
.card-footer { padding: .9rem 1.4rem; border-top: 1px solid var(--border-light); background: #fdf9f6; border-radius: 0 0 var(--radius) var(--radius); }

/* ── Stat Cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  padding: 1.2rem 1.4rem;
  display: flex; flex-direction: column; gap: .4rem;
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-md); }
.stat-label { font-size: .75rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.65rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; }
.stat-value.money { font-size: 1.4rem; }
.stat-sub   { font-size: .75rem; color: var(--text-secondary); }
.stat-icon  { font-size: 1.4rem; margin-bottom: .2rem; }

/* ── Grids ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  text-align: left;
  padding: .7rem 1rem;
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: #faf8f5;
}
thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }
tbody tr { border-bottom: 1px solid var(--border-light); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
tbody td { padding: .8rem 1rem; color: var(--text-primary); vertical-align: middle; }
.td-muted { color: var(--text-secondary); font-size: .83rem; }
.td-mono  { font-family: 'Menlo', 'Consolas', monospace; font-size: .83rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500;
  cursor: pointer; border: none; transition: all .15s ease;
  white-space: nowrap;
  line-height: 1.4;
  font-family: var(--font);
}
.btn svg { width: 15px; height: 15px; }
.btn-primary   { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-secondary { background: var(--bg-hover); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }
.btn-danger    { background: var(--s-danger-bg); color: var(--s-danger); border: 1px solid rgba(168,88,88,.2); }
.btn-danger:hover { background: var(--s-danger); color: #fff; }
.btn-ghost     { background: transparent; color: var(--text-secondary); padding: .4rem .6rem; }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.4rem; font-size: .95rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-secondary); margin-bottom: .4rem; }
.form-control {
  display: block; width: 100%;
  padding: .6rem .85rem;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .875rem; font-family: var(--font);
  color: var(--text-primary);
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(122,158,142,.15); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-hint { font-size: .75rem; color: var(--text-muted); margin-top: .3rem; }
.form-section { margin-bottom: 1.75rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-light); }
.form-section:last-child { border-bottom: none; margin-bottom: 0; }
.form-section-title { font-size: .85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 1rem; text-transform: uppercase; letter-spacing: .06em; }

/* ── Badges ── */
.status-badge {
  display: inline-flex; align-items: center;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .72rem; font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.status-gray    { background: var(--s-gray-bg);    color: var(--s-gray);    }
.status-blue    { background: var(--s-blue-bg);    color: var(--s-blue);    }
.status-info    { background: var(--s-info-bg);    color: var(--s-info);    }
.status-warning { background: var(--s-warning-bg); color: var(--s-warning); }
.status-success { background: var(--s-success-bg); color: var(--s-success); }
.status-danger  { background: var(--s-danger-bg);  color: var(--s-danger);  }
.status-dark    { background: var(--s-dark-bg);    color: var(--s-dark);    }
.status-primary { background: var(--s-primary-bg); color: var(--s-primary); }

.brand-badge {
  display: inline-flex; align-items: center;
  padding: .18rem .55rem;
  border-radius: 20px;
  font-size: .72rem; font-weight: 500;
  white-space: nowrap;
}

/* ── Alerts ── */
.alert { padding: .85rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; font-size: .875rem; border-left: 3px solid; }
.alert-success { background: var(--s-success-bg); color: var(--s-success); border-color: var(--s-success); }
.alert-danger  { background: var(--s-danger-bg);  color: var(--s-danger);  border-color: var(--s-danger);  }
.alert-warning { background: var(--s-warning-bg); color: var(--s-warning); border-color: var(--s-warning); }
.alert-info    { background: var(--s-info-bg);    color: var(--s-info);    border-color: var(--s-info);    }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(26,35,51,.45);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: modal-in .2s ease;
}
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }
@keyframes modal-in { from { opacity: 0; transform: scale(.96) translateY(-8px); } to { opacity: 1; transform: none; } }
.modal-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-close {
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: none; background: transparent;
  color: var(--text-muted); font-size: 1.2rem; line-height: 1;
  transition: all .15s; font-family: var(--font);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body  { padding: 1.5rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: .6rem; flex-shrink: 0; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab-btn {
  padding: .6rem 1.1rem;
  font-size: .875rem; font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer; border: none; background: transparent;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: all .15s; font-family: var(--font);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content > div { display: none; }
.tab-content > div.active { display: block; }

/* ── Search / Filter Bar ── */
.filter-bar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filter-bar .form-control { max-width: 280px; }
.filter-bar select.form-control { max-width: 180px; }
.filter-bar-right { margin-left: auto; display: flex; gap: .5rem; }

/* ── Invoice / Offer View ── */
.doc-header { display: flex; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.doc-brand { }
.doc-brand-name { font-size: 1.4rem; font-weight: 700; }
.doc-brand-tag { font-size: .8rem; color: var(--text-secondary); }
.doc-meta { text-align: right; }
.doc-meta-number { font-size: 1.1rem; font-weight: 700; font-family: monospace; }
.doc-meta-date { font-size: .85rem; color: var(--text-secondary); }
.doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-bottom: 1.5rem; padding: 1.25rem; background: var(--bg-app); border-radius: var(--radius); }
.doc-party-label { font-size: .7rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: .5rem; }
.doc-party-name  { font-size: .95rem; font-weight: 600; }
.doc-party-line  { font-size: .85rem; color: var(--text-secondary); }
.doc-positions { width: 100%; border-collapse: collapse; font-size: .875rem; margin-bottom: 1rem; }
.doc-positions th { text-align: left; padding: .5rem .75rem; font-size: .72rem; text-transform: uppercase; color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 600; }
.doc-positions td { padding: .7rem .75rem; border-bottom: 1px solid var(--border-light); }
.doc-totals { margin-left: auto; width: 280px; }
.doc-totals tr td { padding: .3rem .5rem; font-size: .875rem; }
.doc-totals tr td:first-child { color: var(--text-secondary); }
.doc-totals tr td:last-child  { text-align: right; font-weight: 500; }
.doc-totals .total-row td { font-size: 1rem; font-weight: 700; border-top: 2px solid var(--border); padding-top: .6rem; }
.doc-footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border-light); font-size: .8rem; color: var(--text-secondary); }

/* ── Positions Table (create form) ── */
.positions-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.positions-table th { text-align: left; padding: .45rem .6rem; font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; border-bottom: 1px solid var(--border); background: #faf8f5; }
.positions-table td { padding: .4rem .4rem; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.positions-table .form-control { padding: .4rem .6rem; font-size: .83rem; }
.positions-table tfoot td { padding: .5rem .6rem; }
.add-position-btn { font-size: .8rem; }

/* ── Charts ── */
.chart-wrapper { position: relative; height: 220px; }

/* ── File Upload ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  color: var(--text-muted);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}
.upload-zone svg { width: 32px; height: 32px; margin-bottom: .75rem; }
.upload-zone p { font-size: .875rem; }
.upload-zone .upload-sub { font-size: .78rem; margin-top: .3rem; }

/* ── Calendar ── */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-header { font-size: .75rem; font-weight: 600; text-align: center; color: var(--text-muted); padding: .4rem; text-transform: uppercase; }
.cal-day {
  background: var(--bg-card); border-radius: var(--radius-sm);
  padding: .4rem; min-height: 64px; font-size: .75rem;
  border: 1px solid var(--border-light); position: relative;
}
.cal-day.today { border-color: var(--accent); background: var(--accent-light); }
.cal-day.other-month { background: #f8f5f1; color: var(--text-muted); }
.cal-day-num { font-weight: 600; margin-bottom: .2rem; }
.cal-event { background: var(--accent); color: #fff; border-radius: 3px; padding: 1px 4px; font-size: .68rem; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Checklist ── */
.checklist { list-style: none; }
.checklist-item { display: flex; align-items: flex-start; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border-light); }
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type=checkbox] { width: 16px; height: 16px; margin-top: .15rem; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.checklist-label { font-size: .875rem; flex: 1; cursor: pointer; }
.checklist-label.done { text-decoration: line-through; color: var(--text-muted); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 3.5rem 2rem;
  color: var(--text-muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; opacity: .4; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .4rem; }
.empty-state p { font-size: .875rem; }

/* ── Toast ── */
.toast-container { position: fixed; top: 1.25rem; right: 1.25rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--text-primary);
  color: #fff;
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  animation: toast-in .2s ease;
  display: flex; align-items: center; gap: .5rem;
}
.toast.success { background: var(--s-success); }
.toast.error   { background: var(--s-danger);  }
.toast.warning { background: var(--s-warning); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ── Pill / Tag ── */
.tag {
  display: inline-flex; align-items: center;
  background: var(--s-gray-bg); color: var(--s-gray);
  padding: .15rem .5rem; border-radius: 20px; font-size: .72rem; font-weight: 500;
  gap: .3rem;
}

/* ── Misc Utilities ── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: .25rem; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1rem; }
.text-sm  { font-size: .8rem; }
.text-xs  { font-size: .72rem; }
.text-muted   { color: var(--text-muted); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.font-bold    { font-weight: 700; }
.font-medium  { font-weight: 500; }
.font-mono    { font-family: monospace; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.divider { border: none; border-top: 1px solid var(--border-light); margin: 1.25rem 0; }

/* ============================================================
   MOBILE LAYER
   - Sidebar wird auf < 900px ausgeblendet
   - Stattdessen: Top-Bar oben, Bottom-Nav unten, FAB mittig
   - Tabellen scrollen horizontal, Karten-Inhalte stapeln
   - Touch-Targets ≥ 44px, ausreichend Spacing
   - iOS Safe-Area unten respektieren
   ============================================================ */

/* Mobile chrome standardmäßig ausgeblendet (Desktop-First) */
.mobile-topbar,
.mobile-bottombar,
.mobile-sheet { display: none; }

/* ── ≤ 900px: Mobile Layout ────────────────────────────────────────── */
@media (max-width: 900px) {

  html { font-size: 16px; }

  /* Sidebar weg, Mobile-Chrome an */
  .sidebar { display: none; }
  .mobile-topbar { display: flex; }
  .mobile-bottombar { display: flex; }

  /* Layout: oben Topbar (56px), unten Bottombar (64px + Safe-Area) */
  .app-layout { flex-direction: column; min-height: 100dvh; }
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(56px + 1rem);
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px) + 1.25rem);
  }
  .page-inner { max-width: 100%; }

  /* ── Top Bar ── */
  .mobile-topbar {
    position: fixed; top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 .75rem;
    background: var(--bg-sidebar);
    color: var(--text-white);
    align-items: center;
    gap: .75rem;
    z-index: 90;
    box-shadow: 0 2px 10px rgba(26,35,51,.12);
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(56px + env(safe-area-inset-top, 0px));
  }
  .mt-mark {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: .8rem; font-weight: 700; color: #fff;
    letter-spacing: .04em;
    flex-shrink: 0;
  }
  .mt-title {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .mt-action {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-sidebar);
    flex-shrink: 0;
  }
  .mt-action svg { width: 20px; height: 20px; }
  .mt-action:active { background: rgba(255,255,255,.08); }

  /* Topbar-Padding-Korrektur damit Inhalt nicht unter Notch rutscht */
  .main-content {
    padding-top: calc(56px + env(safe-area-inset-top, 0px) + 1rem);
  }

  /* ── Bottom Nav ── */
  .mobile-bottombar {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(64px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 16px rgba(26,35,51,.06);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    z-index: 95;
  }
  .mb-tab {
    flex: 1;
    min-width: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: .15rem;
    padding: .35rem .25rem;
    color: var(--text-muted);
    font-size: .68rem;
    font-weight: 500;
    text-decoration: none;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: var(--font);
  }
  .mb-tab svg { width: 22px; height: 22px; }
  .mb-tab span { line-height: 1; }
  .mb-tab.active { color: var(--accent-dark); }
  .mb-tab.active svg { color: var(--accent-dark); }
  .mb-tab:active { background: var(--bg-hover); }

  /* FAB als zentrales 5. Element der Bottom-Bar, leicht angehoben */
  .mb-fab {
    flex: 0 0 64px;
    margin-top: -22px;
    width: 60px; height: 60px;
    align-self: flex-start;
    background: var(--accent);
    color: #fff;
    border: 4px solid var(--bg-card);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 6px 18px rgba(122,158,142,.5);
    cursor: pointer;
    transition: transform .15s, background .15s;
  }
  .mb-fab svg { width: 26px; height: 26px; stroke: #fff; }
  .mb-fab:active { transform: scale(.94); background: var(--accent-hover); }

  /* ── Bottom Sheets (FAB-Menü + Mehr-Drawer) ── */
  .mobile-sheet {
    position: fixed; inset: 0;
    z-index: 200;
    display: flex; flex-direction: column;
    justify-content: flex-end;
  }
  .mobile-sheet[hidden] { display: none; }
  .ms-backdrop {
    position: absolute; inset: 0;
    background: rgba(26,35,51,.45);
    animation: ms-fade .18s ease;
  }
  .ms-panel {
    position: relative;
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    padding: .75rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -10px 40px rgba(26,35,51,.20);
    animation: ms-slide .22s ease;
    max-height: 86vh;
    overflow-y: auto;
  }
  @keyframes ms-fade  { from { opacity: 0; } to { opacity: 1; } }
  @keyframes ms-slide { from { transform: translateY(100%); } to { transform: none; } }

  .ms-handle {
    width: 40px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: .25rem auto 1rem;
  }
  .ms-title {
    font-size: .72rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .1em;
    padding: 0 .25rem .75rem;
  }
  .ms-action {
    display: flex; align-items: center; gap: .9rem;
    padding: .85rem .75rem;
    border-radius: var(--radius);
    color: var(--text-primary);
    text-decoration: none;
    margin-bottom: .25rem;
    transition: background .12s;
  }
  .ms-action:active { background: var(--bg-hover); }
  .ms-action.ms-primary {
    background: var(--accent-light);
    border: 1px solid rgba(122,158,142,.3);
  }
  .ms-action-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    background: var(--accent-light);
    color: var(--accent-dark);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    flex-shrink: 0;
  }
  .ms-action-text { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
  .ms-action-text strong { font-size: .95rem; font-weight: 600; color: var(--text-primary); }
  .ms-action-text em      { font-size: .78rem; color: var(--text-muted); font-style: normal; }
  .ms-cancel {
    width: 100%;
    margin-top: .75rem;
    padding: .9rem;
    border: 1px solid var(--border);
    background: var(--bg-card);
    border-radius: var(--radius);
    font-size: .9rem; font-weight: 500;
    color: var(--text-secondary);
    font-family: var(--font);
    cursor: pointer;
  }
  .ms-cancel:active { background: var(--bg-hover); }

  /* "Mehr"-Drawer Inhalt */
  .ms-user {
    display: flex; align-items: center; gap: .75rem;
    padding: .25rem .25rem 1rem;
    margin-bottom: .5rem;
    border-bottom: 1px solid var(--border-light);
  }
  .ms-user-avatar {
    width: 44px; height: 44px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; color: #fff;
  }
  .ms-user-name { font-size: .95rem; font-weight: 600; color: var(--text-primary); }
  .ms-user-role { font-size: .78rem; color: var(--text-muted); text-transform: capitalize; }
  .ms-link {
    display: block;
    padding: .85rem .75rem;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: .95rem;
    font-weight: 500;
    text-decoration: none;
  }
  .ms-link:active { background: var(--bg-hover); }
  .ms-link-danger { color: var(--s-danger); margin-top: .25rem; border-top: 1px solid var(--border-light); border-radius: 0; padding-top: 1rem; margin-top: .5rem; }

  /* ── Page Header mobil ── */
  .page-header { flex-direction: column; align-items: stretch; gap: .5rem; margin-bottom: 1rem; }
  .page-header h1 { font-size: 1.25rem; }
  .page-actions { display: none; } /* Desktop-Aktionen → mobil ersetzt durch FAB */
  .page-actions.page-actions-mobile { display: flex; flex-wrap: wrap; gap: .5rem; }

  /* ── Stats: 2 Spalten statt auto ── */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
  .stat-card { padding: .9rem 1rem; }
  .stat-value { font-size: 1.3rem; }
  .stat-value.money { font-size: 1.15rem; }
  .stat-label { font-size: .68rem; }
  .stat-sub { font-size: .68rem; }

  /* ── Grids ── */
  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: .75rem; }
  .grid-auto { grid-template-columns: 1fr; gap: .75rem; }

  /* ── Cards ── */
  .card-header { padding: .9rem 1rem; }
  .card-body { padding: 1rem; }
  .card-footer { padding: .8rem 1rem; }
  .card-title { font-size: .9rem; }

  /* ── Forms ── */
  .form-row, .form-row-3 { grid-template-columns: 1fr; gap: .6rem; }
  .form-group { margin-bottom: .85rem; }
  .form-control {
    padding: .8rem .9rem;
    font-size: 1rem; /* iOS: ≥16px verhindert Zoom beim Fokus */
    border-radius: var(--radius-sm);
  }
  textarea.form-control { min-height: 96px; }
  .form-section { margin-bottom: 1.25rem; padding-bottom: 1rem; }
  .form-section-title { font-size: .78rem; }

  /* ── Buttons (touch) ── */
  .btn { padding: .7rem 1rem; font-size: .9rem; min-height: 44px; }
  .btn-sm { padding: .5rem .8rem; font-size: .82rem; min-height: 36px; }
  .btn-lg { padding: .9rem 1.4rem; font-size: 1rem; }

  /* ── Tabellen: horizontal scrollen, Spalten-Padding größer ── */
  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1rem; padding: 0 1rem; }
  thead th { padding: .65rem .8rem; font-size: .7rem; }
  tbody td { padding: .85rem .8rem; }
  .filter-bar { gap: .5rem; }
  .filter-bar .form-control,
  .filter-bar select.form-control { max-width: 100%; flex: 1 1 100%; }
  .filter-bar .btn { flex: 0 0 auto; }
  .filter-bar-right { margin-left: 0; width: 100%; }

  /* ── Doc-View ── */
  .doc-parties { grid-template-columns: 1fr; gap: 1rem; padding: 1rem; }
  .doc-header  { flex-direction: column; gap: 1rem; }
  .doc-meta    { text-align: left; }
  .doc-totals  { width: 100%; margin-left: 0; }

  /* ── Charts: kompakter ── */
  .chart-wrapper { height: 200px; }

  /* ── Filter-Bar ── */
  .filter-bar { flex-wrap: wrap; }

  /* ── Modal ── */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: 18px 18px 0 0; max-height: 88vh; animation: ms-slide .22s ease; }
  .modal-header, .modal-body, .modal-footer { padding: 1rem 1.1rem; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; min-width: 120px; }

  /* ── Dashboard mobile reorder: Grafik zuerst, dann Aktionen, dann Stats, dann Listen ── */
  body[data-page="dashboard"] .page-inner { display: flex; flex-direction: column; }
  body[data-page="dashboard"] .page-inner > .page-header           { order: 1; }
  body[data-page="dashboard"] .page-inner > [data-section="charts"]{ order: 2; }
  body[data-page="dashboard"] .page-inner > [data-section="quick"] { order: 3; }
  body[data-page="dashboard"] .page-inner > .stats-grid            { order: 4; }
  body[data-page="dashboard"] .page-inner > [data-section="lists"] { order: 5; }
  body[data-page="dashboard"] .page-inner > .alert                 { order: 0; }

  /* Donut-Charts unter dem Bilanz-Chart auf Mobile stapeln (statt 2-spaltig) */
  body[data-page="dashboard"] [data-section="charts"] > .grid-2 { grid-template-columns: 1fr; }

  /* Dashboard charts: Hauptchart hat eigene Karte; auf Mobile zusätzlich kompakter */
  body[data-page="dashboard"] .chart-wrapper { height: 220px; }

  /* Listen-Items in Dashboard-Cards (Aufgaben, Überfällige) — kompakter */
  body[data-page="dashboard"] .card-body ul li { padding: .85rem 1rem !important; }

  /* Toast: passender Abstand zur Topbar */
  .toast-container { top: calc(56px + env(safe-area-inset-top, 0px) + .5rem); right: .75rem; left: .75rem; }
  .toast { max-width: 100%; }
}

/* ── Sehr schmale Geräte ≤ 380px ─────────────────────────────────────── */
@media (max-width: 380px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.2rem; }
  .mb-tab span { font-size: .62rem; }
}

/* ── Größere Tablets / kleines Desktop: weiches Aufräumen ────────────── */
@media (min-width: 901px) and (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

/* ── Quick Actions (Dashboard mobile) ────────────────────────────────── */
.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
  margin-bottom: 1rem;
}
.quick-action {
  display: flex; align-items: center; gap: .7rem;
  padding: .9rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text-primary);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-xs);
  transition: transform .12s, box-shadow .12s;
}
.quick-action:active { transform: scale(.98); }
.quick-action.qa-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.quick-action.qa-primary:hover { color: #fff; }
.qa-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700;
  flex-shrink: 0;
}
.quick-action.qa-primary .qa-icon { background: rgba(255,255,255,.18); color: #fff; }
.qa-danger .qa-icon { background: var(--s-danger-bg); color: var(--s-danger); }
.qa-text { display: flex; flex-direction: column; line-height: 1.2; }
.qa-text strong { font-size: .92rem; font-weight: 600; }
.qa-text em { font-size: .72rem; color: var(--text-muted); font-style: normal; }
.quick-action.qa-primary .qa-text em { color: rgba(255,255,255,.8); }

/* Auf Desktop: Quick Actions auch sichtbar, aber dezenter (4-spaltig) */
@media (min-width: 901px) {
  .quick-actions { grid-template-columns: repeat(4, 1fr); margin-bottom: 1.5rem; }
}

/* ── Print ── */
@media print {
  .sidebar, .mobile-topbar, .mobile-bottombar, .mobile-sheet,
  .page-header .page-actions, .btn:not(.btn-print), .modal-overlay { display: none !important; }
  .main-content { margin-left: 0; padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
