/**
 * Tenant System — overrides on top of AdminLTE 3.2
 * @see https://github.com/ColorlibHQ/AdminLTE/releases
 */

/* Never show WP admin bar on /app/* */
body.ts-app #wpadminbar {
  display: none !important;
}

html.ts-app {
  margin-top: 0 !important;
}

body.ts-app.admin-bar {
  margin-top: 0 !important;
  padding-top: 0 !important;
}

/* ——— Map legacy ts-* classes to Bootstrap / AdminLTE ——— */
.ts-content { padding: 0; }

.ts-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.ts-card {
  background: #fff;
  border-radius: 0.25rem;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.125), 0 1px 3px rgba(0, 0, 0, 0.08);
  margin-bottom: 1rem;
  padding: 1.25rem;
  border: 0;
}

.ts-card__title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
}

.ts-muted { color: #6c757d; }

.ts-photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.ts-photo-preview--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}

.ts-photo-preview__item {
  display: flex;
  flex-direction: column;
  width: 100px;
  max-width: 100px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #dee2e6;
}

.ts-photo-preview__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ts-photo-preview__name {
  display: block;
  font-size: 0.7rem;
  color: #6c757d;
  padding: 2px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ts-upload-status {
  margin: 0.5rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.ts-upload-status--pending {
  color: #856404;
  background: #fff3cd;
  border: 1px solid #ffeeba;
}

.ts-upload-status--progress {
  color: #004085;
  background: #cce5ff;
  border: 1px solid #b8daff;
}

.ts-upload-status--done {
  color: #155724;
  background: #d4edda;
  border: 1px solid #c3e6cb;
}

.ts-thumb-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.ts-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid #dee2e6;
}

.ts-modal--wide {
  max-width: 720px;
  width: 95vw;
}

.ts-badge--pending { color: #856404; background: #fff3cd; }
.ts-badge--reviewed { color: #155724; background: #d4edda; }
.ts-badge--active { color: #155724; background: #d4edda; }

.ts-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 768px) {
  .ts-grid--2 { grid-template-columns: repeat(2, 1fr); }
  .ts-grid--3 { grid-template-columns: repeat(3, 1fr); }
  .ts-grid--4 { grid-template-columns: repeat(4, 1fr); }
}

.ts-stat {
  font-size: 2rem;
  font-weight: 700;
  color: #007bff;
}

/* Buttons */
.ts-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.5;
  border-radius: 0.25rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}

.ts-btn--primary {
  color: #fff;
  background-color: #007bff;
  border-color: #007bff;
}

.ts-btn--primary:hover {
  color: #fff;
  background-color: #0069d9;
  border-color: #0062cc;
}

.ts-btn--ghost {
  color: #343a40;
  background-color: #fff;
  border-color: #ced4da;
}

.ts-btn--ghost:hover {
  background-color: #f8f9fa;
}

.ts-btn--danger {
  color: #fff;
  background-color: #dc3545;
  border-color: #dc3545;
}

.ts-btn--sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
}

.ts-btn--block { width: 100%; }

/* Forms */
.ts-input,
.ts-form .ts-input {
  display: block;
  width: 100%;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
  color: #495057;
  background-color: #fff;
  border: 1px solid #ced4da;
  border-radius: 0.25rem;
}

.ts-input:focus {
  border-color: #80bdff;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.ts-field { margin-bottom: 1rem; }
.ts-field label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.ts-field--checkbox label { font-weight: 400; display: flex; align-items: center; gap: 0.5rem; }

.ts-form__error { color: #dc3545; font-size: 0.875rem; }
.ts-form__success { color: #28a745; font-size: 0.875rem; }
.ts-hint { font-size: 0.8125rem; color: #6c757d; }

/* Tables */
.ts-table-wrap {
  overflow-x: auto;
  background: #fff;
  border-radius: 0.25rem;
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.125), 0 1px 3px rgba(0, 0, 0, 0.08);
}

.ts-table {
  width: 100%;
  margin-bottom: 0;
  color: #212529;
  border-collapse: collapse;
}

.ts-table th,
.ts-table td {
  padding: 0.75rem;
  vertical-align: top;
  border-top: 1px solid #dee2e6;
}

.ts-table thead th {
  vertical-align: bottom;
  border-bottom: 2px solid #dee2e6;
  background: #f8f9fa;
  font-weight: 600;
}

.ts-table--compact th,
.ts-table--compact td { padding: 0.4rem 0.5rem; }

/* Badges */
.ts-badge {
  display: inline-block;
  padding: 0.25em 0.6em;
  font-size: 75%;
  font-weight: 600;
  line-height: 1;
  border-radius: 0.25rem;
}

.ts-badge--pending { color: #856404; background-color: #fff3cd; }
.ts-badge--approved,
.ts-badge--paid,
.ts-badge--occupied { color: #155724; background-color: #d4edda; }
.ts-badge--rejected,
.ts-badge--unpaid { color: #721c24; background-color: #f8d7da; }
.ts-badge--partial { color: #856404; background-color: #fff3cd; }
.ts-badge--vacant { color: #004085; background-color: #cce5ff; }
.ts-badge--archived { color: #383d41; background-color: #e2e3e5; }

/* Tabs */
.ts-tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.ts-tab {
  padding: 0.5rem 1rem;
  border: 1px solid #dee2e6;
  background: #fff;
  border-radius: 0.25rem;
  cursor: pointer;
}
.ts-tab--active {
  color: #fff;
  background-color: #007bff;
  border-color: #007bff;
}

.ts-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: flex-end;
}

.ts-filters .ts-input {
  width: auto;
  min-width: 140px;
  max-width: 200px;
}

.ts-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.ts-page-header .ts-title { margin: 0; flex: 1; }

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

.ts-col-check { width: 2.5rem; text-align: center; vertical-align: middle; }
.ts-col-check input { margin: 0; }

.ts-bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #e7f1ff;
  border: 1px solid #b8daff;
  border-radius: 0.25rem;
}

.ts-bulk-bar[hidden] { display: none !important; }

.ts-bulk-bar__count { font-size: 0.875rem; color: #495057; margin-right: 0.5rem; }

.ts-input--sm { max-width: 10rem; padding: 0.25rem 0.5rem; font-size: 0.875rem; }

.ts-reading-meters { font-size: 0.875rem; line-height: 1.55; min-width: 12rem; }
.ts-reading-meter + .ts-reading-meter { margin-top: 0.25rem; }

.ts-reading-photos-cell { min-width: 11rem; vertical-align: top; }

.ts-reading-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
}

.ts-reading-photo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  width: 4.25rem;
  text-decoration: none;
  color: inherit;
  border-radius: 0.35rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ts-reading-photo:hover {
  transform: translateY(-1px);
  color: #2563eb;
}

.ts-reading-photo__thumb {
  display: block;
  width: 4rem;
  height: 4rem;
  border-radius: 0.35rem;
  overflow: hidden;
  border: 1px solid #dee2e6;
  background: #f1f3f5;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ts-reading-photo__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ts-reading-photo__label {
  font-size: 0.6875rem;
  line-height: 1.2;
  text-align: center;
  color: #495057;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ts-reading-photos__empty {
  display: block;
  width: 100%;
  font-size: 0.75rem;
  color: #868e96;
  margin-top: 0.15rem;
}

.ts-photo-lightbox {
  border: none;
  padding: 0;
  max-width: min(92vw, 720px);
  width: auto;
  background: transparent;
}

.ts-photo-lightbox::backdrop {
  background: rgba(15, 23, 42, 0.75);
}

.ts-photo-lightbox__figure {
  margin: 0;
  background: #fff;
  border-radius: 0.5rem;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.ts-photo-lightbox__img {
  display: block;
  max-width: min(92vw, 720px);
  max-height: 80vh;
  width: auto;
  height: auto;
  margin: 0 auto;
}

.ts-photo-lightbox__caption {
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  text-align: center;
  color: #343a40;
  border-top: 1px solid #e9ecef;
}

.ts-photo-lightbox__close {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #212529;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.ts-photo-lightbox__hint {
  text-align: center;
  margin: 0.75rem 0 0;
}

.ts-photo-lightbox__hint a {
  color: #fff;
  font-size: 0.875rem;
}

/* Meter / dropzone */
.ts-meter {
  border: 1px solid #dee2e6;
  border-radius: 0.25rem;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #f8f9fa;
}

.ts-meter__title { font-weight: 600; margin-bottom: 0.5rem; }

.ts-dropzone {
  border: 2px dashed #ced4da;
  border-radius: 0.25rem;
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  background: #fff;
}

.ts-dropzone:hover,
.ts-dropzone.is-dragover {
  border-color: #007bff;
  background: #e7f1ff;
}

/* Modals (native dialog) */
.ts-modal {
  border: none;
  border-radius: 0.3rem;
  padding: 0;
  max-width: 500px;
  width: calc(100% - 2rem);
}

.ts-modal--wide { max-width: 640px; }

.ts-modal::backdrop { background: rgba(0, 0, 0, 0.5); }

.ts-modal__form { padding: 1.25rem; }
.ts-modal__title { margin: 0 0 1rem; font-size: 1.25rem; font-weight: 600; }

.ts-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.ts-alert {
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  border-radius: 0.25rem;
}

.ts-alert--success {
  color: #155724;
  background-color: #d4edda;
  border-color: #c3e6cb;
}

/* System dialogs (TsDialog) */
.ts-dialog__message {
  margin: 0 0 1rem;
  color: #495057;
  line-height: 1.5;
  white-space: pre-wrap;
}

.ts-dialog--error .ts-modal__title { color: #dc3545; }

.ts-password-field {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  flex-wrap: wrap;
}

.ts-dialog-password-input {
  flex: 1;
  min-width: 12rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  user-select: all;
}

.ts-dialog-copy-hint {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
}

.ts-dialog-copy-hint--ok { color: #155724; }
.ts-dialog-copy-hint--warn { color: #856404; }

.ts-input.is-invalid { border-color: #dc3545; }

.ts-password-reveal {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.ts-password-reveal .ts-input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  user-select: all;
}

.ts-subtitle { font-size: 1rem; font-weight: 600; margin: 1rem 0 0.5rem; }
.ts-divider { border: 0; border-top: 1px solid #dee2e6; margin: 1.25rem 0; }

/* Hide duplicate page title in content when shown in header */
.content-header #ts-page-title:empty { display: none; }

.ts-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Login */
.login-page .login-box { width: 400px; max-width: 96vw; }

.login-page .card-primary.card-outline {
  border-top: 3px solid #007bff;
}

/* Responsive tables on mobile */
@media (max-width: 767.98px) {
  .ts-filters .ts-input {
    width: 100%;
    max-width: none;
  }

  .content-header h1#ts-page-title {
    font-size: 1.25rem;
  }
}
