/* ==========================================================================
   Baurex — design tokens: warm, milky, minimalist
   ========================================================================== */
:root {
  --font-serif: "Fraunces", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* milky, warm neutrals */
  --bg: #FAF7F1;
  --bg-elevated: #FFFFFF;
  --bg-sunken: #F1ECE1;
  --sidebar-bg: #F4EFE4;
  --sidebar-bg-hover: #EAE2D2;
  --sidebar-text: #574E3F;
  --sidebar-text-muted: #9C917C;

  --text: #2C2620;
  --text-muted: #857A69;
  --text-faint: #B7AB95;
  --border: #E8E0D0;
  --border-strong: #D9CDB4;

  /* elegant warm clay accent */
  --accent: #B0714B;
  --accent-hover: #99603E;
  --accent-soft: #F2E3D5;
  --accent-contrast: #FFFFFF;

  --success: #6E8C5B;
  --success-soft: #E9F0E1;
  --danger: #B75B48;
  --danger-soft: #F6E4DF;
  --warning: #B4863A;

  --badge-offer: #6B7FA8;
  --badge-offer-soft: #E9EDF4;
  --badge-invoice: #6E8C5B;
  --badge-invoice-soft: #E9F0E1;
  --badge-contract: #99709F;
  --badge-contract-soft: #F0E7F0;
  --badge-letter: #B0824A;
  --badge-letter-soft: #F4EAD7;

  --radius-sm: 9px;
  --radius-md: 13px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(72, 55, 30, 0.06);
  --shadow-md: 0 10px 28px rgba(72, 55, 30, 0.08);
  --shadow-lg: 0 20px 48px rgba(72, 55, 30, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1B1712;
    --bg-elevated: #221D16;
    --bg-sunken: #1E1A14;
    --sidebar-bg: #17130F;
    --sidebar-bg-hover: #221C15;
    --sidebar-text: #E4D9C6;
    --sidebar-text-muted: #93876F;

    --text: #F1E9DA;
    --text-muted: #AC9F8A;
    --text-faint: #756B58;
    --border: #34291B;
    --border-strong: #453626;

    --accent: #D89968;
    --accent-hover: #E3AB7E;
    --accent-soft: #3A2A19;
    --accent-contrast: #1B1712;

    --success: #93B87C;
    --success-soft: #22301C;
    --danger: #D68A76;
    --danger-soft: #3A251F;
    --warning: #D8AC63;

    --badge-offer: #93A6D0;
    --badge-offer-soft: #232A3C;
    --badge-invoice: #93B87C;
    --badge-invoice-soft: #22301C;
    --badge-contract: #C79FCE;
    --badge-contract-soft: #322639;
    --badge-letter: #D8AC63;
    --badge-letter-soft: #3A2E18;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #1B1712;
  --bg-elevated: #221D16;
  --bg-sunken: #1E1A14;
  --sidebar-bg: #17130F;
  --sidebar-bg-hover: #221C15;
  --sidebar-text: #E4D9C6;
  --sidebar-text-muted: #93876F;

  --text: #F1E9DA;
  --text-muted: #AC9F8A;
  --text-faint: #756B58;
  --border: #34291B;
  --border-strong: #453626;

  --accent: #D89968;
  --accent-hover: #E3AB7E;
  --accent-soft: #3A2A19;
  --accent-contrast: #1B1712;

  --success: #93B87C;
  --success-soft: #22301C;
  --danger: #D68A76;
  --danger-soft: #3A251F;
  --warning: #D8AC63;

  --badge-offer: #93A6D0;
  --badge-offer-soft: #232A3C;
  --badge-invoice: #93B87C;
  --badge-invoice-soft: #22301C;
  --badge-contract: #C79FCE;
  --badge-contract-soft: #322639;
  --badge-letter: #D8AC63;
  --badge-letter-soft: #3A2E18;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 {
  font-family: var(--font-serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}
h1 { font-size: 2rem; margin: 0 0 6px; }
h2 { font-size: 1.3rem; margin: 32px 0 14px; font-weight: 500; }
.muted { color: var(--text-muted); }
.icon { display: inline-block; vertical-align: -3px; flex-shrink: 0; }

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

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 28px 16px;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: baseline;
  padding: 4px 10px 26px;
  color: var(--text);
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.nav-section-label {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--sidebar-text-muted);
  padding: 20px 12px 8px;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-link:hover { background: var(--sidebar-bg-hover); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-hover); }
.nav-link .icon { opacity: 0.75; }
.nav-link.active .icon { opacity: 1; }

.theme-toggle {
  margin-top: auto;
  display: flex; align-items: center; gap: 10px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--sidebar-text);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: 0.84rem;
  cursor: pointer;
}
.theme-toggle:hover { background: var(--sidebar-bg-hover); }
.theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-icon-dark { display: inline-flex; }

