/* ===========================
   RETAIL ECHO — Mobile-First CSS
   Samsung Blue Theme
=========================== */

:root {
  --blue: #1428A0;
  --blue-dark: #0d1d7e;
  --blue-light: #e8ecf8;
  --danger: #dc3545;
  --danger-dark: #b02a37;
  --success: #198754;
  --secondary: #6c757d;
  --text: #1a1a1a;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --bg: #f0f2f5;
  --card: #ffffff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 16px rgba(0,0,0,0.08);
  --shadow-card: 0 4px 20px rgba(0,0,0,0.10);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Noto Sans', Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---- Sections ---- */
.section {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.section.hidden { display: none !important; }

/* ---- Header ---- */
.app-header {
  background: var(--blue);
  color: #fff;
  padding: 22px 18px 18px;
  text-align: center;
  flex-shrink: 0;
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
}
.app-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.3px;
  line-height: 1.2;
}
.app-subtitle {
  font-size: 13px;
  opacity: 0.82;
  margin-top: 3px;
}

/* ---- Main Content ---- */
.app-main {
  flex: 1;
  padding: 16px;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

/* ---- Instruction ---- */
.instruction-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding: 11px 13px;
  background: var(--blue-light);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--blue);
  line-height: 1.5;
}

/* ---- Card ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 14px;
}

/* ---- Form ---- */
.form-group {
  margin-bottom: 18px;
}
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-input {
  display: block;
  width: 100%;
  padding: 14px 12px;
  font-size: 16px;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 40, 160, 0.12);
}
.form-input.error {
  border-color: var(--danger);
}
.field-error {
  display: none;
  font-size: 12px;
  color: var(--danger);
  margin-top: 5px;
}
.field-error.visible {
  display: block;
}

/* ---- GPS Status ---- */
.gps-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  min-height: 18px;
  padding-left: 2px;
}
.gps-status.acquired { color: var(--success); }
.gps-status.denied { color: var(--danger); }

/* ---- Recording Section ---- */
.recording-section {
  background: #f8f9fb;
  border-radius: var(--radius-sm);
  padding: 18px;
  margin-bottom: 20px;
  border: 2px dashed var(--border);
}

.recording-status-area {
  text-align: center;
  margin-bottom: 14px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.timer-display {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 48px;
  font-weight: 800;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.timer-display.active {
  display: flex;
}
.timer-unit {
  font-size: 22px;
  font-weight: 600;
  align-self: flex-end;
  padding-bottom: 6px;
}
.recording-dot {
  width: 12px;
  height: 12px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse-dot 1s ease-in-out infinite;
  flex-shrink: 0;
  align-self: center;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

.recording-status-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 8px;
}

.recording-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.audio-preview-section {
  margin-top: 16px;
  text-align: center;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.audio-preview-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.audio-player {
  width: 100%;
  border-radius: 8px;
}
.rerecord-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}
.rerecord-hint a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.rerecord-hint a:hover { text-decoration: underline; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 13px 22px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.18s, transform 0.1s, opacity 0.18s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-large {
  padding: 16px 28px;
  font-size: 17px;
  min-width: 170px;
}
.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
}

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #5a6268; }

.btn-outline {
  background: transparent;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.65);
}
.btn-outline:hover:not(:disabled) { background: rgba(255,255,255,0.12); }

.btn-outline-dark {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-outline-dark:hover:not(:disabled) { background: #f0f0f0; }
.btn-outline-dark.active {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue);
}

.btn-submit {
  background: var(--blue);
  color: #fff;
  width: 100%;
  margin-top: 4px;
}
.btn-submit:hover:not(:disabled) { background: var(--blue-dark); }

/* Loading spinner on button */
.btn-loading {
  color: transparent !important;
  position: relative;
  pointer-events: none;
}
.btn-loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Success ---- */
.success-message {
  text-align: center;
  padding: 30px 16px;
}
.success-icon {
  font-size: 56px;
  color: var(--success);
  margin-bottom: 12px;
  line-height: 1;
}
.success-text {
  font-size: 19px;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 24px;
}

/* ---- Footer ---- */
.app-footer {
  text-align: center;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}

/* ---- Admin Link ---- */
.admin-link-wrapper {
  text-align: center;
  padding: 10px 16px 18px;
}
.admin-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  opacity: 0.55;
}
.admin-link:hover { opacity: 1; text-decoration: underline; }

/* ---- Section Title ---- */
.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 20px;
}

/* ---- Admin Action Bar ---- */
.admin-action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  background: #fff;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

/* ---- Search ---- */
.search-container {
  margin-bottom: 10px;
}

/* ---- Record Count ---- */
.record-count {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding: 0 2px;
}

/* ---- Table ---- */
.table-container {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 640px;
}

.records-table th {
  background: var(--blue);
  color: #fff;
  padding: 12px 10px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.records-table th:first-child { border-radius: var(--radius) 0 0 0; }
.records-table th:last-child { border-radius: 0 var(--radius) 0 0; }

.col-sortable {
  cursor: pointer;
  user-select: none;
}
.col-sortable:hover { background: var(--blue-dark); }
.sort-icon { opacity: 0.65; font-size: 11px; }
.col-check { width: 38px; text-align: center; }

.records-table td {
  padding: 10px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
.records-table tr:last-child td { border-bottom: none; }
.records-table tbody tr:hover td { background: #f8f9fb; }

.gps-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  background: #e8f5e9;
  color: var(--success);
  font-weight: 600;
  white-space: nowrap;
}
.gps-tag.none {
  background: #f5f5f5;
  color: #bbb;
}

.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-tbl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.btn-tbl:hover { opacity: 0.85; }
.btn-tbl-play { background: var(--blue); color: #fff; }
.btn-tbl-download { background: var(--success); color: #fff; }
.btn-tbl-delete { background: var(--danger); color: #fff; }

.inline-audio-wrap {
  margin-top: 6px;
}
.inline-audio {
  display: block;
  width: 220px;
  height: 36px;
}

.no-records {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 15px;
}

/* ---- Audit Log ---- */
.audit-table td {
  vertical-align: top;
  font-size: 13px;
}
.audit-detail-row {
  padding: 4px 0;
  border-bottom: 1px solid #f0f0f0;
  line-height: 1.6;
}
.audit-detail-row:last-child { border-bottom: none; }
.audit-tag {
  display: inline-block;
  background: #fdecea;
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
}
.audit-count-badge {
  display: inline-block;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.ip-code {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}

/* ---- Map ---- */
.admin-map {
  height: 460px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  background: #e8ecf0;
}

/* ---- Dialog ---- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 18px;
}
.dialog-overlay.hidden { display: none !important; }

.dialog-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 26px 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
}
.dialog-message {
  font-size: 15px;
  line-height: 1.55;
  margin-bottom: 22px;
  color: var(--text);
}
.dialog-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #222;
  color: #fff;
  padding: 12px 22px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  transition: transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* ---- Utility ---- */
.hidden { display: none !important; }

/* ============================
   Tablet / Desktop overrides
============================ */
@media (min-width: 600px) {
  .app-title { font-size: 32px; }
  .app-main { padding: 22px 24px; }
  .card { padding: 28px; }
  .admin-action-bar { flex-wrap: nowrap; }
  .recording-buttons { flex-wrap: nowrap; }
  .admin-map { height: 520px; }
}

@media (min-width: 900px) {
  .app-header { padding: 28px 32px; }
  .app-main { padding: 28px 32px; max-width: 1000px; }
  .admin-map { height: 580px; }
}
