/* styles.css — dark theme, responsive, color-coded rows */

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --text: #e0e0e0;
  --text-muted: #8a8a9a;
  --accent: #4fc3f7;
  --accent-hover: #81d4fa;
  --border: #2a2a4a;
  --green: #2e7d32;
  --yellow: #f9a825;
  --red: #c62828;
  --gray: #546e7a;
  --radius: 8px;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* --------------- header --------------- */

.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--accent);
}

.header h1 span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* search bar */
.search-bar {
  position: relative;
  flex: 1;
  max-width: 400px;
  min-width: 200px;
}

.search-bar input {
  width: 100%;
  padding: 8px 32px 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-bar input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.search-clear:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.search-result-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 6px 0;
}

.search-result-count strong {
  color: var(--accent);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #111;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: #3a3a5a; }

.btn-danger {
  background: var(--red);
  color: #fff;
}
.btn-danger:hover { background: #d32f2f; }

.btn-small {
  padding: 5px 12px;
  font-size: 0.8rem;
}

/* --------------- main container --------------- */

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* --------------- dashboard stats --------------- */

.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 20px;
  min-width: 120px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.stat:hover {
  background: rgba(79, 195, 247, 0.08);
  border-color: rgba(79, 195, 247, 0.3);
}

.stat:active {
  transform: scale(0.97);
}

.stat.active {
  background: rgba(79, 195, 247, 0.15);
  border-color: var(--accent);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--bg-card);
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
  user-select: none;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

thead th.sortable {
  cursor: pointer;
  transition: color 0.12s;
}

thead th.sortable:hover {
  color: var(--accent);
}

tbody tr {
  cursor: pointer;
  transition: background 0.12s;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover { background: rgba(79, 195, 247, 0.07); }

tbody td {
  padding: 10px 14px;
  vertical-align: middle;
}

/* prominent control number in table */
td.id-col {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  width: 70px;
}

td.date-col { white-space: nowrap; }
td.status-col { white-space: nowrap; }

/* color-coded indicator pip on the left of each row */
tbody tr { border-left: 4px solid transparent; }
tbody tr.row-green  { border-left-color: var(--green); }
tbody tr.row-yellow { border-left-color: var(--yellow); }
tbody tr.row-red    { border-left-color: var(--red); }
tbody tr.row-gray   { border-left-color: var(--gray); opacity: 0.7; }
tbody tr.row-none   { border-left-color: transparent; }

/* status badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-open     { background: rgba(79, 195, 247, 0.15); color: var(--accent); }
.badge-resolved { background: rgba(84, 110, 122, 0.3);  color: #90a4ae; }

/* last-update color text */
.update-green  { color: #66bb6a; }
.update-yellow { color: #fdd835; }
.update-red    { color: #ef5350; }
.update-gray   { color: #90a4ae; }
.update-none   { color: var(--text-muted); font-style: italic; }

/* --------------- detail view --------------- */

.detail-view {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.detail-header h2 {
  font-size: 1.2rem;
  color: var(--text);
}

/* prominent control number at top of detail view */
.detail-id {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: -0.5px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.detail-field {
  position: relative;
}

.detail-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-field .value {
  font-size: 0.95rem;
  word-break: break-word;
}

.detail-field.full-width {
  grid-column: 1 / -1;
}

.detail-field .value a {
  color: var(--accent);
  text-decoration: underline;
}

/* edit button (pencil) inline with field label */
.edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0 4px;
  opacity: 0.4;
  transition: opacity 0.15s;
}

.edit-btn:hover {
  opacity: 1;
  color: var(--accent);
}

/* "edited" badge next to field label */
.edited-badge {
  font-size: 0.65rem;
  color: var(--accent);
  opacity: 0.7;
  cursor: pointer;
  text-decoration: underline;
  text-transform: none;
  letter-spacing: 0;
}

.edited-badge:hover {
  opacity: 1;
}

/* inline edit mode */
.inline-edit {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  margin-top: 4px;
}

.inline-edit input,
.inline-edit select,
.inline-edit textarea {
  flex: 1;
  padding: 6px 10px;
  font-size: 0.875rem;
}

.inline-edit textarea {
  min-height: 60px;
}

.inline-edit-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.inline-edit-actions button {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* undo import banner */
.undo-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(198, 40, 40, 0.12);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text);
}

.banner-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.banner-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

/* edit history section */
.edit-history-section {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 8px;
}

.edit-history-section h3 {
  font-size: 1rem;
  margin-bottom: 14px;
  color: var(--text);
}

.edit-entry {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.edit-entry .edit-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 3px;
}

.edit-entry .edit-detail {
  color: var(--text);
}

.edit-entry .edit-field-name {
  color: var(--accent);
  font-weight: 600;
}

.edit-entry .edit-old {
  color: var(--red);
  text-decoration: line-through;
  opacity: 0.7;
}

.edit-entry .edit-new {
  color: #66bb6a;
}

/* resolve confirmation bar */
.resolve-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}

.resolve-bar label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.resolve-bar input[type="date"] {
  width: auto;
  padding: 5px 10px;
  font-size: 0.85rem;
}

/* updates section */
.updates-section {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  margin-top: 8px;
}

.updates-section h3 {
  font-size: 1rem;
  margin-bottom: 14px;
  color: var(--text);
}

.update-entry {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 10px;
}

.update-entry .update-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.update-entry .update-text {
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.update-entry .update-source {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 6px;
}

.update-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.update-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.update-entry:hover .update-actions {
  opacity: 1;
}

.update-action-btn {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}

.update-action-btn:hover {
  color: var(--accent);
  background: rgba(79, 195, 247, 0.1);
}

.update-delete-btn:hover {
  color: var(--red);
  background: rgba(198, 40, 40, 0.15);
}

.update-edit-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.update-edit-form textarea {
  min-height: 80px;
  resize: vertical;
}

.update-edit-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.update-edit-controls input[type="date"] {
  width: auto;
  padding: 5px 10px;
  font-size: 0.85rem;
}

.update-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.update-form textarea {
  flex: 1;
  min-height: 60px;
  resize: vertical;
}

.update-form-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-self: flex-end;
}

.update-form-controls input[type="date"] {
  width: auto;
  padding: 5px 10px;
  font-size: 0.8rem;
}

/* --------------- modal --------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal h2 {
  margin-bottom: 20px;
  font-size: 1.15rem;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.modal-wide {
  max-width: 850px;
}

/* --------------- forms --------------- */

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

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 80px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* duplicate warning */
.dup-warning {
  background: rgba(249, 168, 37, 0.12);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  color: var(--yellow);
}

/* --------------- import wizard --------------- */

.import-steps {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.import-step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-radius: var(--radius);
}

.import-step .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--border);
  font-size: 0.75rem;
  font-weight: 600;
}

.import-step.active {
  color: var(--accent);
  font-weight: 600;
}

.import-step.active .step-num {
  background: var(--accent);
  color: #111;
}

.import-step.done .step-num {
  background: var(--green);
  color: #fff;
}

.import-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 18px;
}

.file-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  margin-bottom: 18px;
  transition: border-color 0.15s, background 0.15s;
}

.file-drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79, 195, 247, 0.05);
}

