/* AS POS — UAT Tracker | light theme, RTL-first, logical properties */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .18);
  --font: "Segoe UI", "Tahoma", "Noto Kufi Arabic", "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ------------------------------- buttons ------------------------------- */

.btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: var(--primary-soft); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); border-color: #fecaca; }
.btn-danger-ghost:hover:not(:disabled) { background: #fef2f2; }
.btn-block { width: 100%; }
.btn-lang { margin-top: 10px; width: 100%; background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

/* ------------------------------- login ------------------------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.login-logo { font-size: 40px; text-align: center; }
.login-title { text-align: center; margin: 6px 0 0; font-size: 24px; letter-spacing: .5px; }
.login-subtitle { text-align: center; color: var(--text-2); margin: 4px 0 22px; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text-2); }
.password-wrap { position: relative; }
.password-wrap input {
  width: 100%;
  padding: 10px 40px 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-family: var(--font);
}
[dir="rtl"] .password-wrap input { padding: 10px 12px 10px 40px; }
.password-wrap input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.toggle-password {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  inset-inline-end: 8px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  opacity: .6;
  padding: 4px;
}
.toggle-password:hover { opacity: 1; }
.login-error {
  margin-top: 10px;
  padding: 8px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
}
#login-submit { margin-top: 16px; }

/* ------------------------------- topbar ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 26px; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: .4px; }
.brand-sub { font-size: 12px; color: var(--text-2); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------- cards ------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 16px 20px 4px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
  border-inline-start: 4px solid var(--border-strong);
}
.stat-card:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.stat-card .stat-value { font-size: 22px; font-weight: 800; line-height: 1.2; }
.stat-card .stat-label { font-size: 12px; color: var(--text-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-card.stat-total { border-inline-start-color: var(--text); }
.stat-cards-title {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-3);
  margin: 8px 0 -2px;
}

/* ------------------------------- filters ------------------------------- */

.filterbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding: 12px 20px;
}
.filterbar select,
.filter-search {
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.filterbar select:focus, .filter-search:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.filter-search { flex: 1 1 220px; min-width: 160px; }
.archived-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }

/* ------------------------------- table ------------------------------- */

.table-wrap {
  margin: 0 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 250px);
}
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.items-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: start;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  z-index: 5;
}
.items-table tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.items-table tbody tr { cursor: pointer; }
.items-table tbody tr:hover { background: var(--surface-2); }
.items-table tbody tr.row-archived { opacity: .55; }
.col-id { width: 78px; }
.col-date { width: 96px; }
.col-title { min-width: 260px; }
.col-module { min-width: 140px; }
.col-priority, .col-severity, .col-status { width: 120px; }
.col-owner, .col-reporter { min-width: 110px; }
.cell-id { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--text-3); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.cell-muted { color: var(--text-2); }

.status-select {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  max-width: 170px;
  appearance: auto;
}

