/* =====================================================================
   Rattay · Ungarn-Rechnungen — App Stylesheet
   Design: Clean, calm, trustworthy office tool.
   Typeface: system-ui / Segoe UI stack — familiar, sharp, efficient.
   Accent: Rattay Rot #c8102e — used sparingly for authority.
   ===================================================================== */

/* ── 1. Custom Properties ─────────────────────────────────────────── */
:root {
  /* Palette – Light */
  --color-bg:           #f4f5f7;
  --color-surface:      #ffffff;
  --color-surface-2:    #f8f9fb;
  --color-text:         #1a1d21;
  --color-text-muted:   #6b7280;
  --color-border:       #e5e7eb;
  --color-border-focus: #c8102e;

  /* Accent */
  --color-accent:       #c8102e;
  --color-accent-hover: #a60d26;
  --color-accent-weak:  #fdf1f3;
  --color-accent-text:  #ffffff;

  /* Status badge colours */
  --badge-done-bg:        #d1fae5;
  --badge-done-text:      #065f46;
  --badge-review-bg:      #fef3c7;
  --badge-review-text:    #92400e;
  --badge-error-bg:       #fee2e2;
  --badge-error-text:     #991b1b;
  --badge-processing-bg:  #dbeafe;
  --badge-processing-text:#1e40af;
  --badge-queued-bg:      #f3f4f6;
  --badge-queued-text:    #374151;

  /* Shadows */
  --shadow-card:  0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
  --shadow-card-hover: 0 4px 12px rgba(0,0,0,.10), 0 1px 3px rgba(0,0,0,.06);
  --shadow-topbar: 0 1px 0 var(--color-border);

  /* Geometry */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-pill: 999px;

  /* Motion */
  --transition: 150ms ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:           #0f1115;
    --color-surface:      #181b20;
    --color-surface-2:    #1e2228;
    --color-text:         #e7e9ec;
    --color-text-muted:   #9aa1ab;
    --color-border:       #2a2e35;
    --color-border-focus: #e0253f;

    --color-accent:       #e0253f;
    --color-accent-hover: #c8102e;
    --color-accent-weak:  #2a1219;

    --badge-done-bg:        #052e16;
    --badge-done-text:      #86efac;
    --badge-review-bg:      #2d1f04;
    --badge-review-text:    #fcd34d;
    --badge-error-bg:       #2d0a0a;
    --badge-error-text:     #fca5a5;
    --badge-processing-bg:  #0c1a3a;
    --badge-processing-text:#93c5fd;
    --badge-queued-bg:      #1f2329;
    --badge-queued-text:    #9ca3af;

    --shadow-card:      0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
    --shadow-card-hover:0 4px 16px rgba(0,0,0,.5), 0 1px 4px rgba(0,0,0,.35);
    --shadow-topbar:    0 1px 0 var(--color-border);
  }
}

/* ── 2. Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── 3. Typography ────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

h1 { font-size: 1.5rem;   margin-bottom: 1rem; }
h2 { font-size: 1.2rem;   margin-bottom: .75rem; }
h3 { font-size: 1.05rem;  margin-bottom: .6rem; }

p  { margin-bottom: .5rem; }

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

/* ── 4. Topbar ────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1.5rem;
  height: 52px;
  background: var(--color-surface);
  box-shadow: var(--shadow-topbar);
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--color-accent);
  letter-spacing: .02em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex-wrap: wrap;
}

.topbar nav a {
  color: var(--color-text-muted);
  font-size: .875rem;
  font-weight: 500;
  padding: .35rem .65rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}

.topbar nav a:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  text-decoration: none;
}

/* ── 5. Main Content Area ─────────────────────────────────────────── */
main {
  max-width: 1160px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 3rem;
}

/* ── 6. Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.25rem;
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

/* ── 7. Buttons ───────────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1;
  padding: .5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background var(--transition),
    border-color var(--transition),
    box-shadow var(--transition),
    opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;

  /* Primary style by default */
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-color: var(--color-accent);
}

