/* ====================================================================
   KKRE-Kassenbuch — Stylesheet (ersetzt Bootstrap 4 + Alt-style.css)
   ==================================================================== */

/* ---------------- Basis / Reset ---------------- */

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

html {
    font-family: sans-serif;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji",
        "Segoe UI Emoji", "Segoe UI Symbol";
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    background-color: #fff;
    overflow-y: scroll; /* permanente Scrollbar gegen Layout-Springen */
}

h2 {
    margin: 0 0 .5rem;
    font-size: 2rem;
    font-weight: 500;
    line-height: 1.2;
}

h5,
h6 {
    margin: 0;
}

label {
    display: inline-block;
    margin-bottom: .5rem;
}

img {
    vertical-align: middle;
    border-style: none;
}

[hidden] {
    display: none !important;
}

/* ---------------- Formular-Elemente ---------------- */

.form-control,
.custom-select {
    display: inline-block;
    height: calc(1.5em + .75rem + 2px);
    padding: .375rem .75rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: .25rem;
}

.form-control:focus,
.custom-select:focus {
    color: #495057;
    background-color: #fff;
    border-color: #80bdff;
    outline: 0;
    box-shadow: 0 0 0 .2rem rgba(0, 123, 255, .25);
}

.form-control:disabled,
.form-control[readonly] {
    background-color: #e9ecef;
    opacity: 1;
}

select.form-control[multiple] {
    height: auto;
    padding: .375rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin: 0;
}

/* Eingabegruppe mit €-Suffix */
.input-group {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: stretch;
}

.input-group .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: .375rem .5rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #495057;
    text-align: center;
    white-space: nowrap;
    background-color: #e9ecef;
    border: 1px solid #ced4da;
    border-left: 0;
    border-radius: 0 .25rem .25rem 0;
}

/* ---------------- Buttons ---------------- */

.btn {
    display: inline-block;
    font-family: inherit;
    font-weight: 400;
    color: #212529;
    text-align: center;
    vertical-align: middle;
    -webkit-user-select: none;
    user-select: none;
    background-color: transparent;
    border: 1px solid transparent;
    padding: .375rem .75rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: .25rem;
    cursor: pointer;
    transition: background-color .15s ease-in-out, border-color .15s ease-in-out;
}

.btn:disabled {
    opacity: .65;
    cursor: default;
}

.btn-sm {
    padding: .25rem .5rem;
    font-size: .875rem;
    line-height: 1.5;
    border-radius: .2rem;
}

.btn-light {
    color: #212529;
    background-color: #f8f9fa;
    border-color: #f8f9fa;
}

.btn-light:hover:not(:disabled) {
    background-color: #e2e6ea;
    border-color: #dae0e5;
}

.btn-primary {
    color: #fff;
    background-color: #007bff;
    border-color: #007bff;
}

.btn-primary:hover:not(:disabled) {
    background-color: #0069d9;
    border-color: #0062cc;
}

.btn-secondary {
    color: #fff;
    background-color: #6c757d;
    border-color: #6c757d;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #5a6268;
    border-color: #545b62;
}

.btn-success {
    color: #fff;
    background-color: #28a745;
    border-color: #28a745;
}

.btn-success:hover:not(:disabled) {
    background-color: #218838;
    border-color: #1e7e34;
}

.btn-danger {
    color: #fff;
    background-color: #dc3545;
    border-color: #dc3545;
}

.btn-danger:hover:not(:disabled) {
    background-color: #c82333;
    border-color: #bd2130;
}

.btn-block {
    display: block;
    width: 100%;
}

.btn-block + .btn-block {
    margin-top: .5rem;
}

/* ---------------- Tabellen ---------------- */

table {
    border-collapse: collapse;
}

.table {
    width: 100%;
    margin-bottom: 1rem;
    color: #212529;
}

.table th,
.table td {
    padding: .3rem;
    vertical-align: middle;
    text-align: left;
    border-top: 1px solid #dee2e6;
}

.table thead th {
    vertical-align: bottom;
    border-top: 0;
    border-bottom: 2px solid #dee2e6;
}

/* ---------------- Kopfzeile ---------------- */

header {
    background-color: #dfdfdf;
    padding: 15px;
    margin-bottom: 25px;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 15px;
}

#user-account {
    position: relative;
}

#user-account img {
    height: 38px;
    background-color: #007bff;
    border-radius: 5px;
}

#user-account img:hover {
    cursor: pointer;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    min-width: 10rem;
    padding: .5rem 0;
    margin: .125rem 0 0;
    font-size: 1rem;
    text-align: left;
    background-color: #007bff;
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: .25rem;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-header {
    padding: .5rem 1.5rem;
    margin-bottom: 0;
    font-size: .875rem;
    color: rgb(211, 211, 211);
    white-space: nowrap;
}

