/* ==========================================================================
   WAAD Mobile & Theme Overrides
   Works alongside design-system.css — handles mobile fixes & dark mode
   Bootstrap overrides for dark theme
   ========================================================================== */

/* ---------- Legacy CSS variable aliases (for backward compat) ---------- */
:root {
  --admin-bg: var(--ds-bg);
  --admin-text: var(--ds-text);
  --admin-muted-text: var(--ds-text-muted);
  --card-bg: var(--ds-surface);
  --card-border-color: var(--ds-border);
  --card-shadow-color: rgba(28, 25, 23, 0.075);
  --sidebar-bg: var(--ds-sidebar-bg);
  --sidebar-link-color: var(--ds-sidebar-text);
  --sidebar-link-active-bg: var(--ds-sidebar-active-bg);
  --sidebar-link-active-color: var(--ds-sidebar-active-text);
  --focus-color: var(--ds-primary);
}

html[data-theme='dark'] {
  --card-shadow-color: rgba(0, 0, 0, 0.45);
}

/* ---------- Basic responsive ---------- */
* {
  box-sizing: border-box;
}

body {
  font-size: 16px;
  overflow-x: hidden;
}

/* ---------- Dark Mode — Bootstrap Overrides ---------- */
html[data-theme='dark'] .table {
  color: var(--ds-text);
}

html[data-theme='dark'] .table > :not(caption) > * > * {
  background-color: var(--ds-surface);
  color: var(--ds-text);
}

html[data-theme='dark'] .table > thead > tr > th {
  background-color: #1f2329;
  color: var(--ds-text);
}

html[data-theme='dark'] .table-hover > tbody > tr:hover > * {
  background-color: #252a31;
  color: var(--ds-text);
}

html[data-theme='dark'] .table thead th,
html[data-theme='dark'] .table td,
html[data-theme='dark'] .table th {
  border-color: var(--ds-border);
}

html[data-theme='dark'] .form-control,
html[data-theme='dark'] .form-select {
  background-color: #1f2329;
  color: var(--ds-text);
  border-color: var(--ds-border);
}

html[data-theme='dark'] .form-control::placeholder {
  color: #8b949e;
}

html[data-theme='dark'] .dropdown-menu {
  background-color: #1f2329;
  border-color: var(--ds-border);
}

html[data-theme='dark'] .dropdown-item {
  color: var(--ds-text);
}

html[data-theme='dark'] .dropdown-item:hover,
html[data-theme='dark'] .dropdown-item:focus {
  background-color: #2a2f37;
}

html[data-theme='dark'] .card,
html[data-theme='dark'] .modal-content {
  background-color: var(--ds-surface);
  color: var(--ds-text);
  border-color: var(--ds-border);
}

html[data-theme='dark'] .bg-white,
html[data-theme='dark'] .table-light,
html[data-theme='dark'] .sticky-top,
html[data-theme='dark'] .card-header.bg-white {
  background-color: #1f2329 !important;
  color: var(--ds-text) !important;
}

html[data-theme='dark'] .bg-light {
  background-color: #1f2329 !important;
  color: var(--ds-text) !important;
}

html[data-theme='dark'] .border-bottom,
html[data-theme='dark'] .border,
html[data-theme='dark'] hr {
  border-color: var(--ds-border) !important;
}

html[data-theme='dark'] .btn-outline-secondary {
  color: #d0d7de;
  border-color: rgba(255, 255, 255, 0.35);
}

html[data-theme='dark'] .btn-outline-secondary:hover {
  background-color: #2a2f37;
  color: #ffffff;
}

/* ---------- Touch targets ---------- */
.btn {
  min-height: 44px !important;
  padding: 0.75rem 1.5rem !important;
  font-size: 1rem !important;
  touch-action: manipulation;
}

.btn-sm {
  min-height: 38px !important;
  padding: 0.5rem 1rem !important;
  font-size: 0.9rem !important;
}

/* ---------- Form controls ---------- */
.form-control,
.form-select {
  min-height: 44px !important;
  font-size: 16px !important; /* iOS zoom prevention */
  padding: 0.75rem !important;
}

/* ---------- Mobile table ---------- */
@media (max-width: 767px) {
  .table-responsive {
    border: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    font-size: 0.9rem;
  }

  .table th,
  .table td {
    padding: 0.5rem !important;
    white-space: nowrap;
  }

  .card {
    margin-bottom: 1rem;
  }

  .card-body {
    padding: 1rem;
  }
}

/* ---------- Mobile modal ---------- */
@media (max-width: 767px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-content {
    border-radius: var(--ds-radius-lg);
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    padding: 0.75rem;
  }

  .modal-footer .btn {
    margin: 0.25rem;
    width: 100%;
  }
}

/* ---------- Navigation ---------- */
.navbar {
  padding: 0.75rem 1rem;
}

.navbar-brand {
  font-size: 1.25rem;
}

/* ---------- Mobile sidebar ---------- */
@media (max-width: 767px) {
  .sidebar {
    width: 280px !important;
    max-width: 85vw;
  }

  .sidebar .nav-link {
    padding: 1rem !important;
    font-size: 1rem;
  }

  .main-content {
    padding: 1rem !important;
    margin-top: 3rem;
  }
}

/* ---------- Mobile stat cards ---------- */
@media (max-width: 767px) {
  .stat-card {
    margin-bottom: 1rem;
  }

  .stat-card h2 {
    font-size: 1.5rem;
  }

  .stat-card p {
    font-size: 0.9rem;
  }
}

/* ---------- Alerts ---------- */
.alert {
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
}

/* ---------- Badges ---------- */
.badge {
  font-size: 0.85rem;
  padding: 0.35em 0.65em;
}

/* ---------- Input groups ---------- */
.input-group {
  flex-wrap: nowrap;
}

@media (max-width: 767px) {
  .input-group {
    flex-wrap: wrap;
  }

  .input-group .form-control {
    width: 100%;
    margin-bottom: 0.5rem;
  }

  .input-group .btn {
    width: 100%;
  }
}

/* ---------- Pagination ---------- */
@media (max-width: 767px) {
  .pagination {
    font-size: 0.9rem;
  }

  .page-link {
    padding: 0.5rem 0.75rem;
  }
}

/* ---------- Dropdowns ---------- */
.dropdown-menu {
  font-size: 1rem;
}

.dropdown-item {
  padding: 0.75rem 1.25rem;
}

/* ---------- Checkboxes ---------- */
.form-check-input {
  width: 1.25em;
  height: 1.25em;
  margin-top: 0.125em;
}

.form-check-label {
  padding-left: 0.5rem;
  font-size: 1rem;
}

/* ---------- Scroll ---------- */
.table-responsive {
  -webkit-overflow-scrolling: touch;
}

.container-fluid,
.container {
  overflow-x: hidden;
}

/* ---------- Focus ---------- */
.form-control:focus,
.form-select:focus,
.btn:focus {
  outline: 2px solid var(--ds-primary);
  outline-offset: 2px;
}

/* ---------- Touch device ---------- */
@media (hover: none) {
  .btn:hover {
    transform: none;
  }

  a:hover {
    opacity: 0.8;
  }
}

/* ---------- Safe area (iPhone X+) ---------- */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
}
