/* ReolinkANPR - Main Stylesheet */

:root {
    /* Dark mode colors (default) */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border-color: #30363d;
    --accent-color: #58a6ff;
    --accent-hover: #1f6feb;
}

body.light-mode {
    /* Light mode colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-tertiary: #ffffff;
    --text-primary: #24292f;
    --text-secondary: #57606a;
    --text-muted: #6e7781;
    --border-color: #d0d7de;
    --accent-color: #0969da;
    --accent-hover: #0550ae;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    padding-top: 76px; /* Offset for fixed navbar (increased for better mobile spacing) */
}

/* More spacing on mobile to prevent navbar overlap */
@media (max-width: 992px) {
    body {
        padding-top: 75px;
    }
}

/* Navbar */
.navbar {
    background-color: var(--bg-secondary) !important;
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem 1.25rem 1rem; /* Extra bottom padding for desktop gate status badge */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1030;
}

/* Less padding on mobile (no badge below) */
@media (max-width: 992px) {
    .navbar {
        padding: 0.75rem 1rem;
    }
}

/* Fix navbar collapse positioning on mobile */
.navbar-collapse {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
}

/* Remove absolute positioning on desktop */
@media (min-width: 992px) {
    .navbar-collapse {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        border-bottom: none;
        padding: 0;
    }
}

.navbar-brand {
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text-primary) !important;
}

/* Smaller brand font on mobile */
@media (max-width: 992px) {
    .navbar-brand {
        font-size: 1.1rem;
    }
}

.nav-link {
    color: var(--text-secondary) !important;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--accent-color) !important;
}

.nav-link.active {
    color: var(--accent-color) !important;
    font-weight: 600;
}

/* Cards */
.card {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    border-radius: 8px;
}

.card-header {
    background-color: var(--bg-tertiary) !important;
    border-bottom: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
}