.dropdown-divider {
    height: 0;
    margin: .5rem 0;
    overflow: hidden;
    border-top: 1px solid rgba(255, 255, 255, .3);
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: .25rem 1.5rem;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}

.dropdown-item:hover {
    color: #000;
    background-color: rgb(211, 211, 211);
}

#mandant {
    width: auto;
    min-width: 280px;
    max-width: 100%;
}

#settings {
    min-width: 24px;
}

#btn-mandanten-setup {
    height: 24px;
    margin-top: 6px;
    display: none; /* wird per JS nur für Admins eingeblendet */
}

#btn-mandanten-setup:hover {
    cursor: pointer;
}

/* ---------------- Inhalt / Layout ---------------- */

#content {
    display: none; /* erst nach erfolgreichem Laden eines Mandanten sichtbar */
    max-width: 1140px;
    margin: 0 auto;
    padding: 0 15px;
}

#template {
    display: none;
}

#zeitraum {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
}

#zeitraum .form-control {
    width: auto;
}

#kasse {
    width: auto;
    margin-bottom: 30px;
}

#kasse td {
    padding: .3rem 1.5rem .3rem 0;
    border: 0;
}

#btn-box {
    margin-bottom: 30px;
    background-color: rgb(190, 190, 190);
    padding: 10px;
    border-radius: .2rem;
}

#btn-abschluss-month,
#btn-abschluss-reset {
    margin-right: 20px;
}

/* ---------------- Beleg-Tabelle ---------------- */

#belege tbody tr[data-id]:hover {
    background-color: rgb(190, 190, 190);
}

#belege th,
#belege td {
    white-space: nowrap;
}

#belege td:nth-of-type(3) { /* nur Buchungstext bricht um */
    white-space: normal;
}

#belege th:nth-last-of-type(2),   /* Spalte Drucken */
#belege th:nth-last-of-type(3) {  /* Spalte Edit bzw. Save */
    width: 40px;
}

#belege tbody td:nth-of-type(1) { /* Spalte "Nr." */
    text-align: right;
}

#belege tbody td:nth-of-type(2) { /* Spalte "Datum" */
    text-align: center;
}

#belege tr :nth-child(n+4) {      /* Spalten ab "Einnahmen" rechtsbündig */
    text-align: right;
}

.einnahme,
.ausgabe,
.bestand {
    white-space: nowrap;
}

.fehler-red {
    color: #f00;
}

.row-bg1 {
    background-color: #fff;
}

.row-bg2 {
    background-color: rgb(245, 245, 245);
}

/* ---------------- Eingabezeile ---------------- */

#datum {
    width: 130px; /* type=date braucht mehr Platz als die alten 90px */
}

[data-input='buchungstext'] {
    width: 100%;
    min-width: 200px;
}

[data-input='einnahme'],
[data-input='ausgabe'] {
    width: 84px !important;
    text-align: right;
}

[data-input='kostenstelle'] {
    width: 98px;
}

[data-input='konto'] {
    width: 86px;
}

.input-error {
    background-color: #f00 !important;
}

.readonly-white {
    background-color: #fff !important;
}

/* ---------------- Icons ---------------- */

.ico-split,
.ico-check,
.ico-cancel,
.ico-print,
.ico-edit,
.ico-delete,
.ico-lock {
    height: 22px;
    width: 22px;
}

.ico-split {
    transform: rotate(90deg);
    margin-top: 6px;
}

.ico-check,
.beleg-new .ico-cancel,
.beleg-new .ico-delete {
    margin-top: 8px;
}

.beleg-new .ico-cancel {
    display: none; /* nur im Edit-Modus sichtbar */
}

.ico-split:hover,
.ico-check:hover,
.ico-print:hover,
.ico-edit:hover,
.ico-cancel:hover,
.ico-delete:hover {
    cursor: pointer;
}

/* ---------------- Modale Dialoge (ui.js + statische Dialoge) ---------------- */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background-color: rgba(0, 0, 0, .5);
    overflow-y: auto;
}

.modal-box {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 2rem);
    background-color: #fff;
    border-radius: .3rem;
    box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .5);
}

.modal-lg {
    max-width: 800px; /* Mandanten-Setup / Benutzerverwaltung: breit + scrollbar */
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid #dee2e6;
}

.modal-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.5;
}

.modal-close {
    padding: 0;
    margin: -.25rem 0 0;
    background-color: transparent;
    border: 0;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    color: #000;
    opacity: .5;
    cursor: pointer;
}

.modal-close:hover {
    opacity: .75;
}

.modal-body {
    padding: 1rem;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
    padding: .75rem;
    border-top: 1px solid #dee2e6;
}

