/* ============================================================
 * Rechnungstool-Hub — CSS
 * ============================================================ */

:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;
  --text: #1c1917;
  --text-muted: #78716c;
  --text-subtle: #a8a29e;
  --accent: #0891b2;
  --accent-hover: #0e7490;
  --accent-soft: #ecfeff;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 6px;
  --radius-sm: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--ui-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
.muted { color: var(--text-muted); }
.dim { color: var(--text-subtle); padding: 20px; text-align: center; }
.mono { font-family: ui-monospace, Menlo, Monaco, monospace; }
.small { font-size: 12px; }

/* Layout */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar-bg, var(--surface));
  border-right: 1px solid var(--sidebar-border, var(--border));
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  color: var(--sidebar-text, var(--text));
}
.sidebar-brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  margin-bottom: 28px;
  color: var(--sidebar-text, var(--text));
  min-height: 20px;
  display: flex;
  align-items: center;
}
.sidebar-logo {
  max-height: var(--sidebar-logo-height, 40px);
  max-width: 180px;
  object-fit: contain;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  padding: 8px 0;
  color: var(--sidebar-text, var(--text));
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: all 0.25s ease-in-out;
}
.sidebar nav a:hover   { background: var(--sidebar-hover, #f5f5f4); padding: 8px 10px; }
.sidebar nav a.active  { background: var(--sidebar-active, var(--accent-soft)); color: var(--sidebar-active-text, var(--accent-hover)); padding: 8px 10px; font-weight: 500; }
.sidebar-meta {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid var(--sidebar-border, var(--border));
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--sidebar-text-subtle, var(--text-subtle));
}
.sidebar-meta a { color: var(--sidebar-text-subtle, var(--text-subtle)); }
.sidebar-meta a:hover { color: var(--sidebar-text, var(--text)); }

.main { padding: 32px 40px; max-width: 1200px; }

/* Page Head */
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.page-head .sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
}
.btn:hover { background: #f5f5f4; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-row { display: flex; gap: 8px; align-items: center; }

/* Forms */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}
input[type=text], input[type=password], input[type=file], textarea, select {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* List rows */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr 1.3fr auto;
  gap: 20px;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.list-row:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.list-row.release-row {
  grid-template-columns: 2fr 1fr auto;
  cursor: default;
}
.list-row.release-row:hover { border-color: var(--border); box-shadow: none; }
.list-cell .name { font-weight: 500; font-size: 14px; margin-bottom: 2px; }
.list-cell .sub  { font-size: 12px; color: var(--text-muted); }
.list-cell .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
  margin-bottom: 2px;
}
.list-cell.right { text-align: right; }

.release-changelog {
  margin-top: 8px;
  padding: 8px 10px;
  background: #fafaf9;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border-radius: 12px;
  white-space: nowrap;
  margin-right: 6px;
}
.badge.status-active       { background: #dcfce7; color: #166534; }
.badge.status-deactivated  { background: #fee2e2; color: #991b1b; }
.badge.warn                { background: #fef3c7; color: #92400e; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 32px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty-state p:first-child { font-weight: 500; margin-bottom: 6px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  max-width: 520px;
  width: calc(100% - 40px);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}
.modal-box h2 { font-size: 17px; font-weight: 600; margin-bottom: 16px; }

.key-display {
  background: #f5f5f4;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: ui-monospace, Menlo, Monaco, monospace;
  font-size: 12px;
  word-break: break-all;
  user-select: all;
  margin: 14px 0;
}

/* Login */
body.login-locked { overflow: hidden; }
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.login-box {
  background: var(--surface);
  padding: 32px 36px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-error {
  margin-top: 12px;
  padding: 8px 12px;
  background: #fee2e2;
  color: #991b1b;
  border-radius: var(--radius-sm);
  font-size: 12px;
}

/* Toast */
#toast-root {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow);
  transform: translateX(100%);
  opacity: 0;
  transition: transform 0.25s, opacity 0.25s;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

/* Mobile */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 20px; }
  .list-row { grid-template-columns: 1fr; gap: 8px; }
}

/* Icon-Button (z.B. Refresh in Tenant-Zeile) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover {
  background: #f5f5f4;
  color: var(--text);
  border-color: var(--text-muted);
}
.btn-icon:disabled { opacity: 0.5; cursor: wait; }
.btn-icon.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Settings-View */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 640px;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.logo-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.logo-row img {
  max-height: 40px;
  max-width: 140px;
  object-fit: contain;
  background: #fafaf9;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}
.color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.color-row input[type=color] {
  width: 40px;
  height: 32px;
  padding: 2px;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

/* Login-Logo */
.login-logo {
  max-width: 160px;
  max-height: 48px;
  object-fit: contain;
  margin: 0 auto 16px;
  display: block;
}

/* Dark-Mode: kleine Farb-Anpassung für Border im Dark-Mode */
body:has(.sidebar[style*="--sidebar-bg"]) .sidebar {
  transition: background 0.25s;
}

/* Settings-View: Card-System (aus Rechnungstool übernommen) */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.btn-ghost {
  border-color: transparent;
}
.btn-ghost:hover {
  background: #f5f5f4;
  border-color: transparent;
}
.logo-uploader .logo-preview-wrap {
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fafaf9;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.color-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.color-input-row input[type="color"] {
  width: 60px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
}
.color-input-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-input-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }
textarea.code-input {
  font-family: ui-monospace, SFMono-Regular, 'Cascadia Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px;
  background: #1c1917;
  color: #f5f5f4;
  border: 1px solid #44403c;
  border-radius: var(--radius-sm);
  resize: vertical;
  min-height: 100px;
  tab-size: 2;
}
textarea.code-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8,145,178,0.15);
}
.mt-16 { margin-top: 16px; }

/* Update-verfügbar-Badge + Accent-Icon-Button */
.badge.update-available {
  background: var(--accent-soft);
  color: var(--accent-hover);
  margin-top: 4px;
  display: inline-block;
}
.btn-icon.btn-icon-accent {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-icon.btn-icon-accent:hover {
  background: var(--accent-soft);
  border-color: var(--accent-hover);
  color: var(--accent-hover);
}
