/**
 * NYC Case Tracker - Main Stylesheet
 * Includes all styling with improvements for Phase 1
 */

/* ============================================================================
   BASE STYLES
   ============================================================================ */

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  padding: 1.5rem;
  background: #f5f5f7;
  line-height: 1.5;
}

h1 {
  margin-top: 0;
  font-size: 1.75rem;
  color: #111827;
}

h2 {
  font-size: 1.25rem;
  color: #111827;
  margin: 0;
}

h3 {
  font-size: 1rem;
  color: #374151;
  margin: 0.5rem 0;
}

/* ============================================================================
   LAYOUT
   ============================================================================ */

.app-container {
  max-width: 1100px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* ============================================================================
   FORM ELEMENTS
   ============================================================================ */

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 150px;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #374151;
}

input,
select,
textarea {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

/* ============================================================================
   BUTTONS
   ============================================================================ */

button {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.2s ease, transform 0.1s ease;
  font-family: inherit;
}

button:hover {
  opacity: 0.9;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.primary {
  background: #2563eb;
  color: white;
}

button.danger {
  background: #ef4444;
  color: white;
}

button.secondary {
  background: #e5e7eb;
  color: #111827;
}

button.todo-cta {
  background: #dc2626;
  color: #ffffff;
  font-weight: 600;
}

button.small-link {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  border-radius: 999px;
}

/* Loading spinner for buttons */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ============================================================================
   TABLE
   ============================================================================ */

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
  font-size: 0.85rem;
}

th,
td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f3f4f6;
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 600;
  color: #374151;
}

tbody tr {
  cursor: pointer;
  transition: background-color 0.15s ease;
}

tbody tr:hover {
  background: #f9fafb;
}

/* ============================================================================
   TAGS & BADGES
   ============================================================================ */

