:root {
  --bg: #0b0d10;
  --card: #171b1f;
  --border: #262b31;
  --cyan: #00ccff;
  --text: #f4f6f8;
  --text-dim: #a7b0b8;
  --danger: #ff5c5c;
  --ok: #4ade80;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Arial, sans-serif;
  line-height: 1.5;
}

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: #14171b;
  border-bottom: 1px solid var(--border);
}

.admin-header .brand { font-weight: 800; letter-spacing: 0.03em; }
.admin-header .brand span { color: var(--cyan); }

.admin-nav { display: flex; gap: 6px; flex-wrap: wrap; font-size: 0.9rem; font-weight: 600; }
.admin-nav a { padding: 6px 10px; border-radius: 5px; transition: background 0.15s ease, color 0.15s ease; }
.admin-nav a.active { color: var(--cyan); background: rgba(0, 204, 255, 0.12); }
.nav-divider { width: 1px; align-self: stretch; background: var(--border); margin: 4px 4px; }

.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 30px 24px 60px; }
/* Für Seiten mit breiteren Tabellen (viele Aktions-Links pro Zeile, z.B. Archiv/Bestand) -
   verhindert unnötiges horizontales Scrollen auf breiten Bildschirmen. */
.admin-wrap-wide { max-width: 1400px; }

h1 { font-size: 1.6rem; margin-bottom: 6px; }
h2 { font-size: 1.2rem; margin: 30px 0 12px; }
.subtitle { color: var(--text-dim); margin-bottom: 26px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
  margin-bottom: 20px;
  overflow-x: auto;
}

label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.02em; }

input[type=text], input[type=password], input[type=email], input[type=date], input[type=url], input[type=number], input[type=search], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.95rem;
  margin-bottom: 16px;
}

textarea { min-height: 160px; resize: vertical; }

input[type=file] { display: block; margin-bottom: 20px; color: var(--text); }

.file-thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-right: 10px; background: var(--bg); }

.name-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-cell a { max-width: 100%; }

/* Eigene Variante statt .row-actions-inner: bei bis zu 4 Aktionen pro Zeile (Umbenennen,
   Verschieben, Download/ZIP, Löschen) sollen die Buttons bei Platzmangel umbrechen statt die
   Tabelle in die Breite zu drücken - anders als .row-actions-inner (dort schiebt
   "form:last-child { margin-left:auto }" den letzten Button absichtlich ganz nach rechts,
   was hier zusätzlichen Leerraum erzwingen würde). */
.file-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-actions form { display: inline; }

/* Eigener Dropdown-Pfeil statt dem nativen: mobile Browser (v.a. iOS Safari) zeigen bei
   <select> von Haus aus gar keinen sichtbaren Pfeil an - am PC ist er da, am Handy fehlt er
   komplett. appearance:none entfernt den (unsichtbaren) nativen Pfeil überall einheitlich,
   das SVG-Pfeilchen als Hintergrundbild ersetzt ihn auf allen Geräten gleich. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a7b0b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
}

.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; text-transform: none; font-weight: 500; }

.btn {
  display: inline-block;
  background: var(--cyan);
  color: #08222b;
  border: none;
  padding: 11px 22px;
  border-radius: 4px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.btn:hover { opacity: 0.88; text-decoration: none; }
.btn.btn-danger { background: var(--danger); color: #2a0808; }
.btn.btn-outline { background: #232830; border: 1px solid var(--border); color: var(--text); }
.btn.btn-small { padding: 6px 12px; font-size: 0.78rem; }

.alert { padding: 12px 16px; border-radius: 4px; margin-bottom: 20px; font-size: 0.9rem; }
.alert-ok { background: rgba(74,222,128,0.12); border: 1px solid var(--ok); color: var(--ok); }
.alert-error { background: rgba(255,92,92,0.12); border: 1px solid var(--danger); color: var(--danger); }

table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--text-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; }
.badge-rechnung { background: rgba(74,222,128,0.15); color: var(--ok); }
.badge-angebot { background: rgba(0,204,255,0.12); color: var(--cyan); }
.badge-kostenvoranschlag { background: rgba(255,190,92,0.15); color: #ffbe5c; }
.badge-demo { background: rgba(255,92,92,0.12); color: var(--danger); }
.badge-e-invoice { background: rgba(0,204,255,0.12); color: var(--cyan); }
/* Für die Rollen-Anzeige im Reiter Accounts (Hauptadmin/Admin). */
.badge-published { background: rgba(74,222,128,0.15); color: var(--ok); }
.badge-draft { background: rgba(167,176,184,0.15); color: var(--text-dim); }

.row-actions-inner { display: flex; align-items: center; gap: 10px; white-space: nowrap; width: 100%; }
.row-actions-inner form { display: inline; }
.row-actions-inner form:last-child { margin-left: auto; }