button:hover:not(:disabled), .btn:hover:not(:disabled) {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  box-shadow: 0 2px 6px rgba(200,16,46,.25);
}

button:active:not(:disabled), .btn:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled, .btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

/* Secondary / outline variant */
.btn-secondary, button.secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled),
button.secondary:hover:not(:disabled) {
  background: var(--color-surface-2);
  border-color: var(--color-text-muted);
  box-shadow: none;
}

/* Small variant */
.btn-sm {
  font-size: .8rem;
  padding: .35rem .7rem;
}

/* Inline-form buttons that appear next to text */
form[style*="inline"] button {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
  font-size: .8rem;
  padding: .3rem .65rem;
}

form[style*="inline"] button:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  border-color: var(--color-text-muted);
  box-shadow: none;
}

/* ── 8. Forms & Inputs ────────────────────────────────────────────── */
label {
  display: block;
  font-size: .8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: .35rem;
  letter-spacing: .03em;
  text-transform: uppercase;
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
select {
  font-family: inherit;
  font-size: .875rem;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .5rem .75rem;
  width: 100%;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="search"]:focus,
input[type="password"]:focus,
select:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(200,16,46,.12);
}

input::placeholder { color: var(--color-text-muted); opacity: .7; }

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  padding-right: 2.25rem;
  -webkit-appearance: none;
  appearance: none;
}

/* File input */
input[type="file"] {
  font-size: .875rem;
  color: var(--color-text-muted);
  background: none;
  border: none;
  padding: 0;
  width: auto;
}

/* .row — horizontal flex layout for form rows */
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: .65rem;
  margin-bottom: .75rem;
}

.row label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  margin-bottom: 0;
}

.row input[type="text"],
.row input[type="email"],
.row select {
  width: auto;
  min-width: 200px;
}

/* .searchbar — input grows + button flush right */
.searchbar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1.25rem;
}

.searchbar input {
  flex: 1;
  min-width: 0;
}

/* ── 9. Upload / Dropzone ─────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition:
    border-color var(--transition),
    background var(--transition);
  margin-bottom: 1rem;
  background: var(--color-surface-2);
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--color-accent);
  background: var(--color-accent-weak);
}

.dropzone p {
  color: var(--color-text-muted);
  font-size: .875rem;
  margin-bottom: .75rem;
}

.dropzone input[type="file"] {
  display: block;
  margin: .5rem auto 0;
}

/* Upload card specific layout */
.card .upload-hint {
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-top: .5rem;
}

/* Simple upload form (non-dropzone) spacing */
.card form:not(.searchbar):not(.row) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
}

/* ── 10. Tables (.grid) ───────────────────────────────────────────── */
.grid-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1px; /* bleed to card edge on mobile */
}

