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

:root {
  --primary: #1a6bb5;
  --primary-dark: #145a9e;
  --success: #2e7d32;
  --danger: #c62828;
  --warning: #f57c00;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde1e7;
  --text: #1a1a2e;
  --text-secondary: #5a6a7a;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body {
  font-family: 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-size: 15px;
  line-height: 1.5;
}

/* Navbar */
.navbar {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}
.nav-brand { display: flex; align-items: center; gap: 8px; }
.nav-version { color: rgba(255,255,255,0.8); font-size: 14px; align-self: center; font-weight: 600; }
.nav-logo { height: 48px; width: auto; object-fit: contain; background: white; border-radius: 6px; padding: 3px 8px; }
.nav-links { display: flex; gap: 8px; flex: 1; justify-content: center; }
.nav-links a { color: rgba(255,255,255,0.85); text-decoration: none; padding: 6px 16px; border-radius: var(--radius); font-size: 14px; transition: background 0.15s; }
.nav-links a:hover, .nav-links a.active { background: rgba(255,255,255,0.18); color: white; }

/* Nav user */
.nav-user { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,0.25); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.user-name { font-size: 14px; font-weight: 600; }
.user-role { font-size: 12px; color: rgba(255,255,255,0.7); background: rgba(255,255,255,0.12); padding: 2px 8px; border-radius: 10px; }
.logout-btn { color: rgba(255,255,255,0.75); text-decoration: none; font-size: 13px; padding: 4px 10px; border-radius: var(--radius); border: 1px solid rgba(255,255,255,0.3); transition: background 0.15s; }
.logout-btn:hover { background: rgba(255,255,255,0.15); color: white; }

/* Container */
.container { max-width: 1100px; margin: 0 auto; padding: 28px 20px; }

/* Page header */
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 26px; font-weight: 700; margin-top: 8px; }
.subtitle { color: var(--text-secondary); margin-top: 4px; }
.back-link { color: var(--primary); text-decoration: none; font-size: 14px; }
.back-link:hover { text-decoration: underline; }
.tag-code-header { display: inline-block; background: var(--primary); color: white; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 4px; letter-spacing: 0.5px; }
.record-meta { display: flex; align-items: center; gap: 14px; margin-top: 10px; flex-wrap: wrap; }
.meta-item { color: var(--text-secondary); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; border: none; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b71c1c; }
.btn-lg { padding: 12px 28px; font-size: 15px; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* Alert */
.alert { padding: 14px 18px; border-radius: var(--radius); margin-bottom: 20px; font-weight: 500; }
.alert-success { background: #e8f5e9; color: var(--success); border: 1px solid #a5d6a7; }

/* Cards grid */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px; box-shadow: var(--shadow);
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); transform: translateY(-2px); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tag-code { font-size: 13px; font-weight: 700; color: var(--primary); letter-spacing: 0.5px; }
.tag-badge { font-size: 12px; padding: 3px 10px; border-radius: 20px; background: var(--bg); color: var(--text-secondary); }
.badge-active { background: #e3f2fd; color: var(--primary); }
.card-title { font-size: 16px; font-weight: 700; line-height: 1.4; margin-bottom: 16px; }
.card-stats { display: flex; gap: 20px; margin-bottom: 18px; }
.stat { text-align: center; }
.stat-num { display: block; font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-secondary); }
.card-actions { display: flex; gap: 10px; }

/* Form sections */
.form-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 17px; font-weight: 700; color: var(--primary);
  margin-bottom: 18px; padding-bottom: 10px;
  border-bottom: 2px solid var(--primary);
}

/* Fields grid */
.fields-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.field-full { grid-column: 1 / -1; }
.field-group { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.required { color: var(--danger); margin-right: 2px; }
.field-input, .field-textarea {
  padding: 8px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; font-family: inherit;
  direction: rtl; transition: border-color 0.15s;
  background: white;
}
.field-input:focus, .field-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,107,181,0.1); }
.field-textarea { resize: vertical; }
.radio-group { display: flex; gap: 16px; padding-top: 6px; flex-wrap: wrap; }
.radio-label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }
.radio-label input { accent-color: var(--primary); }