.modal-loading {
    max-width: 300px;
    padding: 1.5rem;
    text-align: center;
}

.modal-loading p {
    margin: 0;
}

.spinner {
    width: 3rem;
    height: 3rem;
    margin: 0 auto .75rem;
    border: .25em solid #007bff;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spinner-border .75s linear infinite;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}

body.modal-open {
    overflow: hidden;
}

/* ---------------- Dialog Mandanten-Setup ---------------- */

#mandant-name,
#mandant-nr {
    width: 100%;
}

#box-mandant-anfangsbestand {
    margin-top: 32px;
}

#mandant-anfangsbestand-datum {
    width: 160px;
}

#mandant-anfangsbestand {
    width: 105px !important;
    text-align: right;
}

.picker-col {
    flex: 1 1 0;
    min-width: 200px;
}

#mandant-user-select,
#mandant-user-right {
    height: 115px;
    width: 100%;
}

#box-btn-user-rights {
    padding-top: 50px;
    width: 140px;
}

/* ---------------- Dialog Benutzerverwaltung ---------------- */

#user-admin-table th,
#user-admin-table td {
    white-space: nowrap;
}

#user-admin-table input[type='password'] {
    width: 160px;
}

#user-admin-table select {
    width: auto;
}

/* ---------------- Benutzerverwaltung (/benutzer) ---------------- */

.header-title {
    flex: 1;
    font-size: 1.15rem;
    font-weight: 600;
}

.header-right {
    margin-left: auto;
}

#content-users {
    max-width: 1500px;
    margin: 0 auto;
    padding: 0 15px 40px;
}

.users-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 1rem;
}

.users-toolbar #user-filter { max-width: 320px; }
.users-toolbar #user-scope  { max-width: 220px; }

.users-count {
    color: #6c757d;
    font-size: .9rem;
}

.users-empty {
    color: #6c757d;
    text-align: center;
    padding: 2rem 0;
}

/* Feste Spaltenbreiten: sonst springt die Tabelle bei jedem Filtern um.
   Die Prozente ergeben zusammen 100 — mit table-layout:fixed passt die
   Tabelle damit auf jede Fensterbreite, ohne seitlich zu scrollen. */
.table-users {
    table-layout: fixed;
}

.table-users .col-name      { width: 21%; }
.table-users .col-mail      { width: 27%; }
.table-users .col-role      { width:  7%; }
.table-users .col-status    { width: 10%; }
.table-users .col-mandanten { width: 24%; }
.table-users .col-action    { width: 11%; text-align: right; }

/* Kein Umbruch: eine lange Adresse wird abgeschnitten und per Auslassungs-
   punkten angedeutet (vollständiger Wert im Tooltip). Zweizeilige Zellen
   machten die Liste unruhig und rissen Adressen mitten im Wort auseinander. */
.table-users tbody td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-top: .45rem;
    padding-bottom: .45rem;
}

.table-users .col-action {
    overflow: visible;
}

.table-users tbody tr:hover {
    background-color: #f1f5f9;
}

/* ---- Statusmarken ---- */

.badge {
    display: inline-block;
    padding: .12rem .45rem;
    border-radius: .25rem;
    font-size: .78rem;
    white-space: nowrap;
}

.badge-ok     { background-color: #d7f0dc; color: #17612c; }
.badge-warn   { background-color: #ffe8a1; color: #7a5b00; }
.badge-danger { background-color: #f8d3d3; color: #8b1a1a; }

/* ---- Dialog „Benutzer bearbeiten" ---- */

.user-identity {
    margin: 0 0 1.2rem;
    padding-bottom: .8rem;
    border-bottom: 1px solid #dee2e6;
    font-size: 1.05rem;
}

.user-identity-mail {
    color: #6c757d;
    font-size: .9rem;
    word-break: break-all;
}

.check-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: normal;
    cursor: pointer;
}

.form-hint {
    margin: .3rem 0 0;
    color: #6c757d;
    font-size: .85rem;
}

fieldset.form-group {
    border: 1px solid #dee2e6;
    border-radius: .25rem;
    padding: .8rem 1rem 1rem;
}

fieldset.form-group legend {
    padding: 0 .4rem;
    font-size: .9rem;
    font-weight: 600;
    color: #495057;
}

.mandanten-box {
    max-height: 150px;
    overflow-y: auto;
    padding: .4rem .6rem;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: .25rem;
}

.mandanten-list {
    margin: 0;
    padding-left: 1.2rem;
}

.mandanten-list li {
    padding: .1rem 0;
}

.mandanten-none {
    margin: 0;
    color: #6c757d;
}

/* Nur für Screenreader — die Aktionsspalte braucht keine sichtbare
   Überschrift, leer bleiben soll sie aber auch nicht. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
