:root {
  --primary: #2CB5A0;
  --primary-dark: #1E8C7A;
  --primary-deep: #16705F;
  --bg-light: #F0FAF8;
  --bg-medium: #E0F5F1;
  --text-dark: #1F2937;
  --text-medium: #4B5563;
  --text-light: #9CA3AF;
  --white: #FFFFFF;
  --gray-bg: #F9FAFB;
  --border: #D1D5DB;
  --border-light: #E5E7EB;
  --red: #DC2626;
  --green: #16A34A;
  --orange: #D97706;
}

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

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: linear-gradient(135deg, var(--bg-light) 0%, var(--gray-bg) 100%);
  color: var(--text-dark);
  min-height: 100vh;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Pokud je editor viditelný, body je top-aligned */
body.editor-active {
  align-items: flex-start;
}

.container {
  width: 100%;
  max-width: 460px;
}

body.editor-active .container {
  max-width: 960px;
  margin: 0 auto;
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 24px;
}

.logo-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.logo-icon {
  flex-shrink: 0;
}

.app-header h1 {
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 2px;
}

.subtitle {
  color: var(--text-medium);
  font-size: 0.8rem;
  margin-top: 2px;
}

/* Form Card */
.form-card {
  background: var(--white);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 4px 24px rgba(44, 181, 160, 0.08), 0 1px 4px rgba(0, 0, 0, 0.04);
  border-top: 4px solid var(--primary);
}

.form-title {
  font-size: 1.1rem;
  color: var(--text-dark);
  margin-bottom: 24px;
  text-align: center;
  font-weight: 600;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-dark);
  font-size: 0.85rem;
}

select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  background: var(--white);
  color: var(--text-dark);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(44, 181, 160, 0.12);
}

select:disabled {
  background-color: var(--gray-bg);
  cursor: not-allowed;
  opacity: 0.7;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

/* ── Buttons ── */
.btn-primary {
  padding: 13px 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* V step-select je tlačítko full-width */
#step-select .btn-primary {
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-deep) 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(44, 181, 160, 0.3);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  padding: 10px 18px;
  background: var(--white);
  color: var(--text-dark);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: var(--gray-bg);
  border-color: var(--text-light);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.85rem;
  border-radius: 8px;
}

.btn-icon {
  font-size: 1.1rem;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 6px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Messages */
.error-message {
  margin-top: 16px;
  padding: 12px 16px;
  background: #FEF2F2;
  color: var(--red);
  border-radius: 10px;
  font-size: 0.85rem;
  border: 1px solid #FECACA;
}

.success-message {
  margin-top: 16px;
  padding: 12px 16px;
  background: #F0FDF4;
  color: var(--green);
  border-radius: 10px;
  font-size: 0.85rem;
  border: 1px solid #BBF7D0;
}

/* ── Editor Section ── */
.editor-section {
  width: 100%;
}

.editor-toolbar {
  background: var(--white);
  border-radius: 12px;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
  position: sticky;
  top: 8px;
  z-index: 100;
  border: 1px solid var(--border-light);
}

.editor-info {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-bottom-bar {
  text-align: center;
  margin: 24px 0 8px;
}

.editor-bottom-bar .btn-primary {
  width: 100%;
  max-width: 400px;
  padding: 14px 24px;
  font-size: 1rem;
}

/* ── Device Card ── */
.device-card {
  background: var(--white);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  border: 1px solid var(--border-light);
}

.device-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--bg-medium);
}

.device-card-header .device-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--white);
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.device-card-header h3 {
  font-size: 1rem;
  color: var(--text-dark);
  font-weight: 600;
}

/* ── Editable Tables ── */
.editor-table-section {
  margin-bottom: 16px;
}

.editor-table-section h4 {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-left: 2px;
}

.editor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.editor-table th {
  background: var(--bg-medium);
  color: var(--text-dark);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px 10px;
  text-align: left;
  border: 1px solid var(--border-light);
}

.editor-table td {
  padding: 6px 10px;
  border: 1px solid var(--border-light);
  vertical-align: middle;
}

.editor-table tr:nth-child(even) td {
  background: var(--gray-bg);
}

.editor-table td.label-cell {
  font-weight: 600;
  color: var(--text-dark);
  width: 140px;
  white-space: nowrap;
  background: var(--bg-light);
}

/* Editovatelné buňky */
.editor-table .editable {
  cursor: text;
  position: relative;
  min-height: 1.4em;
  outline: none;
  transition: background 0.15s;
  border-radius: 2px;
}

