/* ===========================
   ADMIN UI (Responsive)

   Goals:
   - Mobile/tablet/desktop friendly layout
   - No horizontal overflow on small phones
   - Keep existing colors/branding (no redesign)
=========================== */

/* ---------------------------
   Global base
--------------------------- */
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: Poppins, Arial, sans-serif;
  background: linear-gradient(90deg, #d7e8ff, #eef3ff);
  margin: 0;
}

img {
  max-width: 100%;
  height: auto;
}

/* ---------------------------
   Back button
--------------------------- */
.back-home {
  display: inline-block;
  margin: 20px;
  padding: 8px 14px;
  background: #006efb;
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 14px;
}

.back-home:hover {
  background: #038129;
}

/* ---------------------------
   Admin login box
   - Use fluid width so it works on all phones
--------------------------- */
.login-box {
  width: min(92vw, 360px);
  margin: 80px auto 24px;
  background: #fff;
  padding: 28px;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12);
  text-align: center;
}

.logo-container {
  text-align: center;
  margin-bottom: 12px;
}

.logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.login-box input {
  width: 100%;
  padding: 12px;
  margin: 10px 0;
  border-radius: 8px;
  border: 1px solid #ddd;
  font-size: 14px;
}

/* ---------------------------
   Password toggle (eye)
--------------------------- */
.password-field {
  position: relative;
  width: 100%;
}

.password-field input {
  padding-right: 44px;
}

.pw-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  line-height: 0;
}

.pw-toggle svg {
  display: block;
}

/* On the login page, the input margins can throw off absolute centering.
   Move the spacing to the wrapper instead so the eye stays perfectly aligned. */
.login-box .password-field {
  margin: 10px 0;
}

.login-box .password-field input {
  margin: 0;
}

.pw-toggle:hover {
  background: #f5f7ff;
}

.pw-icon-hide {
  display: none;
}

.pw-toggle[aria-pressed="true"] .pw-icon-show {
  display: none;
}

.pw-toggle[aria-pressed="true"] .pw-icon-hide {
  display: inline;
}

.login-box button[type="submit"] {
  width: 100%;
  padding: 12px;
  background: #006efb;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
}

.login-box button[type="submit"]:hover {
  background: #c09d00;
}

.error {
  background: #ffdfdf;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 12px;
  color: #c00;
  font-size: 14px;
}

/* ---------------------------
   Admin dashboard layout
--------------------------- */
.top-nav {
  background: #006bf7;
  color: #fff;
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap; /* prevent overflow on narrow screens */
}

.top-nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.container {
  width: min(92vw, 1100px);
  margin: 24px auto;
  padding: 0 12px;
}

.panel {
  background: #fff;
  padding: 18px;
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
  margin-bottom: 18px;
}

.panel-help {
  margin: 6px 0 14px;
  color: #4c5a7a;
  font-size: 13px;
}

.panel input {
  width: 100%;
  padding: 10px;
  margin: 10px 0;
  border: 1px solid #ddd;
  border-radius: 6px;
}

/* ---------------------------
   Tables / grids (frontend-like)
   Keep desktop layout on mobile - scale to fit
--------------------------- */
.table-scroll {
  overflow-x: auto;
  border: 1px solid #e3e8ff;
  border-radius: 12px;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}

.result-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 12px;
  overflow: hidden;
}

/* Table border-radius corners */
.result-table thead tr:first-child th:first-child {
  border-top-left-radius: 12px;
}

.result-table thead tr:first-child th:last-child {
  border-top-right-radius: 12px;
}

.result-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 12px;
}

.result-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 12px;
}

/* Tablet screens: set min-width for horizontal scroll */
@media (min-width: 651px) {
  .result-table {
    min-width: 820px;
  }
}

.result-table th,
.result-table td {
  padding: 10px;
  border-bottom: 1px solid #eef1ff;
  border-right: 1px solid #eef1ff;
  text-align: center;
  vertical-align: middle;
  background: #fff;
}

.result-table th:first-child,
.result-table td:first-child {
  border-left: 1px solid #eef1ff;
}

.result-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f4f7ff;
  color: #113a8d;
  font-weight: 700;
}

.result-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f8faff;
  text-align: left;
  min-width: 120px;
}