/* Forms */
.form-control, .form-select {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.form-control:focus, .form-select:focus {
    background-color: var(--bg-tertiary);
    border-color: var(--accent-color);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.25rem rgba(88, 166, 255, 0.15);
}

.form-label {
    color: var(--text-primary);
    font-weight: 500;
}

/* Buttons */
.btn-primary {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

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

/* Tables */
.table {
    color: var(--text-primary);
    --bs-table-border-color: var(--border-color);
}

.table th {
    background-color: var(--bg-secondary);
    border-bottom: 2px solid var(--border-color);
    color: var(--text-secondary);
}

.table tbody tr:nth-of-type(odd) {
    background-color: #151619 !important;
    border-color: var(--border-color);
}
.table tbody tr:nth-of-type(even) {
    background-color: #0b0c0d !important;
    border-color: var(--border-color);
}

.table tbody tr:hover {
    background-color: #2c2d2e !important;
}

body.light-mode .table {
    --bs-table-bg: #ffffff;
    --bs-table-striped-bg: #f8f9fa;
    --bs-table-border-color: #dee2e6;
}

/* Light mode table overrides */
body.light-mode .table {
    color: #60656a; /* darker text in tables for light mode */
}
body.light-mode .table th {
    background-color: #f6f8fa;
}
body.light-mode .table tbody tr:nth-of-type(odd) {
    background-color: #eff1f4 !important;
}
body.light-mode .table tbody tr:nth-of-type(even) {
    background-color: #c8cacc !important;
}
body.light-mode .table tbody tr:hover {
    background-color: #dfecf8 !important;
}
/* tint icons & outline-light buttons inside tables for better contrast in light mode */
body.light-mode .table .bi, body.light-mode .table .btn-outline-light {
    color: #60656a !important;
    border-color: rgba(96,101,106,0.12) !important;
}

/* Footer */
footer {
    margin-top: 3rem;
    padding: 2rem 0;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.text-muted {
    color: var(--text-muted) !important;
}

/* Pagination */
.pagination .page-link {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--accent-color);
}

.pagination .page-link:hover {
    background-color: var(--bg-tertiary);
    color: var(--accent-color);
}

.pagination .page-item.active .page-link {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

/* Alerts */
.alert {
    border-radius: 8px;
}

/* Images */
.img-thumbnail {
    border-radius: 8px;
    border: 2px solid var(--border-color);
    background-color: var(--bg-secondary);
}

.img-thumbnail:hover {
    border-color: var(--accent-color);
    transform: scale(1.02);
    transition: all 0.2s;
}

/* Modal */
.modal-content {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.modal-header {
    border-bottom: 1px solid var(--border-color);
}

body:not(.light-mode) .btn-close {
    filter: invert(1);
}

/* Plate badge */
.plate-badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: 0.04em;
    /* slightly larger to make plates more prominent */
    font-size: 1.05rem;
}

/* Centralized rounded table wrapper and app-table styles */
.table-rounded-wrapper {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background-color: transparent; /* table controls its own header/bg */
    margin-bottom: 1rem;
}
/* inner table should not override wrapper corners */
.table-rounded-wrapper .table {
    margin-bottom: 0; /* avoid extra gap under wrapper */
    border: none;
    border-collapse: separate; /* allow rounded header/bg */
    border-spacing: 0;
}
.table-rounded-wrapper .table thead th {
    background-color: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
}
/* round header corners */
.table-rounded-wrapper .table thead th:first-child { border-top-left-radius: 12px; }
.table-rounded-wrapper .table thead th:last-child { border-top-right-radius: 12px; }

/* Table row colors (simple odd/even/hover) */
.table-rounded-wrapper .table tbody tr:nth-of-type(odd) {
    background-color: #1a1c1e !important;
}
.table-rounded-wrapper .table tbody tr:nth-of-type(even) {
    background-color: #282a2d !important;
}
.table-rounded-wrapper .table tbody tr:hover {
    background-color: #333435 !important;
}

/* ensure header cells are unaffected */
.table-rounded-wrapper .table thead th { background-color: transparent; }
/* transition */
.table-rounded-wrapper .table tbody tr, .table-rounded-wrapper .table tbody tr > td { transition: background-color .12s ease-in-out; }

/* use subtle row separators, but remove separator for the last row to avoid double bottom line */
.table-rounded-wrapper .table tbody tr td { border-bottom: 1px solid rgba(255,255,255,0.03); }
.table-rounded-wrapper .table tbody tr:last-child td { border-bottom: none; }

.table-rounded-wrapper .table td, .table-rounded-wrapper .table th { vertical-align: middle; }

/* Value-only cells used in desktop table rows (labels are shown in the table header already) */
.td-value {
  font-size: 0.95rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
/* small responsive image styling inside our tables */
.table-rounded-wrapper .table img { height: 48px; object-fit: cover; border-radius: 6px; }

/* keep reusable class for plate chips */
.plate-badge { /* (already defined above) */ }

/* Final enforcement: highest-specificity rules to ensure all tables use the same odd/even/hover colors
   This is appended last so it wins over any earlier rules (Bootstrap or page-specific). */
html body .table.table-striped tbody tr:nth-of-type(odd),
html body .table.table-striped tbody tr:nth-of-type(odd) > td {
  background-color: #1a1c1e !important;
}
html body .table.table-striped tbody tr:nth-of-type(even),
html body .table.table-striped tbody tr:nth-of-type(even) > td {
  background-color: #282a2d !important;
}
html body .table.table-striped tbody tr:hover,
html body .table.table-striped tbody tr:hover > td {
  background-color: #333435 !important;
}
/* Also apply to plain .table as a fallback */
html body .table tbody tr:nth-of-type(odd) { background-color: #1a1c1e !important; }
html body .table tbody tr:nth-of-type(even) { background-color: #282a2d !important; }
html body .table tbody tr:hover { background-color: #333435 !important; }

/* High-specificity light-mode overrides to ensure light theme takes precedence when body.light-mode is set */
html body.light-mode .table.table-striped tbody tr:nth-of-type(odd),
html body.light-mode .table.table-striped tbody tr:nth-of-type(odd) > td {
  background-color: #eff1f4 !important;
}
html body.light-mode .table.table-striped tbody tr:nth-of-type(even),
html body.light-mode .table.table-striped tbody tr:nth-of-type(even) > td {
  background-color: #ededed !important;
}
html body.light-mode .table.table-striped tbody tr:hover,
html body.light-mode .table.table-striped tbody tr:hover > td {
  background-color: #dfecf8 !important;
}
/* Fallback for plain .table */
html body.light-mode .table tbody tr:nth-of-type(odd) { background-color: #eff1f4 !important; }
html body.light-mode .table tbody tr:nth-of-type(even) { background-color: #ededed !important; }
html body.light-mode .table tbody tr:hover { background-color: #dfecf8 !important; }

/* Ensure table text and icons are darker in light mode and override Bootstrap body color variables */
html body.light-mode {
  /* set Bootstrap body color variable so --bs-table-color picks it up where used */
  --bs-body-color: #60656a;
}
html body.light-mode .table,
html body.light-mode .table th,
html body.light-mode .table td,
html body.light-mode .table tbody tr > td {
  color: #60656a !important;
}
/* set table-specific variable too (where Bootstrap reads --bs-table-color) */
html body.light-mode .table {
  --bs-table-color: #60656a;
  color: #60656a !important;
}
html body.light-mode .table .bi,
html body.light-mode .table .btn-outline-light {
  color: #60656a !important;
}

/* Invitations search dropdown (scoped to modal) */
#createInvitationModal #searchResults {
  position: absolute;
  z-index: 1050;
  max-height: 300px;
  overflow-y: auto;
  width: 100%;
  left: 0;
  top: 100%;
  margin-top: 0;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.3);
  border-radius: 0.375rem;
  background-color: #161b22;
  border: 1px solid var(--border-color);
}

#createInvitationModal #searchResults .list-group-item {
  border-left: none;
  border-right: none;
  background-color: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}

#createInvitationModal #searchResults .list-group-item:hover {
  background-color: #333435;
  cursor: pointer;
}

/* Light mode overrides */
body.light-mode #createInvitationModal #searchResults {
  background-color: #ffffff;
  border-color: #d0d7de;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

body.light-mode #createInvitationModal #searchResults .list-group-item {
  color: #24292f;
  border-color: #d0d7de;
}

body.light-mode #createInvitationModal #searchResults .list-group-item:hover {
  background-color: #dfecf8;
}

/* keep Add New Guest button styling */
#addNewGuestBtn { font-weight: 500; }

/* Clickable table rows */
.table-hover tbody tr { cursor: pointer; }
.table-hover tbody tr:hover { background-color: rgba(0, 0, 0, 0.075); }
  border-color: rgba(96,101,106,0.12) !important;
}

/* Mobile: convert tables to card-like rows for better readability on narrow screens */
@media (max-width: 768px) {
  .table-rounded-wrapper { padding: 0.5rem; }
  .table-rounded-wrapper .table { display: block; width: 100%; }
  .table-rounded-wrapper .table thead { display: none; }
  .table-rounded-wrapper .table tbody { display: block; }
  .table-rounded-wrapper .table tbody tr {
    display: block;
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    margin-bottom: 0.8rem;
    padding: 0.5rem;
  }

  /* each cell becomes its own row inside the card */
  .table-rounded-wrapper .table tbody tr td {
    display: block;
    padding: 0.25rem 0.5rem;
    border: none;
  }

  /* Photo: full width on top with 4:3 aspect */
  .table-rounded-wrapper .table tbody tr td.photo-cell {
    padding: 0; /* remove extra padding so image touches card edges */
  }
  .table-rounded-wrapper .table tbody tr td.photo-cell img {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 8px;
    display: block;
  }

  /* Plate left-aligned below photo with its confidence on the right of the plate */
  .table-rounded-wrapper .table tbody tr td.plate-cell {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0.6rem;
    padding: 0.45rem 0 0.3rem 0;
  }
  .table-rounded-wrapper .table tbody tr td.plate-cell .plate-badge { font-size: 1.05rem; }
  .table-rounded-wrapper .table tbody tr td.plate-cell .badge { margin-left: 0.35rem; }
}

/* Mobile gate button styling: smaller buttons aligned with title */
@media (max-width: 992px) {
  /* Position status below buttons with minimal gap */
  #mobileControlGroup { 
    margin-left: auto; 
    display: flex; 
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
  }
  
  /* Smaller buttons (~10% reduction) aligned with navbar-brand */
  #cameraGateQuickBtnMobile {
    width: 38px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
  }
  #cameraGateQuickBtnMobile .bi { font-size: 1.05rem; line-height: 1; }
  
  .navbar-toggler { 
    padding: 0.35rem 0.5rem;
    width: 38px;
    height: 34px;
  }
  .navbar-toggler-icon {
    width: 1.15em;
    height: 1.15em;
  }
}

/* Tighten spacing on very small screens so buttons don't wrap */
@media (max-width: 418px) {
  .navbar .container-fluid { padding-left: 0.5rem; padding-right: 0.5rem; }
  .navbar-brand { margin-right: 6px; font-size: 1rem; }
  
  /* Even smaller buttons on tiny screens */
  #cameraGateQuickBtnMobile {
    width: 34px;
    height: 30px;
  }
  .navbar-toggler { 
    padding: 0.3rem 0.45rem;
    width: 34px;
    height: 30px;
  }
  
  .navbar .container-fluid { display: flex; align-items: center; flex-wrap: nowrap; }
  .navbar-brand { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

  /* kv rows: label on left, value (with badge) on right */
  .table-rounded-wrapper .table tbody tr td .kv {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.18rem 0;
    color: var(--text-secondary);
  }
  .table-rounded-wrapper .table tbody tr td .kv .kv-label { font-size: 0.9rem; color: var(--text-secondary); }
  .table-rounded-wrapper .table tbody tr td .kv .kv-value { font-size: 0.95rem; color: var(--text-primary); display:flex; align-items:center; gap:0.4rem; }

  /* Decision row spacing */
  .table-rounded-wrapper .table tbody tr td.decision-cell { padding-top: 0.25rem; }

  /* Actions centered horizontally */
  .table-rounded-wrapper .table tbody tr td.actions-cell {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    margin-top: 0.6rem;
  }
  .table-rounded-wrapper .table tbody tr td.actions-cell .btn { padding: 0.45rem 0.9rem; }

  /* Plate badge sizing */
  .plate-badge { font-size: 1rem; padding: 0.35rem 0.6rem; }

  /* Keep badges on a single line where possible */
  .table-rounded-wrapper .table .badge { white-space: nowrap; }

  /* Mobile card-row: use a parent grid so all labels share the same column and values align */
  .table-rounded-wrapper .table tbody tr.card-row td .event-card .kv-list {
    display: grid;
    grid-template-columns: 7.25rem 1fr;
    row-gap: 0.25rem;
    column-gap: 0.5rem;
    align-items: center;
  }
  /* Let kv children participate directly in the grid so each label/value pair lines up */
  .table-rounded-wrapper .table tbody tr.card-row td .event-card .kv {
    display: contents;
  }
  .table-rounded-wrapper .table tbody tr.card-row td .event-card .kv .kv-label {
    text-align: right;
    white-space: nowrap;
    justify-self: end;
    padding-right: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
  }
  .table-rounded-wrapper .table tbody tr.card-row td .event-card .kv .kv-value {
    justify-self: start;
    font-size: 0.95rem;
    color: var(--text-primary);
    display:flex;
    gap:0.4rem;
    align-items:center;
  }
}

  /* Plate badge sizing */
  .plate-badge { font-size: 1rem; padding: 0.35rem 0.6rem; }

  /* Keep badges on a single line where possible */
  .table-rounded-wrapper .table .badge { white-space: nowrap; }
}