.tag {
  display: inline-block;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.tag-felony {
  background: #fee2e2;
  color: #b91c1c;
}

.tag-a {
  background: #e0f2fe;
  color: #1d4ed8;
}

.tag-b {
  background: #dcfce7;
  color: #166534;
}

.tag-v {
  background: #fef3c7;
  color: #92400e;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  font-size: 0.7rem;
  margin-left: 0.25rem;
}

.badge-warrant {
  background: #fee2e2;
  color: #b91c1c;
}

.badge-closed {
  background: #e5e7eb;
  color: #374151;
}

.badge-todo {
  background: #fee2e2;
  color: #b91c1c;
}

/* ============================================================================
   NCD COLORING
   ============================================================================ */

.ncd-red {
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 600;
}

.ncd-yellow {
  background: #fef9c3;
  color: #92400e;
  font-weight: 600;
}

.ncd-green {
  background: #dcfce7;
  color: #166534;
  font-weight: 600;
}

/* ============================================================================
   TABLE ROW STATES
   ============================================================================ */

.row-warrant {
  background: #fef2f2;
}

.row-closed {
  opacity: 0.6;
}

.row-ready {
  background: #eff6ff;
}

.row-todo-highlight {
  box-shadow: inset 3px 0 0 #ef4444;
}

/* ============================================================================
   SMALL TEXT & HELPER TEXT
   ============================================================================ */

.small-text {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 0.25rem;
  line-height: 1.4;
}

.todo-completed {
  color: #9ca3af;
  text-decoration: line-through;
}

/* ============================================================================
   TOP BAR & FILTERS
   ============================================================================ */

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-input {
  max-width: 260px;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  align-items: flex-start;
}

.filters-row .field-inline {
  display: flex;
  flex-direction: column;
  min-width: 160px;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.8rem;
}

.checkbox-group label {
  font-weight: 400;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.checkbox-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

/* ============================================================================
   BACKUP BAR
   ============================================================================ */

.backup-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
}

.backup-section {
  flex: 1;
  min-width: 260px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.backup-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.backup-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* ============================================================================
   QUICK ACTIONS BAR (v2.1)
   ============================================================================ */

.quick-actions-bar {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.action-btn {
  flex: 1;
  min-width: 150px;
  padding: 0.75rem 1.25rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.action-today {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.action-today:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(16, 185, 129, 0.4);
}

.action-today-small {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 1px 2px rgba(16, 185, 129, 0.2);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.action-today-small:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(16, 185, 129, 0.3);
}

.action-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 2px solid #e2e8f0;
}

.action-secondary:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.action-secondary-small {
  background: #f1f5f9;
  color: #475569;
  border: 2px solid #e2e8f0;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.action-secondary-small:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

/* ============================================================================
   DASHBOARD HEADER (NEW)
   ============================================================================ */

.dashboard-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.today-card {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: #eff6ff;
  border-left: 4px solid #93c5fd;
  transition: all 0.3s ease;
}

.today-card.busy {
  background: #fef2f2;
  border-left-color: #ef4444;
}

.today-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
  font-weight: 600;
}

.today-metric {
  font-size: 1rem;
  font-weight: 650;
  color: #111827;
}

.today-sub {
  font-size: 0.78rem;
  color: #4b5563;
}

.week-line {
  margin-left: 0.25rem;
  font-size: 0.8rem;
  color: #6b7280;
}

/* ============================================================================
   VIEW MODES
   ============================================================================ */

.view-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.view-mode {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: none;
  font-size: 0.8rem;
  background: #f3f4f6;
  color: #374151;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-mode.active {
  background: #2563eb;
  color: #ffffff;
}

/* ============================================================================
   ADVANCED FILTERS
   ============================================================================ */

.advanced-filters {
  display: none;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}

.advanced-filters .field-inline {
  min-width: 180px;
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}

.modal {
  background: #ffffff;
  border-radius: 12px;
  max-width: 700px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  cursor: pointer;
  font-size: 1.5rem;
  border: none;
  background: transparent;
  color: #6b7280;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s ease;
}

.modal-close:hover {
  background: #f3f4f6;
  color: #111827;
}

.modal-body {
  padding: 1.25rem 1.5rem;
}

/* ============================================================================
   MODAL HERO SECTION (NEW - IMPROVED UX)
   ============================================================================ */

.modal-hero {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.5rem;
  margin: -1.25rem -1.5rem 1rem;
  border-radius: 12px 12px 0 0;
}

.modal-hero h2 {
  color: white;
  margin-bottom: 1rem;
  font-size: 1.4rem;
}

.modal-key-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.info-card {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  opacity: 0.9;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.info-value {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0.25rem 0;
}

.info-subtext {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

/* ============================================================================
   MODAL SECTIONS
   ============================================================================ */

.modal-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ============================================================================
   NOTES & TODOS LISTS
   ============================================================================ */

.notes-list {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.8rem;
  line-height: 1.6;
}

.notes-list li {
  margin-bottom: 0.5rem;
}

.note-date {
  font-weight: 600;
  color: #374151;
}

/* ============================================================================
   EXCLUDABLE CALCULATOR ROWS
   ============================================================================ */

.excalc-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.4rem;
  padding: 0.5rem;
  background: #f9fafb;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}

.excalc-row input[type="date"] {
  min-width: 120px;
  flex: 0 0 auto;
}

.excalc-row input[type="text"] {
  flex: 1 1 140px;
}

.excalc-days {
  font-size: 0.8rem;
  color: #374151;
  white-space: nowrap;
  font-weight: 600;
}

.excalc-remove {
  font-size: 1.2rem;
  padding: 0.1rem 0.4rem;
}

/* ============================================================================
   CHARGES LIST (NEW)
   ============================================================================ */

.charges-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.5rem 0;
}

.charge-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: #f9fafb;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}

.charge-info {
  flex: 1;
}

.charge-name {
  font-weight: 600;
  color: #111827;
  font-size: 0.9rem;
}

.charge-statute {
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 0.2rem;
}

.charge-primary {
  background: #dbeafe;
  border-color: #93c5fd;
}

.charge-actions {
  display: flex;
  gap: 0.25rem;
}

/* ============================================================================
   APPEARANCE TYPE (NEW)
   ============================================================================ */

.appearance-type-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e0f2fe;
  color: #0369a1;
  margin-top: 0.25rem;
}

/* ============================================================================
   FOOTER
   ============================================================================ */

footer {
  margin-top: 2rem;
  font-size: 0.8rem;
  color: #6b7280;
  text-align: center;
  line-height: 1.4;
}

footer p {
  margin: 0.5rem 0;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 700px) {
  body {
    padding: 1rem;
  }

  .app-container {
    padding: 1rem;
  }

  table {
    font-size: 0.75rem;
  }

  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal {
    max-width: 95vw;
    max-height: 90vh;
  }

  .modal-key-info {
    grid-template-columns: 1fr;
  }

  .dashboard-header {
    gap: 0.35rem;
  }

  .backup-bar {
    flex-direction: column;
  }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-1 {
  margin-top: 0.5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.mb-1 {
  margin-bottom: 0.5rem;
}

.mb-2 {
  margin-bottom: 1rem;
}

/* ============================================================================
   MOBILE CARD VIEW (v2.1)
   ============================================================================ */

.mobile-cards {
  display: none;
}

.case-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.case-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid #e2e8f0;
}

.case-card-title {
  font-weight: 600;
  font-size: 1.1rem;
  color: #1e293b;
  margin-bottom: 0.25rem;
}

.case-card-subtitle {
  font-size: 0.85rem;
  color: #64748b;
}

.case-card-badge {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.case-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.case-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f1f5f9;
}

.case-card-row:last-child {
  border-bottom: none;
}

.case-card-label {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
}

.case-card-value {
  font-size: 0.85rem;
  color: #1e293b;
  text-align: right;
  font-weight: 500;
}

.case-card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 2px solid #e2e8f0;
}

.case-card-actions button {
  flex: 1;
  padding: 0.5rem;
  font-size: 0.85rem;
}

/* Mobile responsiveness */
@media screen and (max-width: 768px) {
  table {
    display: none;
  }

  .mobile-cards {
    display: block;
  }

  .quick-actions-bar {
    flex-direction: column;
  }

  .action-btn {
    width: 100%;
    min-width: 100%;
  }

  .app-container {
    padding: 0.5rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .dashboard-header {
    flex-direction: column;
  }

  .today-card {
    width: 100%;
    margin-bottom: 0.75rem;
  }

  .week-line {
    width: 100%;
  }

  .backup-bar {
    grid-template-columns: 1fr;
  }

  .backup-buttons {
    flex-direction: column;
  }

  .backup-buttons button {
    width: 100%;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .filters-row {
    flex-direction: column;
    align-items: stretch;
  }

  .field-inline {
    width: 100%;
  }

  .view-modes {
    flex-wrap: wrap;
  }

  .modal {
    width: 95%;
    max-height: 90vh;
    margin: 1rem;
  }

  .modal-hero {
    flex-direction: column;
  }

  .modal-key-info {
    flex-direction: column;
  }

  .info-card {
    width: 100%;
  }
}