.file-drop-zone p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}

.file-drop-zone .file-name {
  color: var(--accent);
  font-weight: 600;
  margin-top: 10px;
  margin-bottom: 0;
}

.import-preview {
  margin-bottom: 18px;
}

.import-preview h3 {
  font-size: 0.9rem;
  margin-bottom: 10px;
  color: var(--text-muted);
}

.import-preview table {
  font-size: 0.8rem;
}

.import-preview td {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.import-preview .row-num-col {
  color: var(--text-muted);
  font-size: 0.7rem;
  width: 32px;
  text-align: center;
}

.import-preview .preview-header-row {
  background: rgba(79, 195, 247, 0.12);
  font-weight: 600;
}

.mapping-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.mapping-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  align-items: center;
  gap: 12px;
}

.mapping-label {
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}

.mapping-select {
  width: 100%;
}

.mapping-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.import-results {
  margin-bottom: 18px;
}

.import-error-log {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 18px;
}

.import-error-log h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.import-error-log ul {
  list-style: none;
  font-size: 0.8rem;
}

.import-error-log li {
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.import-error-log li:last-child {
  border-bottom: none;
}

/* --------------- empty state --------------- */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state p { font-size: 1.1rem; margin-bottom: 16px; }

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

@media (max-width: 768px) {
  .header {
    padding: 12px 16px;
    flex-direction: column;
    align-items: stretch;
  }
  .header-actions {
    flex-wrap: wrap;
  }
  .search-bar {
    max-width: 100%;
    width: 100%;
    margin: 8px 0;
  }
  .container { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-bar { gap: 10px; }
  .stat { min-width: 90px; padding: 10px 14px; }
  .stat-value { font-size: 1.2rem; }
  .update-form { flex-direction: column; }
  .update-form-controls { flex-direction: row; align-self: stretch; justify-content: space-between; }
  .update-actions { opacity: 1; }
  .modal-wide { max-width: 100%; }
  .mapping-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .mapping-hint { display: none; }
  .import-steps { gap: 2px; }
  .import-step { padding: 4px 8px; font-size: 0.75rem; }
  .detail-id { font-size: 1.4rem; }
}

@media (max-width: 480px) {
  table { font-size: 0.8rem; }
  thead th, tbody td { padding: 8px 10px; }
}

/* --------------- login / auth screens --------------- */

#loginScreen, #deniedScreen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  text-align: center;
  max-width: 360px;
  width: 100%;
}

.login-box h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
  line-height: 1.3;
}

.login-box h1 span {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.login-btn {
  width: 100%;
  justify-content: center;
  margin-bottom: 10px;
  padding: 11px 20px;
}

/* user info in header */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-email {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* loading state */
.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 1rem;
}