/* Event card styles adapted from provided example */

/* Mobile-only card tweaks: set fixed label column width so all values align under the longest label
   and add extra breathing room (horizontal padding) and slight top gap above the plate/title. */
@media (max-width: 768px) {
  /* Ensure kv inside the mobile card uses grid (override earlier mobile flex rule) so all labels have the same width
     Targeting the card-row event-card specifically avoids changing table cell kv elsewhere. */
  .table-rounded-wrapper .table tbody tr.card-row td .event-card .kv {
    display: grid;
    grid-template-columns: 7.25rem 1fr;
    align-items: center;
    gap: 0.5rem;
  }
  /* Also set label alignment and prevent wrapping so labels form a uniform column */
  .table-rounded-wrapper .table tbody tr.card-row td .event-card .kv .kv-label {
    text-align: right;
    white-space: nowrap;
    padding-right: 0.5rem;
  }
  /* Slightly more horizontal padding and a touch more vertical padding inside the card */
  .table-rounded-wrapper .table tbody tr.card-row td .event-card {
    padding: 1rem 1rem;
  }
  /* Add a little space above the plate/title so the image breathes into the card */
  .event-card .title { margin-top: 0.5rem; padding-left: 0.25rem; padding-right: 0.25rem; }
}

.event-card.card {
  --bg-card: var(--bg-secondary);
  --primary: var(--accent-color);
  --primary-800: #2b2b31;
  --light: var(--text-primary);
  --zinc-800: #161618;

  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem; /* increased inner padding so text doesn't touch border */
  box-sizing: border-box;
  width: 100%;
  background-color: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

/* spacing for stacked card lists (mobile) */
.card-list { display:flex; flex-direction:column; gap:1rem; padding:0.5rem 0; }
.card-list .event-card { margin: 0 0.25rem; }

.event-card .image_container { overflow:hidden; position:relative; width:100%; height:0; padding-bottom:75%; border-radius:8px; background-color:var(--primary-800); }
.event-card .image_container img{ position:absolute; inset:0; width:100%; height:100%; object-fit:cover; }
/* ensure our card image wins over global table img rules */
.event-card .image_container .card-image{ width:100% !important; height:100% !important; object-fit:cover !important; display:block !important; }
.event-card .image { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); width:3rem; fill:var(--light);} 
.event-card .title { font-size:1rem; font-weight:700; color:var(--text-primary); padding-top:0.25rem; padding-left:0.25rem; padding-right:0.25rem; }
.event-card .title-row { display:flex; align-items:center; gap:0.5rem; justify-content:flex-start; }
.event-card .plate-title { font-weight:700; color:var(--text-primary); }
.event-card .plate-conf { margin-left:0.35rem; }

