/* ==========================================================================
   LWC-Faktura — UI System
   Design tokens + Pico.css overrides for a modern, professional faktura tool.
   Colors derived from the LWC logo (blue + red accent).
   ========================================================================== */

:root {
  /* Brand */
  --brand-primary: #0b3d66;
  --brand-primary-hover: #0f4d80;
  --brand-primary-soft: rgba(11, 61, 102, 0.08);
  --brand-primary-soft-hover: rgba(11, 61, 102, 0.14);
  --brand-accent: #c8102e;
  --brand-accent-hover: #a40d24;

  /* Neutrals */
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-alt: #fafbfc;
  --text: #1a1f2c;
  --muted: #6b7280;
  --border: #e5e8ee;
  --border-strong: #cdd2db;

  /* Effects */
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .04);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, .08), 0 12px 32px rgba(0, 0, 0, .04);
  --radius: 10px;
  --radius-sm: 6px;

  /* Status */
  --success: #047857;
  --success-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --info: #0b3d66;
  --info-soft: rgba(11, 61, 102, 0.08);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;

  /* Pico overrides */
  --pico-primary: var(--brand-primary);
  --pico-primary-hover: var(--brand-primary-hover);
  --pico-primary-focus: rgba(11, 61, 102, 0.25);
  --pico-primary-inverse: #ffffff;
  --pico-secondary: #4b5563;
  --pico-font-family: var(--font-sans);
  --pico-font-size: 14.5px;
  --pico-line-height: 1.55;
  --pico-border-radius: var(--radius-sm);
  --pico-form-element-spacing-vertical: 0.5rem;
  --pico-form-element-spacing-horizontal: 0.7rem;
  --pico-spacing: 1rem;
}

/* ==========================================================================
   Base / typography
   ========================================================================== */

html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5 {
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.2;
  font-weight: 600;
}
h1 { font-size: 1.65rem; margin-bottom: 0.25rem; }
h2 { font-size: 1.25rem; margin-top: 2rem; }
h3 { font-size: 1.05rem; margin-top: 1.5rem; }

p { margin-block: 0.5rem; }

a { color: var(--brand-primary); text-decoration: none; }
a:hover { color: var(--brand-primary-hover); text-decoration: underline; }