.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.grid thead th {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.grid thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.grid thead th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

.grid tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.grid tbody tr:last-child { border-bottom: none; }

.grid tbody tr:hover { background: var(--color-surface-2); }

.grid tbody td {
  padding: .7rem 1rem;
  vertical-align: middle;
  color: var(--color-text);
}

.grid tbody td a {
  font-weight: 500;
}

/* Zahlenspalten (Mengen, Preise) rechtsbündig + tabellarische Ziffern */
.grid th.num, .grid td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Kein Umbruch (Datum, Rechnungsnr., kompakte Spalten) */
.grid td.nowrap { white-space: nowrap; }

/* Aktionsspalte: kompakt, rechtsbündig */
.grid td.actions { white-space: nowrap; text-align: right; }
.grid td.actions form { display: inline; }

/* Quelle-Chip (Browser / E-Mail) */
.src {
  display: inline-block;
  font-size: .68rem;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: 0 .4em;
  margin-left: .3em;
  vertical-align: middle;
}

/* Öffnen-Button blau */
.btn-open {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}
.btn-open:hover:not(:disabled) {
  background: #1d4ed8;
  border-color: #1d4ed8;
  box-shadow: 0 2px 6px rgba(37, 99, 235, .25);
}

/* Löschen als kleines rotes ✕ (hohe Spezifität, schlägt form[inline] button) */
.actions .btn-del {
  background: transparent;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  padding: .25rem .45rem;
  font-size: .8rem;
  line-height: 1;
  margin-left: .35rem;
}
.actions .btn-del:hover:not(:disabled) {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
  box-shadow: none;
}

/* Wrap table in a scrollable div if not already — applied via template */
.card .grid {
  /* tables inside cards don't need extra wrapper if card handles overflow */
}

/* ── 11. Status Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .2em .65em;
  border-radius: var(--radius-pill);
  font-size: .73rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}

.badge-done       { background: var(--badge-done-bg);       color: var(--badge-done-text); }
.badge-review     { background: var(--badge-review-bg);     color: var(--badge-review-text); }
.badge-error      { background: var(--badge-error-bg);      color: var(--badge-error-text); }
.badge-processing { background: var(--badge-processing-bg); color: var(--badge-processing-text); }
.badge-queued     { background: var(--badge-queued-bg);     color: var(--badge-queued-text); }

/* ── 12. Detail Split View ────────────────────────────────────────── */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.viewer {
  width: 100%;
  height: 70vh;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  display: block;
  margin-top: .5rem;
}

/* Seiten-Vorschau als Bilder (browser-unabhängig, kein PDF-Download) */
.pageview {
  max-height: 72vh;
  overflow-y: auto;
  margin-top: .5rem;
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
  padding: .5rem;
}

.pageimg {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  margin-bottom: .5rem;
}

.pageimg:last-child { margin-bottom: 0; }

/* ── 13. Login Page ───────────────────────────────────────────────── */
.login {
  max-width: 400px;
  margin: 5vh auto 0;
}

.login h1 {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
}

.login label {
  display: block;
  margin-bottom: .35rem;
}

.login input[type="email"] {
  margin-bottom: .85rem;
}

.login button {
  width: 100%;
  padding: .6rem 1rem;
  font-size: .925rem;
}

.login p {
  font-size: .875rem;
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ── 14. Utility Classes ──────────────────────────────────────────── */
.muted {
  color: var(--color-text-muted);
  font-size: .875rem;
}

.err {
  color: var(--badge-error-text);
  background: var(--badge-error-bg);
  border-radius: var(--radius-sm);
  padding: .45rem .8rem;
  font-size: .875rem;
  border: 1px solid rgba(153,27,27,.2);
  margin-bottom: .5rem;
}

/* ── 15. Detail page meta row ─────────────────────────────────────── */
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  margin-bottom: 1rem;
  color: var(--color-text-muted);
  font-size: .875rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .25rem;
  align-items: center;
}

.detail-actions a {
  display: inline-flex;
  align-items: center;
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  font-size: .8rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  background: var(--color-surface);
  transition: background var(--transition), border-color var(--transition);
}

.detail-actions a:hover {
  background: var(--color-surface-2);
  border-color: var(--color-text-muted);
  text-decoration: none;
}

/* ── 16. Responsive ───────────────────────────────────────────────── */
@media (max-width: 640px) {
  .topbar {
    padding: 0 1rem;
    height: 48px;
  }

  main {
    padding: 1rem .75rem 2.5rem;
  }

  .card {
    padding: 1.1rem 1.1rem;
    border-radius: var(--radius-md);
  }

  .topbar nav a {
    padding: .3rem .45rem;
    font-size: .8rem;
  }

  .grid thead th,
  .grid tbody td {
    padding: .55rem .65rem;
  }
}

/* ── 17. Scrollbar (subtle) ───────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* ── 18. Focus Visible (accessibility) ───────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 3px;
}