.event-card .kv-list { padding-top:0.25rem; padding-left:0.5rem; padding-right:0.5rem; }

.event-card .action { display:flex; justify-content:center; gap:0.5rem; margin-top:0.5rem; padding-bottom:0.5rem; }
.event-card .action .btn { min-width:96px; }

/* ensure the table row containing the card is transparent so outer card padding shows */
.card-row { background: transparent !important; }
.card-row td { background: transparent !important; border: none !important; padding: 0.75rem !important; }

/* Ensure table striping does not show behind card rows */
.table-rounded-wrapper .table tbody tr.card-row,
.table-rounded-wrapper .table tbody tr.card-row td {
  background: transparent !important;
}

/* Make the event-card the visual card: add inner padding and drop inner bg on td */
.table-rounded-wrapper .table tbody tr.card-row td .event-card {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 0.85rem;
  margin: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.01) inset;
  border: 1px solid var(--border-color);
}

/* Tighten spacing between cards */
.table-rounded-wrapper { padding: 0.5rem; }


/* User-provided kv-grid wrapper (mobile only) - clean grid per request. This targets only event-card mobile layout
   and will not affect desktop table view. Adjust column sizes (first is label) as needed. */
@media (max-width: 768px) {
  .event-card .kv-list { padding-left: 0.5rem; padding-right: 0.5rem; }
  .event-card .kv-list .kv-grid-wrapper { display: block; }
  .event-card .kv-list .kv-grid-wrapper .line-wrapper {
    display: grid;
    grid-template-columns: 66px 1fr; /* tightened first column */
    gap: 0.5rem 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
  }
  .event-card .kv-list .kv-grid-wrapper .line-wrapper .col-1 {
    color: var(--text-secondary);
    text-align: right;
    font-size: 0.95rem;
    padding-right: 0.5rem;
    white-space: nowrap;
    /* no boxed background on label column to avoid artifacts */
  }
  .event-card .kv-list .kv-grid-wrapper .line-wrapper .col-2 {
    color: var(--text-primary);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
  }
  /* No background for either column — keep layout spacing but remove boxes/artifacts */
  .event-card .kv-list .kv-grid-wrapper .line-wrapper > .col-1,
  .event-card .kv-list .kv-grid-wrapper .line-wrapper > .col-2 {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0.35rem 0.8rem;
  }
  .event-card .kv-list .kv-grid-wrapper .line-wrapper .badge { margin-left: 0.25rem; }
}