code {
  font-family: var(--font-mono);
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

.muted { color: var(--muted); }

/* Numeric columns / amounts: use tabular figures */
[data-amount], .amount, td.amount, td[style*="text-align:right"] {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.main {
  padding: 1.75rem 2rem 3rem;
  background: var(--bg);
  min-width: 0;  /* avoid grid overflow */
}

.main > h1:first-child,
.main > .page-header:first-child { margin-top: 0; }

.main h2 + form,
.main h2 + table,
.main h2 + .card,
.main form + h2,
.main table + h2 { margin-top: 1rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .main { padding: 1rem; }
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 1.1rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.sidebar-brand .dot {
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  background: var(--brand-accent);
  border-radius: 50%;
  margin: 0 0.15em;
}

.sidebar nav {
  flex: 1;
  padding: 0.6rem 0.5rem;
  overflow-y: auto;
}

.sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sidebar nav > ul > li { margin-bottom: 1px; }

.sidebar nav ul ul {
  margin: 0.15rem 0 0.4rem 0.6rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--border);
}
.sidebar nav ul ul a { font-size: 0.92em; padding: 5px 10px; }

.sidebar nav a,
.sidebar nav strong {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
  margin-left: -3px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar nav strong {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-top: 0.6rem;
  cursor: default;
}
.sidebar nav > ul > li:first-child > strong { margin-top: 0; }

.sidebar nav a:hover {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
  font-weight: 600;
  border-left-color: var(--brand-primary);
}

/* Inline badge inside sidebar links (e.g. Mahn-Inbox count) */
.sidebar nav a .badge,
.sidebar nav a > .badge {
  margin-left: auto;
  background: var(--brand-accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  line-height: 1.5;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-footer a { color: var(--brand-primary); }

/* Emoji / icon spacing helper */
.sidebar nav a > .ico,
.ico {
  display: inline-block;
  width: 1.2em;
  text-align: center;
  flex-shrink: 0;
}

@media (max-width: 900px) {
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card,
.main > article,
article {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem;
  margin-block: 1rem;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.card > header,
article > header {
  margin: -1rem -1.1rem 0.6rem;
  padding: 0.6rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* Stat tiles for dashboard */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-block: 1.25rem;
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.9rem 1rem 1rem;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.stat-tile:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.stat-tile.stat--success { border-left-color: var(--success); }
.stat-tile.stat--warn { border-left-color: var(--warn); }
.stat-tile.stat--danger { border-left-color: var(--brand-accent); }
.stat-tile .stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  margin: 0;
}
.stat-tile .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0.25rem 0 0;
  font-variant-numeric: tabular-nums;
}
.stat-tile .stat-sub {
  font-size: 0.83rem;
  color: var(--muted);
  margin: 0.2rem 0 0;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

button,
input[type="submit"],
input[type="button"],
[role="button"],
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--brand-primary);
  color: #fff;
  border: 1px solid var(--brand-primary);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.95rem;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}
button:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
[role="button"]:hover,
.btn:hover {
  background: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
  color: #fff;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}
button:active,
[role="button"]:active,
.btn:active { transform: translateY(1px); }
button:focus-visible,
[role="button"]:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}
button:disabled,
button[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}

/* Secondary */
button.secondary,
input[type="submit"].secondary,
[role="button"].secondary,
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
button.secondary:hover,
[role="button"].secondary:hover,
.btn-secondary:hover {
  background: var(--surface-alt);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

/* Danger / outline danger */
button.danger,
[role="button"].danger,
.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger);
}
button.danger:hover,
[role="button"].danger:hover,
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

/* Ghost / link-like */
button.ghost,
.btn-ghost {
  background: transparent;
  color: var(--brand-primary);
  border-color: transparent;
}
button.ghost:hover {
  background: var(--brand-primary-soft);
  border-color: transparent;
}

/* ==========================================================================
   Forms
   ========================================================================== */

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.85rem;
}
label > input,
label > select,
label > textarea {
  margin-top: 0.25rem;
}

label > input[type="checkbox"],
label > input[type="radio"] {
  margin-top: 0;
  margin-right: 0.4rem;
  vertical-align: middle;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.65rem;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand-primary);
  outline: none;
  box-shadow: 0 0 0 3px rgba(11, 61, 102, 0.18);
}
input::placeholder,
textarea::placeholder { color: var(--muted); opacity: 0.7; }

input[readonly],
input[disabled],
select[disabled],
textarea[readonly],
textarea[disabled] {
  background: var(--surface-alt);
  color: var(--muted);
  cursor: not-allowed;
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-block;
  width: auto;
  accent-color: var(--brand-primary);
}

input[type="file"] {
  padding: 0.4rem 0.5rem;
  background: var(--surface-alt);
}

fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1rem 1.1rem 0.5rem;
  margin-bottom: 1rem;
}
legend {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  padding: 0 0.4rem;
  margin-left: -0.4rem;
}

/* Forms outside a fieldset get their own card-ish surface */
form.card-form,
.main > form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem 0.6rem;
  margin-bottom: 1.25rem;
}
.main > form.row,
.main > form.toolbar {
  /* compact filter rows: keep the row layout but lighter */
  background: var(--surface);
  padding: 0.7rem 0.85rem;
}
.main > form > button:last-child,
.main > form > .form-actions {
  margin-top: 0.25rem;
}

/* .row used as flex-row of inputs */
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: flex-end;
}
.row > * { flex: 1 1 12rem; min-width: 0; }
.row > button,
.row > [role="button"] { flex: 0 0 auto; }

/* ==========================================================================
   Tables
   ========================================================================== */

