:root {
  --primary: #007bff;
  --primary-dark: #0056b3;
  --success: #28a745;
  --success-dark: #218838;
  --danger: #dc3545;
  --danger-dark: #a71d2a;
  --text: #263238;
  --muted: #607d8b;
  --surface: #ffffff;
  --page: #f4f7fb;
  --border: #dfe7ef;
  --shadow: 0 10px 28px rgba(31, 45, 61, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  background: var(--page);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
}

.dashboard-summary,
.time-rupees-container,
.app-footer {
  width: min(100% - 24px, 980px);
  margin-inline: auto;
}

.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
  margin-bottom: 16px;
}

.summary-card {
  background: var(--surface);
  padding: 18px;
  border-radius: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  min-width: 0;
}

.summary-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 32px rgba(31, 45, 61, 0.14);
}

.summary-card h3 {
  margin: 0;
  font-size: clamp(0.9rem, 2vw, 1.05rem);
  color: var(--muted);
}

.summary-card p {
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  font-weight: 700;
  margin: 10px 0 0;
  color: #111;
  overflow-wrap: anywhere;
}

.time-rupees-container {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: clamp(16px, 3vw, 28px);
  text-align: center;
}

.time-rupees-container h2 {
  margin: 0 0 18px;
  font-size: clamp(1.35rem, 4vw, 1.8rem);
}

.camera-wrapper {
  position: relative;
  width: min(100%, 680px);
  margin-inline: auto;
  background: #111827;
  border-radius: 12px;
  overflow: hidden;
}

#cameraStream {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: #0f172a;
}

#overlay {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  display: none;
  transition: background 0.5s ease;
  pointer-events: none;
}

.video-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.55);
  padding: 6px 8px;
  border-radius: 8px;
  transition: opacity 0.2s ease;
}

.video-controls button {
  background: transparent;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
}

.video-controls.hidden {
  opacity: 0;
  pointer-events: none;
}

#volumeSlider {
  width: 90px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin: 18px 0;
}

#role {
  flex: 1 1 26px;
  max-width: 420px;
  padding: 11px 12px;
  font-size: 0.95rem;
  border: 1px solid #1ce1bd;
  border-radius: 8px;
  background-color: #fff;
  color: #333;
  cursor: pointer;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#role:hover {
  border-color: #888;
}

#role:focus,
#memberPhone:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.16);
}

.btn,
#permissionBtn,
#addMemberBtn,
.time-rupees-container > button:not(.btn) {
  min-height: 42px;
  padding: 10px 18px;
  border-radius: 8px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  transition: background-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover,
#permissionBtn:hover,
#addMemberBtn:hover,
.time-rupees-container > button:not(.btn):hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.15);
}

.btn.green,
#addMemberBtn {
  background: var(--success);
}

.btn.green:hover,
#addMemberBtn:hover {
  background: var(--success-dark);
}

.btn.blue,
#permissionBtn,
.time-rupees-container > button:not(.btn) {
  background: var(--primary);
}

.btn.blue:hover,
#permissionBtn:hover,
.time-rupees-container > button:not(.btn):hover {
  background: var(--primary-dark);
}

.btn.red {
  background: var(--danger);
}

.btn.red:hover {
  background: var(--danger-dark);
}

.btn:active,
#permissionBtn:active,
#addMemberBtn:active,
.time-rupees-container > button:not(.btn):active {
  transform: translateY(0);
}

.status-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  background: #edf7c2;
  padding: 14px 18px;
  margin: 14px auto;
  border-radius: 12px;
  font-size: clamp(1.1rem, 4vw, 1.45rem);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

#timerDisplay,
#earningsDisplay {
  flex: 1 1 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

#timerDisplay {
  color: var(--primary);
}

#earningsDisplay {
  color: var(--success);
}

#warnings {
  min-height: 22px;
  color: var(--danger);
  font-weight: 700;
  overflow-wrap: anywhere;
}

#snapshotHistory {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 20px;
  text-align: left;
}

#snapshotHistory img {
  width: 100% !important;
  height: auto;
  margin: 0 !important;
  border-radius: 8px;
  border: 1px solid var(--border) !important;
}

#snapshotHistory p {
  margin: 4px 0 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

#addMemberBtn {
  display: block;
  margin: 18px auto;
}

#permissionSection {
  display: none;
  background: #fff;
  padding: 18px;
  margin: 18px auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  max-width: 520px;
  text-align: center;
}

#memberPhone {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#permissionBtn {
  width: 100%;
}

.history-table-wrap {
  width: 100%;
  margin-top: 20px;
  overflow-x: auto;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  -webkit-overflow-scrolling: touch;
}

#historyTable {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: #fff;
}

#historyTable th {
  background: var(--primary);
  color: #fff;
  padding: 12px;
  text-align: left;
  font-weight: 700;
  white-space: nowrap;
}

#historyTable td {
  padding: 11px 12px;
  border-bottom: 1px solid #eee;
  text-align: left;
  vertical-align: middle;
}

#historyTable tr:nth-child(even) {
  background: #f9fbfd;
}

.deleteBtn {
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  padding: 8px 10px;
}

.buttonRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.buttonRow button,
.viewWorkBtn,
.viewSnapshotsBtn,
.viewLiveBtn {
  flex: 1 1 auto;
  min-width: 110px;
  padding: 10px;
  border-radius: 8px;
  font-size: clamp(13px, 2.5vw, 14px);
  color: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.buttonRow button:hover,
.viewWorkBtn:hover,
.viewSnapshotsBtn:hover,
.viewLiveBtn:hover {
  transform: translateY(-2px);
  opacity: 0.9;
}

.viewWorkBtn {
  background: #4caf50;
}

.viewSnapshotsBtn {
  background: #2196f3;
}

.viewLiveBtn {
  background: #f44336;
}

#toastField {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  animation: slideIn 0.3s ease;
  word-wrap: break-word;
  pointer-events: auto;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.app-footer {
  padding: 14px 16px;
  margin-top: 18px;
  background-color: #65a4e4;
  border-top: 1px solid #ddd;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: #000;
}

.app-footer p {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 768px) {
  .dashboard-summary {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 680px);
  }

  .time-rupees-container,
  .app-footer {
    width: min(100% - 20px, 680px);
  }

  .controls {
    flex-direction: column;
  }

  #role,
  .btn,
  .time-rupees-container > button:not(.btn) {
    width: 100%;
    max-width: none;
  }

  .status-card {
    flex-direction: column;
    align-items: stretch;
  }

  #toastField {
    top: 10px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .toast {
    text-align: center;
  }

  .buttonRow {
    flex-direction: column;
  }

  .buttonRow button,
  .viewWorkBtn,
  .viewSnapshotsBtn,
  .viewLiveBtn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .dashboard-summary,
  .time-rupees-container,
  .app-footer {
    width: calc(100% - 16px);
  }

  .time-rupees-container {
    border-radius: 12px;
    padding: 14px;
  }

  .camera-wrapper,
  #cameraStream,
  #overlay {
    border-radius: 10px;
  }

  .video-controls {
    left: 8px;
    right: 8px;
    justify-content: center;
  }

  #volumeSlider {
    width: min(120px, 45vw);
  }

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

  #permissionSection {
    padding: 14px;
  }

  .app-footer {
    font-size: 0.85rem;
  }
}