.sidebar-account {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  margin-top: 10px; padding: 10px 12px 2px;
  border-top: 1px solid var(--border);
}
.sidebar-account-name {
  font-size: 0.82rem; font-weight: 600; color: var(--sidebar-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-account-name:hover { color: var(--accent-hover); }
.sidebar-account form { display: inline-flex; }

/* ==========================================================================
   Login / setup
   ========================================================================== */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.auth-wrap { width: 100%; max-width: 380px; }
.auth-brand {
  text-align: center; font-family: var(--font-serif); font-weight: 500;
  font-size: 1.7rem; color: var(--text); margin-bottom: 22px;
}
.auth-hint { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin: -10px 0 20px; }
.auth-wrap .form-card { margin-bottom: 0; }
.auth-wrap .flash { font-size: 0.85rem; }

.main-col { flex: 1; min-width: 0; }
.container { max-width: 1040px; margin: 0 auto; padding: 48px 36px 90px; }

/* ==========================================================================
   Cards / dashboard
   ========================================================================== */
.card-row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 8px; }
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  flex: 1; min-width: 260px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute; top: 0; left: 0; bottom: 0; width: 3px;
  background: var(--card-accent, var(--accent));
}
.card h2 { margin: 0 0 3px; font-size: 1.2rem; }
.card .muted { font-size: 0.87rem; }
.card .button-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.card[data-biz="rexoma"] { --card-accent: #4A5A78; }
.card[data-biz="bauclean"] { --card-accent: #C1704B; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.button, button, input[type="submit"] {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.87rem;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.05s ease, box-shadow 0.14s ease;
  box-shadow: var(--shadow-sm);
}
.button:hover, button:hover, input[type="submit"]:hover { background: var(--accent-hover); }
.button:active, button:active { transform: translateY(1px); }
.button.secondary, button.secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}
.button.secondary:hover, button.secondary:hover { background: var(--bg-sunken); }
.button.small, button.small { padding: 7px 13px; font-size: 0.81rem; }

.icon-btn {
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent; box-shadow: none;
  padding: 6px; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--bg-sunken); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ==========================================================================
   Tables
   ========================================================================== */
table.list-table, table.line-items, table.totals-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 16px 0 22px;
}
table.list-table th, table.line-items th {
  background: var(--bg-sunken);
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}
table.list-table td, table.line-items td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.list-table tr:last-child td { border-bottom: none; }
table.list-table tbody tr:hover { background: var(--bg-sunken); }
table.list-table a { font-weight: 600; }

.table-scroll { overflow-x: auto; border-radius: var(--radius-md); }
table.line-items { min-width: 720px; }
table.line-items input, table.line-items select {
  width: 100%; min-width: 0; padding: 7px 8px; margin: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.87rem;
  font-family: var(--font-sans);
}
table.line-items input[readonly] { background: var(--bg-sunken); color: var(--text-faint); }
table.line-items td:nth-child(3) { width: 64px; }
table.line-items td:nth-child(4) { width: 76px; }
table.line-items td:nth-child(6), table.line-items td:nth-child(7) { width: 72px; }
table.line-items td:last-child { text-align: center; width: 40px; }

table.totals-table { max-width: 380px; margin-left: auto; border: none; background: transparent; }
table.totals-table td { padding: 6px 4px; text-align: right; border: none; }
table.totals-table .grand-total td {
  font-family: var(--font-serif);
  font-weight: 600; font-size: 1.15rem;
  border-top: 1.5px solid var(--text); padding-top: 12px;
}

/* Badges */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em;
}
.badge-offer { background: var(--badge-offer-soft); color: var(--badge-offer); }
.badge-invoice { background: var(--badge-invoice-soft); color: var(--badge-invoice); }
.badge-contract { background: var(--badge-contract-soft); color: var(--badge-contract); }
.badge-letter { background: var(--badge-letter-soft); color: var(--badge-letter); }

/* ==========================================================================
   Forms
   ========================================================================== */
form { max-width: 100%; }
form label {
  display: block; margin-bottom: 15px;
  font-size: 0.84rem; font-weight: 600; color: var(--text-muted);
}
form input, form select, form textarea {
  width: 100%; padding: 10px 13px; margin-top: 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 0.92rem; font-family: var(--font-sans);
  background: var(--bg-elevated); color: var(--text);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
form input[type="checkbox"] { width: auto; }
form textarea { resize: vertical; font-family: var(--font-sans); }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row label { flex: 1; min-width: 180px; }

.form-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Misc
   ========================================================================== */
.flash {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--success-soft); border: 1px solid var(--success);
  color: var(--success);
  padding: 13px 17px; border-radius: var(--radius-md);
  margin-bottom: 22px; font-weight: 600; font-size: 0.9rem;
}
.flash div { display: flex; align-items: center; gap: 8px; }

.empty-state {
  text-align: center; padding: 52px 20px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

hr.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); }
  .nav-group { flex-direction: row; flex-wrap: wrap; }
  .theme-toggle { margin-top: 0; }
  .container { padding: 28px 20px 64px; }
}