table,
table.compact {
  width: 100%;
  background: var(--surface);
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-block: 1rem;
  font-size: 0.93rem;
}
table thead th {
  background: var(--surface-alt);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table tbody td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table tbody tr:last-child td { border-bottom: none; }

table.compact td,
table.compact th {
  padding: 0.5rem 0.75rem;
}

/* tabular numbers for right-aligned cells (typically amounts) */
table td[style*="text-align:right"],
table td[style*="text-align: right"] {
  font-variant-numeric: tabular-nums;
}

/* Subtle zebra optional via .zebra modifier */
table.zebra tbody tr:nth-child(even) td {
  background: rgba(11, 61, 102, 0.025);
}

/* ==========================================================================
   Clickable rows
   ========================================================================== */
tr.row-clickable { cursor: pointer; transition: background 0.12s ease; }
tr.row-clickable:hover td { background: rgba(11, 61, 102, 0.04); }

/* ==========================================================================
   Status badges
   ========================================================================== */

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.74rem;
  font-weight: 600;
  border-radius: 999px;
  background: #e5e7eb;
  color: #374151;
  letter-spacing: 0.02em;
  line-height: 1.5;
  white-space: nowrap;
}
.badge--draft       { background: #e5e7eb; color: #374151; }
.badge--firmed      { background: var(--info-soft); color: var(--info); }
.badge--paid        { background: var(--success-soft); color: var(--success); }
.badge--partial     { background: var(--warn-soft); color: var(--warn); }
.badge--reminded    { background: var(--danger-soft); color: var(--danger); }
.badge--cancelled   { background: #f3f4f6; color: var(--muted); text-decoration: line-through; }

/* ==========================================================================
   Inline alerts (replaces ad-hoc <article style="background:#dfd"> etc.)
   ========================================================================== */

.alert {
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  margin-block: 0.85rem;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.alert--success { background: var(--success-soft); color: var(--success); border-color: rgba(4, 120, 87, 0.2); }
.alert--info    { background: var(--info-soft); color: var(--info); border-color: rgba(11, 61, 102, 0.2); }
.alert--warn    { background: var(--warn-soft); color: var(--warn); border-color: rgba(180, 83, 9, 0.2); }
.alert--danger  { background: var(--danger-soft); color: var(--danger); border-color: rgba(185, 28, 28, 0.25); }

/* ==========================================================================
   Login / anonymous layout
   ========================================================================== */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: linear-gradient(160deg, #eef3f9 0%, var(--bg) 60%, #f4f6fa 100%);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.75rem 1.85rem;
}
.auth-card .auth-brand {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: -0.01em;
  margin-bottom: 0.25rem;
}
.auth-card .auth-brand .dot {
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  background: var(--brand-accent);
  border-radius: 50%;
  margin: 0 0.18em;
  vertical-align: 0.18em;
}
.auth-card .auth-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.auth-card form button[type="submit"] {
  width: 100%;
  padding: 0.6rem 1rem;
  margin-top: 0.25rem;
}

/* ==========================================================================
   Document editor — sticky summary
   ========================================================================== */

.doc-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 0.85rem 1rem;
  margin-block: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  align-items: baseline;
  justify-content: space-between;
}
.doc-summary .total {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--brand-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.doc-summary .breakdown {
  color: var(--muted);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}

.doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding-top: 0.85rem;
  margin-top: 0.85rem;
  border-top: 1px solid var(--border);
}
.doc-actions form { display: inline-block; margin: 0; padding: 0; background: transparent; border: none; box-shadow: none; }

/* Toolbar: filter rows etc */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1rem;
}
.toolbar > input,
.toolbar > select { flex: 1 1 12rem; min-width: 8rem; }
.toolbar > .spacer { flex: 1 1 auto; }

/* Generic cluster of inline forms / buttons */
.button-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.button-group form { display: inline-block; margin: 0; padding: 0; background: transparent; border: none; box-shadow: none; }

/* ==========================================================================
   Misc
   ========================================================================== */

details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.5rem 0.85rem; margin-block: 0.85rem; }
details > summary { cursor: pointer; font-weight: 500; }
details[open] > summary { margin-bottom: 0.5rem; }

aside.note,
.aside-note {
  background: var(--surface-alt);
  border-left: 3px solid var(--border-strong);
  padding: 0.6rem 0.85rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  color: var(--muted);
  margin-block: 0.85rem;
}

::selection { background: rgba(11, 61, 102, 0.18); }

/* Verschluesselungs-Mode Radio-Group (E-Mail-Settings) */
fieldset.enc-mode {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  margin: 0.5rem 0 1rem;
  background: var(--surface-alt, #fafbfc);
}
fieldset.enc-mode legend {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 0.4rem;
}
label.enc-radio {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.5rem;
  margin: 0.2rem 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
label.enc-radio:hover {
  background: var(--brand-primary-soft, rgba(11,61,102,0.08));
  border-color: var(--border);
}
label.enc-radio input[type="radio"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--brand-primary, #0b3d66);
}
label.enc-radio span { line-height: 1.3; }
label.enc-radio em.muted {
  font-style: normal;
  font-size: 0.85em;
  color: var(--muted);
}
