/* === VARIABLES === */
:root {
  --primary: #4a7c59;
  --primary-dark: #346045;
  --accent: #aed9e0;
  --accent-hover: #89c2d9;
  --error: #e74c3c;
  --error-dark: #c0392b;
  --bg: #f8f9fa;
  --card: #fff;
  --text: #333;
  --border: #ddd;
}

/* === RESET === */
*, *::before, *::after {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* === LAYOUT === */
#app, #loginScreen, .container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* === HIDDEN === */
.hidden {
  display: none !important;
}

/* === LOGIN === */
.centered-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.centered-screen form {
  background: var(--card);
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.centered-screen label {
  font-weight: 600;
  color: var(--primary);
}
.centered-screen input {
  padding: 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 16px;
}
.centered-screen button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-weight: 600;
  cursor: pointer;
  font-size: 16px;
}
.centered-screen button:hover {
  background: var(--primary-dark);
}
.error-msg {
  color: var(--error);
  font-weight: 600;
  font-size: 14px;
  margin-top: 4px;
}

/* === APP HEADER === */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 24px 0;
  flex-wrap: wrap;
  gap: 16px;
}
header h1 {
  color: var(--primary);
  font-size: 28px;
  margin: 0;
}
.header-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.header-actions button,
.controls button,
.modal-actions button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: var(--text);
}
.header-actions button:hover,
.controls button:hover,
.modal-actions button:hover {
  background: var(--accent-hover);
  color: white;
}
#logoutBtn {
  background: var(--primary);
  color: white;
}
#logoutBtn:hover {
  background: var(--primary-dark);
}
.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
}
.btn-link:hover {
  background: #f0f8ff;
  text-decoration: underline;
}

/* === CONTROLS === */
.controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.controls input {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}

/* === TABLE === */
.table-container {
  background: var(--card);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 120px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 1000px;
}
th, td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background-color: #f5f7f9;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  padding: 10px 8px;
}
th:hover {
  background-color: #eef2f5;
}
th:not(.wide-col),
td:not(.wide-col) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.wide-col {
  max-width: 220px;
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}

/* === ACTION BUTTONS === */
.action-cell {
  text-align: center;
  white-space: nowrap;
  padding: 8px !important;
}
.action-buttons {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.action-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #555;
  transition: all 0.2s;
}
.action-btn:hover {
  background: #f0f8ff;
  border-color: var(--primary);
  color: var(--primary);
}
.action-btn.delete-btn:hover {
  color: var(--error);
  border-color: var(--error);
}

/* === MODAL === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--card);
  width: 95%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  position: relative;
  padding: 24px;
}
.close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #999;
}
.close:hover {
  color: #666;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin: 16px 0;
}
.form-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--primary);
}
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.form-field textarea {
  min-height: 80px;
  resize: vertical;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

/* === PAGINATION === */
.pagination {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  gap: 8px;
}
.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  border-radius: 4px;
}
.pagination button.active {
  background: var(--primary);
  color: white;
}
.pagination button:hover:not(.active) {
  background: #f0f0f0;
}

/* === SUMMARY BAR === */
.summary {
  margin: 12px 0;
  color: #666;
  font-size: 14px;
}

/* === TOAST NOTIFICATIONS === */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 6px;
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 2000;
  animation: fadeInOut 3s ease-in-out;
}
@keyframes fadeInOut {
  0% { opacity: 0; transform: translateY(20px); }
  10% { opacity: 1; transform: translateY(0); }
  90% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(20px); }
}
.toast.success { background: var(--primary); }
.toast.error { background: var(--error); }

/* === DETAIL MODAL === */
.detail-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}
.detail-modal:not(.hidden) {
  opacity: 1;
  visibility: visible;
}
.detail-modal-content {
  background: white;
  width: 95%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  padding: 20px;
  position: relative;
  font-size: 14px;
}
.detail-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #999;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-close:hover {
  color: #666;
  background: #f0f0f0;
  border-radius: 50%;
}
.detail-field {
  display: flex;
  align-items: flex-start;
  padding: 10px 0;
  gap: 8px;
  word-break: break-word;
  line-height: 1.4;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}
.detail-field::before {
  content: attr(data-label) ": ";
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 100px;
  text-align: right;
  padding-right: 12px;
  font-size: 14px;
}
.detail-wide {
  padding: 16px 0 0 0;
  border-top: 1px solid #eee;
  margin-top: 10px;
  word-break: break-word;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}
.detail-wide::before {
  content: attr(data-label) ":";
  display: block;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
  font-size: 14px;
  border-bottom: 1px solid #eee;
  padding-bottom: 8px;
}

/* === 3-LEVEL PRIORITY STYLING (NO BARS) === */
tr.priority-critical td {
  background-color: #fff5f5 !important;
}
tr.priority-critical:hover td {
  background-color: #feecec !important;
}

tr.priority-less td {
  background-color: #f0f7fb !important;
}
tr.priority-less:hover td {
  background-color: #e0f0f8 !important;
}

/* Optional: Emoji in Ticket column */
td[data-label="Ticket"].priority-critical::before { content: "🔴 "; }
td[data-label="Ticket"].priority-less::before { content: "⬇️ "; }

/* === MOBILE VIEW === */
@media (max-width: 700px) {
  body { font-size: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .header-actions, .controls { flex-direction: column; }
  .header-actions button, .controls button { padding: 12px; font-size: 15px; }
  .table-container { margin: 0 -20px; padding: 0 20px; }
  thead { display: none; }
  tr { display: block; background: white; border: 1px solid #ddd; border-radius: 10px; padding: 12px; margin-bottom: 10px; }
  td[data-label="Ticket"] { font-weight: 700; color: var(--primary); margin-bottom: 4px; }
  td[data-label="Case Details"] { margin-bottom: 12px; }
  td.action-cell { padding-top: 8px; }
  .action-buttons { gap: 10px; }
  .action-btn { width: 36px; height: 36px; border-radius: 8px; }
  td:not([data-label="Ticket"]):not([data-label="Case Details"]):not(.action-cell) { display: none !important; }
}

/* === PRINT === */
@media print {
  .header-actions, .controls, .pagination, .modal, .detail-close, .action-cell { display: none !important; }
  #app { padding: 0 !important; }
  header h1 { text-align: center; margin: 20px 0; }
  .table-container { border: 1px solid #ddd; }
  table { font-size: 12pt; }
  th, td { padding: 8px; }
  .wide-col { max-width: none; word-wrap: break-word; white-space: normal; }
}

/* === CASE DETAILS HOVER PREVIEW === */
.case-detail-tooltip {
  position: absolute;
  background: var(--primary);
  color: white;
  padding: 10px;
  border-radius: 6px;
  font-size: 13px;
  max-width: 400px;
  z-index: 1001;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  white-space: pre-wrap;
  word-break: break-word;
  pointer-events: none;
  display: none;
}

/* === CHRONOLOGY REPORT MODAL === */
#recordDetails {
  font-size: 14px;
}
.record-detail-row {
  display: flex;
  margin-bottom: 8px;
}
.record-label {
  font-weight: bold;
  width: 120px;
  color: var(--primary);
}
.record-value {
  flex: 1;
}
.chrono-timeline-entry {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}
.chrono-time {
  font-weight: bold;
  min-width: 80px;
  color: var(--primary);
}
.chrono-desc {
  flex: 1;
  padding-left: 12px;
}

/* Preserve formatting in case details */
.case-details-formatted {
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 13px;
  background: #f0f0f0;
  padding: 8px;
  border-radius: 4px;
  margin-top: 4px;
}