.qty-control { display: flex; align-items: center; justify-content: center; gap: 10px; }
.qty-control form { display: inline; }
.table-scroll { overflow-x: auto; }
.table-scroll table { white-space: nowrap; }

.drag-handle { cursor: grab; font-size: 1.2rem; color: var(--text-dim); touch-action: none; user-select: none; padding: 4px 6px; }
.table-scroll tr.dragging { position: relative; z-index: 20; background: var(--card); box-shadow: 0 6px 16px rgba(0,0,0,0.35); cursor: grabbing; }
.table-scroll tr.dragging .drag-handle { cursor: grabbing; }
.table-scroll tr.drag-placeholder td { padding: 0; border-top: 2px dashed var(--cyan); border-bottom: none; background: transparent; }

/* Drag & Drop zum Verschieben von Dateien/Ordnern in der Dateien-Ansicht (dateien.php). */
.file-row-drag { cursor: grab; }
.file-row-drag.dragging-source { opacity: 0.4; }
tr.drop-target-hover, a.drop-target-hover {
  outline: 2px dashed var(--cyan);
  outline-offset: -2px;
  background: rgba(0, 204, 255, 0.1);
}
a.drop-target-hover { border-radius: 4px; padding: 1px 4px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 30px; }
.stat-box { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 18px; }
.stat-box .num { font-size: 1.8rem; font-weight: 800; color: var(--cyan); }
.stat-box .label { color: var(--text-dim); font-size: 0.82rem; margin-top: 4px; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 32px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 20px; }

/* Positionszeilen im Rechnungsformular */
#items-table th, #items-table td { padding: 6px; vertical-align: top; }
#items-table td input { margin-bottom: 0; }
/* Bezeichnungsfeld als Textarea statt einzeiligem Input, damit man den Zeilenumbruch
   selbst per Enter setzen kann (wird 1:1 so auf der PDF übernommen) - wächst per JS
   automatisch mit dem Inhalt statt eine Scrollbar zu zeigen. */
#items-table .desc-input {
  min-height: unset;
  height: 40px;
  resize: none;
  overflow: hidden;
  line-height: 1.35;
  margin-bottom: 0;
}
#items-table .col-desc { width: 45%; }
#items-table .col-qty { width: 12%; }
#items-table .col-price { width: 18%; }
#items-table .col-total { width: 18%; text-align: right; padding-top: 16px; white-space: nowrap; }
#items-table .col-del { width: 40px; }
#items-table .col-del button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1.1rem; padding: 8px; }

.totals-box { max-width: 340px; margin-left: auto; margin-top: 16px; }
.totals-box .totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.92rem; color: var(--text-dim); }
.totals-box .totals-row.grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; font-size: 1.15rem; font-weight: 800; color: var(--text); }

@media (max-width: 640px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .back-to-top { right: 14px; bottom: 14px; width: 42px; height: 42px; }
}

/* "Nach oben"-Button, gleiches Design wie auf der Website - taucht erst nach
   etwas Scrollen auf. */
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(11, 13, 16, 0.85);
  border: 1.5px solid var(--cyan);
  color: var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease, color 0.15s ease;
}
.back-to-top svg { width: 20px; height: 20px; }
.back-to-top.is-visible { opacity: 1; pointer-events: auto; transform: translateY(0); }
.back-to-top:hover { background: var(--cyan); color: #08222b; }

/* Am Handy/Tablet: Logo über die Navigation stellen (statt nebeneinander), und
   die Navigation zu einer einzeiligen, seitlich wegwischbaren Leiste machen
   statt in die Höhe umzubrechen. */
@media (max-width: 900px) {
  .admin-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .admin-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .admin-nav a { flex: 0 0 auto; white-space: nowrap; }
}

/* Positionstabelle im Rechnungsformular: auf schmalen Bildschirmen wird aus jeder Zeile
   eine kleine Karte mit beschrifteten Feldern statt einer zu eng gequetschten Tabellenzeile. */
@media (max-width: 640px) {
  #items-table thead { display: none; }
  #items-table, #items-table tbody, #items-table tr, #items-table td { display: block; width: 100%; }
  #items-table .item-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 12px; }
  #items-table td { padding: 4px 0; border-bottom: none; }
  #items-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-dim);
    margin-bottom: 2px;
  }
  /* Die Desktop-Spaltenbreiten (.col-desc/.col-qty/.col-price als %-Anteil der Tabellenbreite)
     würden die Eingabefelder hier sonst winzig schmal machen, da eine %-Breite auf einer
     Klasse spezifischer ist als das width:100% auf #items-table td weiter oben - deshalb
     hier explizit wieder auf volle Breite setzen. */
  #items-table .col-desc, #items-table .col-qty, #items-table .col-price { width: 100%; }
  #items-table .col-total { font-size: 1.05rem; font-weight: 700; }
  #items-table .col-del { text-align: right; }
  #items-table .col-del button { font-size: 0.85rem; }
}