.result-table .row-label {
  font-weight: 800;
  color: #003a8c;
}

.result-table .show-number-row td,
.result-table .show-number-row th {
  background: #fbfcff;
  color: #56628a;
  font-weight: 700;
  padding-top: 8px;
  padding-bottom: 8px;
}

.matrix-input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 40px;
  padding: 8px 10px;
  border: 1px solid #d9e0ff;
  border-radius: 10px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  background: #ffffff;
}

.matrix-input:focus {
  outline: none;
  border-color: #006efb;
  box-shadow: 0 0 0 3px rgba(0, 110, 251, 0.15);
}

.mini-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 10px;
  overflow: hidden;
}

.mini-table th,
.mini-table td {
  border: 1px solid #eef1ff;
  padding: 10px;
  text-align: center;
}

.mini-table thead th {
  background: #f4f7ff;
  color: #113a8d;
  font-weight: 800;
}

/* Mini table border-radius corners */
.mini-table thead tr:first-child th:first-child {
  border-top-left-radius: 10px;
}

.mini-table thead tr:first-child th:last-child {
  border-top-right-radius: 10px;
}

.mini-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: 10px;
}

.mini-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: 10px;
}

.mini-table .row-label {
  text-align: left;
  background: #f8faff;
  color: #003a8c;
  font-weight: 800;
  width: 140px;
}

/* ---------------------------
   Slot inputs (legacy / still used elsewhere)
--------------------------- */
.slot-grid {
  display: grid;
  gap: 10px;
  margin: 10px 0 14px;
}