/* Table toolbar */
.table-toolbar { display: flex; justify-content: flex-start; margin-bottom: 6px; }
.btn-check-all { background: #e8f5e9; color: var(--success); border: 1px solid #a5d6a7; }
.btn-check-all:hover { background: #c8e6c9; }

/* Steps table */
.steps-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
  margin-top: 8px;
}
.steps-table th {
  background: #f0f4f8; padding: 10px 12px; text-align: center;
  font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.steps-table th.col-action { text-align: right; }
.steps-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.steps-table tr:last-child td { border-bottom: none; }
.steps-table tr:hover { background: #fafbfc; }
.col-num { width: 52px; text-align: center; font-weight: 700; color: var(--primary); }
.col-action { text-align: right; line-height: 1.5; }
.col-result { width: 70px; text-align: center; }
.col-notes { width: 180px; }
.center { text-align: center; }
.step-check { accent-color: var(--primary); width: 18px; height: 18px; cursor: pointer; }
.notes-input { width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; }
.notes-input:focus { outline: none; border-color: var(--primary); }
.reading-field { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.reading-input { padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; width: 130px; }

/* Row states */
.row-ok { background: #f1f8e9 !important; }
.row-fail { background: #fce4e4 !important; }

/* Result icons */
.result-ok { color: var(--success); font-size: 18px; font-weight: 700; }
.result-fail { color: var(--danger); font-size: 18px; font-weight: 700; }
.result-empty { color: #bbb; }

/* Equipment table */
.equipment-grid { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.equipment-grid th.eq-header { background: #f0f4f8; padding: 7px 10px; text-align: right; font-weight: 600; border: 1px solid var(--border); white-space: nowrap; width: 120px; }
.equipment-grid td { border: 1px solid var(--border); padding: 4px 6px; }
.eq-input { width: 100%; padding: 5px 8px; border: none; font-size: 13px; }

/* Assembler QC note */
.assembler-note-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.assembler-note-label { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; }
.assembler-note-input { width: 160px; }

/* Fill-all / clear buttons */
.btn-fill-lin { background: #fff8e1; color: var(--warning); border: 1px solid #ffe082; }
.btn-fill-lin:hover { background: #fff3cd; }
.btn-clear-lin { background: #fce4e4; color: var(--danger); border: 1px solid #ef9a9a; }
.btn-clear-lin:hover { background: #ffcdd2; }

/* Corners diagram */
.corners-diagram { display: inline-block; border: 2px solid var(--border); border-radius: 8px; padding: 10px; background: #fafafa; margin-top: 8px; direction: rtl; }
.cd-row { display: flex; gap: 8px; margin-bottom: 8px; }
.cd-row:last-child { margin-bottom: 0; }
.cd-middle { justify-content: center; }
.cd-cell { min-width: 130px; }
.cd-empty { min-width: 130px; }
.cd-corner { border: 2px solid var(--primary); border-radius: 6px; padding: 8px 10px; background: white; display: flex; flex-direction: column; gap: 4px; }
.cd-center { border-color: var(--warning); }
.cd-num { font-size: 13px; font-weight: 700; color: var(--primary); }
.cd-center .cd-num { color: var(--warning); }
.cd-input { width: 100%; padding: 5px 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; text-align: center; }
.cd-dev { width: 100%; padding: 4px 6px; border: 1px solid #e0e0e0; border-radius: 4px; font-size: 12px; text-align: center; background: #f5f5f5; color: var(--text-secondary); }
.cd-note { font-size: 11px; color: var(--text-secondary); margin-top: 6px; }

/* Extra fields */
.extra-field-section, .extra-view { margin-top: 20px; }
.extra-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; color: var(--text); }

/* Linearity / corners tables */
.linearity-table, .corners-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.linearity-table th, .corners-table th {
  background: #f0f4f8; padding: 8px 10px; text-align: center;
  font-weight: 600; border: 1px solid var(--border);
}
.linearity-table td, .corners-table td {
  padding: 7px 10px; border: 1px solid var(--border); text-align: center;
}
.table-input { width: 80px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; text-align: center; font-size: 13px; }
.table-input:focus { outline: none; border-color: var(--primary); }
.allowed { color: var(--warning); font-weight: 600; }
.bold { font-weight: 700; }

/* Linearity/corner validation colors */
.td-dev input[readonly] { background: #f8f8f8; cursor: default; font-weight: 600; }
.table-input.valid   { background: #e8f5e9 !important; border-color: #66bb6a !important; color: #1b5e20 !important; font-weight: 600; }
.table-input.invalid { background: #fce4e4 !important; border-color: #ef5350 !important; color: #b71c1c !important; font-weight: 600; }

/* Final result auto highlight */
input[name="final_result"][value="עבר"]:checked + span,
.radio-label:has(input[name="final_result"][value="עבר"]:checked) { color: var(--success); font-weight: 700; }
input[name="final_result"][value="נכשל"]:checked + span,
.radio-label:has(input[name="final_result"][value="נכשל"]:checked) { color: var(--danger); font-weight: 700; }

/* Auto-filled user field */
.field-auto-user { background: #f0f7ff; border-color: #90c4f0; }
.field-auto-user:focus { border-color: var(--primary); }

/* Signature row */
.signature-row { display: flex; gap: 20px; margin-top: 16px; flex-wrap: wrap; }
.sig-field { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 5px; }
.sig-field label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }

/* Form actions */
.form-actions {
  display: flex; gap: 14px; justify-content: flex-end;
  padding: 20px 0; margin-top: 8px;
}

/* Record view */
.record-actions { display: flex; gap: 10px; margin-bottom: 24px; flex-wrap: wrap; }
.view-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.view-fields { display: flex; flex-wrap: wrap; gap: 14px 28px; }
.view-field { display: flex; align-items: baseline; gap: 6px; }
.view-label { font-size: 13px; color: var(--text-secondary); font-weight: 600; white-space: nowrap; }
.view-value { font-size: 14px; font-weight: 500; }
.signature-display { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border); }
.reading-display { margin-top: 6px; font-size: 13px; color: var(--text-secondary); }

/* Status badges */
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-submitted { background: #e8f5e9; color: var(--success); }
.status-draft { background: #fff8e1; color: var(--warning); }

/* Filters bar */
.filters-bar { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 20px; box-shadow: var(--shadow); }
.filters-form { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 160px; }
.filter-group label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.filter-select, .filter-input { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; background: white; }
.filter-select:focus, .filter-input:focus { outline: none; border-color: var(--primary); }

/* Results header */
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.results-count { font-weight: 600; color: var(--text-secondary); }

/* Records table */
.records-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.records-table th { background: #f0f4f8; padding: 11px 14px; text-align: right; font-weight: 600; border-bottom: 2px solid var(--border); font-size: 13px; }
.records-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.records-table tr:last-child td { border-bottom: none; }
.records-table tr:hover td { background: #f8fafc; }
.tag-code-sm { font-size: 12px; font-weight: 700; color: var(--primary); background: #e3f2fd; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { color: var(--text-secondary); margin-bottom: 16px; font-size: 16px; }

/* Login page */
.login-page { background: linear-gradient(135deg, #1a6bb5 0%, #0d4a8a 100%); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-container { width: 100%; max-width: 520px; padding: 20px; }
.login-logo { text-align: center; margin-bottom: 16px; }
.login-logo img { height: 70px; width: auto; object-fit: contain; background: white; border-radius: 8px; padding: 6px 14px; }
.login-title { text-align: center; color: white; font-size: 22px; font-weight: 700; margin-bottom: 24px; }
.login-card { background: white; border-radius: 12px; padding: 24px; margin-bottom: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.18); }
.login-card h2 { font-size: 16px; font-weight: 700; color: var(--text-secondary); margin-bottom: 16px; }
.login-divider { text-align: center; color: rgba(255,255,255,0.7); margin: 8px 0; font-size: 13px; }
.login-divider span { background: rgba(255,255,255,0.15); padding: 4px 14px; border-radius: 20px; }
.new-user-form { display: flex; flex-direction: column; gap: 12px; }
.user-select-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.user-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 10px; border: 2px solid var(--border); border-radius: 10px; background: white; cursor: pointer; transition: all 0.15s; text-align: center; }
.user-tile:hover { border-color: var(--primary); background: #e8f0fb; transform: translateY(-2px); }
.user-tile-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 700; }
.user-tile-name { font-size: 14px; font-weight: 600; color: var(--text); }
.user-tile-role { font-size: 12px; color: var(--text-secondary); }

/* Users table */
.row-inactive td { opacity: 0.5; }
.user-avatar-sm { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: white; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.badge-you { font-size: 11px; background: #e3f2fd; color: var(--primary); padding: 2px 7px; border-radius: 10px; margin-right: 6px; font-weight: 600; }

/* Permission badges */
.user-perm-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.perm-admin   { background: #fce4e4; color: var(--danger); }
.perm-manager { background: #e8f0fb; color: var(--primary); }
.perm-worker  { background: #e8f5e9; color: var(--success); }
.user-tile .user-perm-badge { margin-top: 2px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal-box { background: white; border-radius: 12px; padding: 28px; width: 100%; max-width: 400px; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }

/* Alert error */
.alert-error { background: #fce4e4; color: var(--danger); border: 1px solid #ef9a9a; }

/* English (LTR) overrides */
html[lang="en"] body { direction: ltr; }
html[lang="en"] .field-input,
html[lang="en"] .field-textarea,
html[lang="en"] .filter-input,
html[lang="en"] .filter-select,
html[lang="en"] .table-input,
html[lang="en"] .notes-input,
html[lang="en"] .reading-input,
html[lang="en"] .eq-input { direction: ltr; text-align: left; }
html[lang="en"] .steps-table th.col-action,
html[lang="en"] .col-action { text-align: left; }
html[lang="en"] .records-table th { text-align: left; }
html[lang="en"] .equipment-grid th.eq-header { text-align: left; }
html[lang="en"] .corners-diagram { direction: ltr; }

/* Print */
@media print {
  .navbar, .record-actions, .btn, .back-link { display: none !important; }
  .container { max-width: 100%; padding: 0; }
  .view-section, .form-section { box-shadow: none; border: 1px solid #ccc; }
  body { font-size: 12px; }
}

/* Responsive */
@media (max-width: 600px) {
  .fields-grid { grid-template-columns: 1fr; }
  .filters-form { flex-direction: column; }
  .form-actions { flex-direction: column; }
  .signature-row { flex-direction: column; }
}