.editor-table .editable:hover {
  background: rgba(44, 181, 160, 0.06);
}

.editor-table .editable:focus {
  background: rgba(44, 181, 160, 0.1);
  box-shadow: inset 0 0 0 1.5px var(--primary);
}

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.status-badge.clickable {
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.status-badge.clickable:hover {
  opacity: 0.75;
}

.status-ok {
  background: #DCFCE7;
  color: var(--green);
}

.status-warn {
  background: #FEF3C7;
  color: var(--orange);
}

.status-crit {
  background: #FEE2E2;
  color: var(--red);
}

/* Security row icons */
.security-ok {
  color: var(--green);
}

.security-warn {
  color: var(--orange);
}

/* Software 2-col grid */
.sw-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.sw-grid .editor-table {
  width: 100%;
}

/* ── Add/Remove buttons ── */
.row-actions {
  white-space: nowrap;
  width: 36px;
  text-align: center;
}

.btn-remove-row {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.btn-remove-row:hover {
  background: #FEE2E2;
}

.btn-add-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px dashed var(--border);
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
  margin-top: 6px;
  transition: all 0.2s;
}

.btn-add-row:hover {
  background: var(--bg-light);
  border-color: var(--primary);
}

/* Footer */
.app-footer {
  text-align: center;
  margin-top: 20px;
  color: var(--text-light);
  font-size: 0.75rem;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .editor-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    position: static;
  }

  .editor-info {
    order: -1;
    width: 100%;
    text-align: center;
  }

  .sw-grid {
    grid-template-columns: 1fr;
  }

  .device-card {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .form-card {
    padding: 24px 20px;
  }

  .form-row {
    flex-direction: column;
    gap: 0;
  }
}


/* ── Volitelný text na titulní stranu (výkaz práce) ── */
.worklog-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.worklog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.worklog-header h3 {
  margin: 0;
  font-size: 1rem;
  color: #1E8C7A;
}

.worklog-optional {
  font-weight: 400;
  font-size: 0.85rem;
  color: #9CA3AF;
}

.worklog-help-btn {
  background: #F0FAF8;
  border: 1px solid #E0F5F1;
  color: #1E8C7A;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.worklog-help-btn:hover {
  background: #E0F5F1;
}

.worklog-hint {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: #9CA3AF;
}

/* ── Panel nástrojů editoru ── */
.rte-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 7px 9px;
  background: #F9FAFB;
  border: 1px solid #D1D5DB;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}

.rte-toolbar button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 9px;
  font-size: 0.82rem;
  color: #4B5563;
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.rte-toolbar button:hover {
  background: #E0F5F1;
  color: #16705F;
}

.rte-toolbar button.active {
  background: #2CB5A0;
  border-color: #2CB5A0;
  color: #fff;
}

.rte-sep {
  width: 1px;
  height: 20px;
  background: #D1D5DB;
  margin: 0 4px;
}

/* ── Editační plocha ── */
.rte-editor {
  border: 1px solid #D1D5DB;
  border-radius: 0 0 8px 8px;
  padding: 14px 16px;
  min-height: 160px;
  max-height: 460px;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #1F2937;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.rte-editor:focus {
  outline: none;
  border-color: #2CB5A0;
  box-shadow: 0 0 0 3px rgba(44, 181, 160, 0.15);
}

/* Zástupný text v prázdném editoru */
.rte-editor:empty::before {
  content: attr(data-placeholder);
  color: #B6BDC7;
  pointer-events: none;
}

/* Vzhled uvnitř editoru odpovídá tomu, jak to vyjde v PDF */
.rte-editor h1 {
  font-size: 1.15rem;
  color: #1E8C7A;
  margin: 10px 0 6px;
  font-weight: 600;
}

.rte-editor h2 {
  font-size: 1rem;
  color: #1F2937;
  margin: 10px 0 5px;
  font-weight: 600;
}

.rte-editor h1:first-child,
.rte-editor h2:first-child {
  margin-top: 0;
}

.rte-editor ul,
.rte-editor ol {
  margin: 4px 0 8px;
  padding-left: 24px;
}

.rte-editor li {
  margin-bottom: 3px;
}

.rte-editor hr {
  border: none;
  border-top: 1px solid #D1D5DB;
  margin: 10px 0;
}

.rte-editor b,
.rte-editor strong {
  font-weight: 600;
}
