:root {
  --primary: #E31D1A;
  --primary-dark: #c41815;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #dde1e7;
  color: var(--gray-900);
  line-height: 1.5;
}

/* ─── Header ──────────────────────────────────── */
.header {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 0 1.5rem;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0.5rem;
  z-index: 100;
  max-width: calc(1400px - 3rem);
  margin: 0.5rem auto 0;
  width: calc(100% - 3rem);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.header-left { display: flex; align-items: center; gap: 2rem; }
.logo-img { height: 36px; }
.header-title {
  font-family: 'Poppins', 'Segoe UI', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--primary);
  text-transform: uppercase;
  margin-right: 1.5rem;
}
.header-nav { display: flex; gap: 0.5rem; align-items: center; }
.header-nav a {
  text-decoration: none;
  color: var(--gray-500);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.header-nav a:hover {
  background: var(--primary);
  color: #fff;
}
.header-nav a.active {
  background: var(--primary);
  color: #fff;
}
.header-search {
  display: flex;
  margin-left: 0.5rem;
}
.header-search input {
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.88rem;
  outline: none;
  width: 180px;
}
.header-search input:focus { border-color: var(--primary); }
.header-search button {
  padding: 0.4rem 0.8rem;
  background: var(--gray-500);
  color: #fff;
  border: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.15s;
}
.header-search button:hover { background: var(--primary); }

/* ─── Main ────────────────────────────────────── */
.main { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ─── Status filter tabs ──────────────────────── */
.status-tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.status-tab {
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  background: #fff;
  text-decoration: none;
  color: var(--gray-700);
  font-size: 0.82rem;
  white-space: nowrap;
  transition: all 0.15s;
}
.status-tab:hover { border-color: var(--primary); color: var(--primary); }
.status-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.status-tab .badge {
  display: inline-block;
  background: rgba(0,0,0,0.1);
  padding: 0 0.4rem;
  border-radius: 10px;
  font-size: 0.75rem;
  margin-left: 0.25rem;
}
.status-tab.active .badge { background: rgba(255,255,255,0.3); }

/* ─── Table ───────────────────────────────────── */
.table-wrap {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
th {
  background: var(--gray-50);
  padding: 0.6rem 0.75rem;
  text-align: left;
  font-weight: 600;
  color: var(--gray-700);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: top;
}
tr:hover td { background: var(--gray-50); }
tr.row-link { cursor: pointer; }

.col-id { width: 60px; font-weight: 600; color: var(--primary); }
.col-date { width: 90px; white-space: nowrap; color: var(--gray-500); font-size: 0.82rem; }
.col-customer { min-width: 140px; }
.col-customer .name { font-weight: 500; }
.col-customer .contact { font-size: 0.8rem; color: var(--gray-500); }
.customer-link { color: inherit; text-decoration: none; border-bottom: 1px dotted #999; }
.customer-link:hover { color: var(--primary); border-bottom-color: var(--primary); }
.col-device { min-width: 120px; }
.col-fault { min-width: 180px; max-width: 300px; }
.col-fault .text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Status badges */
.stav {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}
.stav-prijato { background: #dbeafe; color: #1e40af; }
.stav-pracuje { background: #fef3c7; color: #92400e; }
.stav-dily { background: #fce7f3; color: #9d174d; }
.stav-zakaznik { background: #e0e7ff; color: #3730a3; }
.stav-pripraveno { background: #dcfce7; color: #166534; }
.stav-vyzvednuto { background: var(--gray-100); color: var(--gray-500); }
.stav-neprijato { background: #fee2e2; color: #991b1b; }
.stav-reklamace { background: #fee2e2; color: #991b1b; font-weight: 600; }

/* ─── Age coloring ────────────────────────────── */
tr.age-green td { border-left: 3px solid #16a34a; }
tr.age-green td:first-child { background: #f0fdf4; }
tr.age-yellow td { border-left: 3px solid #f59e0b; }
tr.age-yellow td:first-child { background: #fffbeb; }
tr.age-orange td { border-left: 3px solid #ea580c; }
tr.age-orange td:first-child { background: #fff7ed; }
tr.age-red td { border-left: 3px solid #dc2626; }
tr.age-red td:first-child { background: #fef2f2; }

/* ─── Pagination ──────────────────────────────── */
.pagination {
  display: flex;
  gap: 0.25rem;
  justify-content: center;
  margin-top: 1rem;
}
.pagination a, .pagination span {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--gray-700);
  font-size: 0.85rem;
}
.pagination a:hover { background: var(--gray-100); }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── Forms ───────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.card-prijem { border-left: 3px solid #3b82f6; background: #f8faff; }
.card-vydej  { border-left: 3px solid #16a34a; background: #f7fdf9; }
.card-subtitle {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-700);
  margin: 1.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px dashed var(--gray-300);
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--gray-200);
  color: var(--gray-700);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--gray-500);
}
.form-group input, .form-group select, .form-group textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(192,57,43,0.1);
}
.form-group textarea { resize: vertical; min-height: 60px; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* ─── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline {
  background: #fff;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.82rem; }

/* ─── Material table in detail ────────────────── */
.material-add {
  display: flex;
  gap: 0.5rem;
  align-items: end;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.material-add input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.85rem;
}
.material-add .m-nazev { flex: 2; min-width: 150px; }
.material-add .m-sn { flex: 1; min-width: 100px; }
.material-add .m-cena { width: 110px; }
.material-add .m-pocet { width: 70px; }

.total-row { font-weight: 600; }
.total-row td { border-top: 2px solid var(--gray-300); }

/* ─── Autocomplete ────────────────────────────── */
.autocomplete-wrap { position: relative; display: flex; gap: 0.5rem; }
.autocomplete-wrap input { flex: 1; min-width: 0; }
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--gray-300);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  display: none;
}
.autocomplete-list.show { display: block; }
.autocomplete-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.88rem;
}
.autocomplete-item:hover { background: var(--gray-100); }
.autocomplete-item .ac-name { font-weight: 500; }
.autocomplete-item .ac-phone { color: var(--gray-500); font-size: 0.82rem; }

/* ─── Files ──────────────────────────────────── */
.file-list { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.file-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--gray-50);
}
.file-thumb { flex-shrink: 0; }
.file-thumb img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--gray-200);
}
.file-icon { font-size: 2rem; flex-shrink: 0; width: 60px; text-align: center; }
.file-info { flex: 1; min-width: 0; }
.file-name {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-name:hover { text-decoration: underline; }
.file-meta { font-size: 0.78rem; color: var(--gray-500); }
.file-upload-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.file-upload-label input[type="file"] { display: none; }
.file-upload-label .btn { cursor: pointer; }

/* ─── Print ───────────────────────────────────── */
@media print {
  body { background: #fff; }
  .header, .toolbar, .status-tabs, .pagination, .no-print { display: none !important; }
  .main { padding: 0; max-width: 100%; }
  .card { border: none; padding: 0; box-shadow: none; }
}

/* ─── Print pages ─────────────────────────────── */
.print-page {
  font-family: 'Segoe UI', Arial, sans-serif;
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  background: #fff;
  position: relative;
}
.print-page > * { position: relative; z-index: 1; }
.print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #333;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}
.print-company { font-size: 0.85rem; color: #555; }
.print-company strong { font-size: 1rem; color: #000; }
.print-company-main { margin-bottom: 0.2rem; }
.print-contacts { font-size: 0.78rem; color: #777; }
.print-title {
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1rem;
}
.print-number { font-size: 1.1rem; color: var(--primary); }
.print-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 2rem;
  margin-bottom: 1rem;
}
.print-field { display: flex; gap: 0.5rem; padding: 0.25rem 0; border-bottom: 1px dotted #ccc; }
.print-field .label { font-weight: 600; min-width: 120px; font-size: 0.85rem; color: #555; }
.print-field .value { font-size: 0.9rem; flex: 1; }
.print-field.full { grid-column: 1 / -1; }
.print-section {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0.8rem 0 0.3rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #999;
  page-break-inside: avoid;
}
.print-signature {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 2rem;
  page-break-inside: avoid;
}
.sig-img {
  display: block;
  height: 57px;
  margin: 0 auto 0.25rem;
}
.print-signature .sig-line {
  border-top: 1px solid #333;
  padding-top: 0.25rem;
  text-align: center;
  font-size: 0.82rem;
  color: #555;
}
.print-blank-page { display: none; }
.print-divider {
  border: none;
  border-top: 2px dashed #999;
  margin: 2rem 0;
}
.print-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
}
.print-table th, .print-table td {
  border: 1px solid #ccc;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
}
.print-table th { background: #f5f5f5; font-weight: 600; }

.print-terms {
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid #ccc;
  page-break-inside: avoid;
}
.print-terms-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  margin-bottom: 0.4rem;
}
.print-terms p {
  font-size: 0.65rem;
  line-height: 1.4;
  color: #666;
  margin: 0.2rem 0;
}
.print-terms p strong {
  color: #333;
}

@page {
  margin: 0;
  size: A4;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  html, body {
    margin: 0;
    padding: 0;
  }
  .print-page {
    padding: 12mm 12mm;
    max-width: 100%;
    margin: 0;
  }
  .print-actions { display: none !important; }
  .print-divider { display: none; }
  .print-blank-page {
    display: block;
    page-break-before: always;
    page-break-after: always;
    height: 0;
  }
  .print-page + .print-page,
  .print-divider + .print-page { page-break-before: always; }
}

/* ─── Responsive ──────────────────────────────── */
@media (max-width: 768px) {
  .header { padding: 0 1rem; }
  .main { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .print-grid { grid-template-columns: 1fr; }
  .header { flex-wrap: wrap; padding: 0.5rem 1rem; gap: 0.5rem; }
  .header-nav { width: 100%; justify-content: center; flex-wrap: wrap; }
  .header-search { width: 100%; }
  .header-search input { flex: 1; width: auto; }
}

/* ─── Payment badges ─────────────────────────── */
.platba-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}
.platba-hotove { background: #dcfce7; color: #166534; }
.platba-kartou { background: #dbeafe; color: #1e40af; }
.platba-prevodem { background: #f3e8ff; color: #6b21a8; }

/* ─── Footer ──────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--gray-500);
  font-size: 0.82rem;
}
.footer a { color: var(--gray-500); text-decoration: none; }
.footer a:hover { color: var(--primary); }