/* status badge colors */
.st-new                { background: #e0e7ff; color: #3730a3; border-color: #c7d2fe; }
.st-in-progress        { background: #dbeafe; color: #1d4ed8; border-color: #bfdbfe; }
.st-fixed              { background: #dcfce7; color: #15803d; border-color: #bbf7d0; }
.st-closed             { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.st-working-as-designed{ background: #f3e8ff; color: #7e22ce; border-color: #e9d5ff; }
.st-needs-details      { background: #fef3c7; color: #b45309; border-color: #fde68a; }
.st-product-decision   { background: #fce7f3; color: #be185d; border-color: #fbcfe8; }
.st-cannot-reproduce   { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.st-data-issue         { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }
.st-deferred           { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }
.st-other              { background: #f1f5f9; color: #334155; border-color: #e2e8f0; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-archived { background: #f1f5f9; color: #64748b; border-color: var(--border); margin-inline-start: 8px; }
.p-p0 { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.p-p1 { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }
.p-p2 { background: #fef9c3; color: #a16207; border-color: #fde68a; }
.p-p3 { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.sev-blocker { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.sev-critical { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.sev-major { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }
.sev-minor { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.sev-other { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }

.empty-state { padding: 40px; text-align: center; color: var(--text-3); }

/* ------------------------------- drawer ------------------------------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  inset-inline-end: 0;
  width: min(680px, 96vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  border-inline-start: 1px solid var(--border);
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.drawer-id { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }
.drawer-close { font-size: 15px; padding: 5px 10px; }
.drawer-body { overflow-y: auto; padding: 18px 20px 28px; flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-field.span-2 { grid-column: span 2; }
.form-field label { font-size: 12px; font-weight: 700; color: var(--text-2); }
.form-field input,
.form-field select,
.form-field textarea {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  resize: vertical;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }

.drawer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}
.save-status { font-size: 13px; color: var(--text-2); }
.save-status.ok { color: #15803d; }
.save-status.err { color: var(--danger); }

/* ------------------------------- notes ------------------------------- */

.notes-section { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 16px; }
.notes-section h3 { margin: 0 0 12px; font-size: 14px; }
.notes-timeline { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.note-entry {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.note-meta { font-size: 12px; color: var(--text-2); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; }
.note-author { font-weight: 700; color: var(--text); }
.note-text { white-space: pre-wrap; word-break: break-word; }
.notes-empty { color: var(--text-3); font-size: 13px; }
.note-form { display: flex; flex-direction: column; gap: 8px; }
.note-form input,
.note-form textarea {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  resize: vertical;
}
.note-form input:focus, .note-form textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.note-form .btn { align-self: flex-start; }
[dir="rtl"] .note-form .btn { align-self: flex-end; }

/* ------------------------------- toast ------------------------------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
.toast.toast-error { background: var(--danger); }

/* ------------------------------- responsive ------------------------------- */

@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-field.span-2 { grid-column: span 1; }
  .topbar { padding: 10px 12px; }
  .cards { padding: 12px 12px 2px; }
  .filterbar { padding: 10px 12px; }
  .table-wrap { margin: 0 12px 16px; }
}

/* ------------------------------- faceted filters ------------------------------- */

.facet { position: relative; }
.facet-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.facet-btn:hover { background: var(--surface-2); }
.facet-btn.facet-active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.facet-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 1px 7px;
}
.facet-caret { font-size: 10px; color: var(--text-3); }
.facet-panel {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0;
  min-width: 240px;
  max-width: 320px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 30;
  padding: 6px;
}
.facet-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.facet-row:hover { background: var(--surface-2); }
.facet-row input[type="checkbox"] { accent-color: var(--primary); margin: 0; flex: none; }
.facet-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.facet-count { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.facet-exclude {
  flex: none;
  width: 20px;
  height: 20px;
  line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}
.facet-exclude:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }
.facet-exclude.on { border-color: var(--danger); color: #fff; background: var(--danger); }
.facet-row.excluded .facet-value { text-decoration: line-through; color: var(--text-3); }
.facet-row.excluded input[type="checkbox"] { visibility: hidden; }
.facet-empty { padding: 10px; color: var(--text-3); font-size: 13px; }

/* ------------------------------- filter chips ------------------------------- */

.chips-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 20px 10px;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
}
[dir="rtl"] .chip { padding: 3px 10px 3px 6px; }
.chip-exclude { background: #fef2f2; border-color: #fecaca; color: var(--danger); }
.chip-x {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 11px;
  padding: 2px 4px;
  opacity: .7;
}
.chip-x:hover { opacity: 1; }
.chips-clear {
  background: none;
  border: none;
  color: var(--text-2);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}
.chips-clear:hover { color: var(--danger); }

/* ------------------------------- users panel ------------------------------- */

.users-wrap { position: relative; }
.users-panel {
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-end: 0;
  width: 280px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 30;
  padding: 12px 14px;
}
.users-panel h4 { margin: 0 0 8px; font-size: 13px; }
.users-ul {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  columns: 1;
}
.users-ul li {
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
}
.users-ul li:last-child { border-bottom: none; }
.add-user-form { display: flex; gap: 6px; }
.add-user-form input {
  flex: 1;
  min-width: 0;
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
}
.add-user-form input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.user-status { margin-top: 8px; font-size: 12px; color: var(--text-2); min-height: 14px; }
.user-status.ok { color: #15803d; }
.user-status.err { color: var(--danger); }

/* ------------------------------- images ------------------------------- */

.images-section { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 16px; }
.images-section h3 { margin: 0 0 12px; font-size: 14px; }
.images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.image-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}
.image-card img {
  display: block;
  width: 100%;
  height: 90px;
  object-fit: cover;
  cursor: zoom-in;
}
.image-caption {
  font-size: 11px;
  color: var(--text-3);
  padding: 4px 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.image-del {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, .7);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.image-del:hover { background: var(--danger); }
.upload-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px 14px;
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.upload-zone:hover, .upload-zone:focus { border-color: var(--primary); background: var(--primary-soft); outline: none; }
.upload-zone.dragover { border-color: var(--primary); background: var(--primary-soft); border-style: solid; }
.upload-icon { font-size: 20px; }
.upload-status { margin-top: 8px; font-size: 12px; color: var(--text-2); min-height: 14px; }
.upload-status.ok { color: #15803d; }
.upload-status.err { color: var(--danger); }
.attach-badge { color: var(--text-3); font-size: 12px; font-weight: 600; }