.slot-grid-8 {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.slot-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.slot-grid input {
  text-align: center;
}

@media (max-width: 900px) {
  .slot-grid-8 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .slot-grid-8 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-table {
    min-width: 760px;
  }
}

/* ===========================
   MOBILE RESPONSIVE TABLE (below 650px)
   Keep exact desktop table layout - scale down to fit
   - Same row-column grid as laptop view
   - No scrolling (horizontal or vertical)
   - All rows and columns visible at once
=========================== */

/* Hide mobile grid layouts - we use scaled desktop tables instead */
.admin-mobile-table-grid {
  display: none !important;
}

@media (max-width: 650px) {
  /* Keep desktop tables visible */
  .table-scroll .result-table.admin-edit-table {
    display: table !important;
    width: 100%;
    min-width: unset !important;
    border-radius: 10px;
    table-layout: fixed; /* Equal-width columns on mobile */
  }

  /* Equal-width columns across all 9 columns (Time + 8 slots) */
  .result-table.admin-edit-table th,
  .result-table.admin-edit-table td {
    width: calc(100% / 9);
  }

  /* Remove scroll wrapper behavior */
  .table-scroll {
    overflow: visible;
    border: 1px solid #e3e8ff;
    border-radius: 10px;
    background: #fff;
  }

  /* Scale table cells for mobile */
  .result-table th,
  .result-table td {
    padding: 4px 2px;
    font-size: 8px;
    white-space: normal; /* Allow wrapping in cells */
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* Override any global header nowrap for mobile */
  .table-scroll table th {
    white-space: normal;
  }

  /* Sticky column adjustments */
  .result-table .sticky-col {
    min-width: auto; /* allow equal-width distribution */
    font-size: 7px;
    padding: 3px 2px;
  }

  .result-table .row-label {
    font-size: 7px;
  }

  /* Time header row */
  .result-table .time-header th {
    padding: 4px 1px;
    font-size: 6px;
    white-space: nowrap; /* Keep time headers compact */
  }

  /* Show number row */
  .result-table .show-number-row td,
  .result-table .show-number-row th {
    padding: 3px 1px;
    font-size: 7px;
  }

  /* Matrix inputs - compact and smaller font */
  .matrix-input {
    height: 26px;
    padding: 3px 1px;
    font-size: 10px;
    border-radius: 5px;
  }

  /* Ensure edit-table inputs match mini-table font size behavior */
  .result-table.admin-edit-table .matrix-input {
    font-size: 10px;
  }

  /* Container adjustments */
  .container {
    width: 100%;
    padding: 0 4px;
  }

  .panel {
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 10px;
  }

  .panel h3 {
    font-size: 14px;
    margin-bottom: 5px;
  }

  .panel-help {
    font-size: 10px;
    margin: 3px 0 6px;
  }

  /* Mini tables (Main Bazar, PK Mumbai) - scale down */
  .mini-table {
    font-size: 10px;
    border-radius: 8px;
    overflow: hidden;
  }

  .mini-table th,
  .mini-table td {
    padding: 5px 3px;
  }

  .mini-table .row-label {
    width: auto;
    min-width: 45px;
    font-size: 9px;
  }

  .mini-table .matrix-input {
    height: 28px;
    font-size: 10px;
    padding: 3px 2px;
  }
}

/* Small screens (below 550px) */
@media (max-width: 550px) {
  .result-table th,
  .result-table td {
    padding: 3px 1px;
    font-size: 7px;
  }

  .result-table .sticky-col {
    min-width: 35px;
    font-size: 6px;
  }

  .result-table .time-header th {
    font-size: 5px;
    padding: 3px 1px;
  }

  .matrix-input {
    height: 24px;
    padding: 2px 1px;
    font-size: 9px;
    border-radius: 4px;
  }

  /* Ensure edit-table inputs match mini-table font size behavior */
  .result-table.admin-edit-table .matrix-input {
    font-size: 9px;
  }

  .mini-table .matrix-input {
    height: 26px;
    font-size: 9px;
  }

  .panel {
    padding: 6px;
  }

  .panel h3 {
    font-size: 13px;
  }
}

/* Extra small screens (below 450px) */
@media (max-width: 450px) {
  .result-table th,
  .result-table td {
    padding: 2px 1px;
    font-size: 6px;
  }

  .result-table .sticky-col {
    min-width: 30px;
    font-size: 5px;
  }

  .result-table .time-header th {
    font-size: 5px;
    padding: 2px 1px;
  }

  .matrix-input {
    height: 22px;
    padding: 2px 1px;
    font-size: 8px;
    border-radius: 3px;
  }

  /* Ensure edit-table inputs match mini-table font size behavior */
  .result-table.admin-edit-table .matrix-input {
    font-size: 8px;
  }

  .container {
    padding: 0 2px;
  }

  .mini-table th,
  .mini-table td {
    padding: 4px 2px;
    font-size: 9px;
  }

  .mini-table .row-label {
    min-width: 38px;
    font-size: 8px;
  }

  .mini-table .matrix-input {
    height: 24px;
    font-size: 8px;
  }
}

/* Very small screens (below 380px) - use CSS transform scale */
@media (max-width: 380px) {
  .table-scroll {
    transform: scale(0.92);
    transform-origin: top left;
    width: 108.7%;
  }

  .matrix-input {
    height: 20px;
    font-size: 7px;
  }

  /* Ensure edit-table inputs match mini-table font size behavior */
  .result-table.admin-edit-table .matrix-input {
    font-size: 7px;
  }

  .mini-table .matrix-input {
    height: 22px;
    font-size: 7px;
  }
}

/* Extremely small screens (below 340px) */
@media (max-width: 340px) {
  .table-scroll {
    transform: scale(0.85);
    transform-origin: top left;
    width: 117.6%;
  }
}

.panel button:not([type]),
.panel button[type="submit"] {
  padding: 10px 14px;
  background: #007bff;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

h3 {
  color: #003a8c;
}

/* ---------------------------
   Responsive tweaks
--------------------------- */
@media (max-width: 650px) {
  .back-home {
    margin: 10px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .login-box {
    margin: 40px auto 16px;
    padding: 18px 14px;
    width: min(94vw, 320px);
  }

  .top-nav {
    padding: 10px;
    font-size: 13px;
  }

  .top-nav h2 {
    font-size: 15px;
  }

  /* Mobile usability: prevent iOS from zooming on focus */
  .login-box input,
  .panel input {
    font-size: 16px;
  }

  .panel button:not([type]),
  .panel button[type="submit"] {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    margin-top: 8px;
  }
}

@media (max-width: 480px) {
  .back-home {
    margin: 8px;
  }

  .login-box {
    margin: 30px auto 12px;
    padding: 16px 12px;
  }

  .top-nav {
    padding: 8px;
  }

  .panel label {
    font-size: 12px;
  }
}
