/* pwa.css - Mobile-First PWA Styling for ChaiFi */

:root {
  --primary: #6f4e37;
  --primary-hover: #5d4037;
  --primary-light: #f5ebe0;
  --bg: #fdfbf7;
  --card: #ffffff;
  --text: #433422;
  --text-muted: #9c8c74;
  --border: #e6dccf;
  --accent-gold: #d4a373;
  --success: #166534;
  --danger: #ef4444;
  --nav-height: 64px;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea, [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}

/* App Layout Container */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* Header */
.app-header {
  height: calc(var(--header-height) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: 16px;
  padding-right: 16px;
  background: rgba(253, 251, 247, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-size: 19px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 12px;
  border: 1px solid var(--border);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.install-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 5px 11px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(111, 78, 55, 0.2);
}

.install-btn.visible {
  display: flex;
}

/* Tab Views */
.tab-content-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.tab-pane {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
}

.tab-pane.active {
  display: block;
}

#tab-map {
  padding-bottom: 0;
  overflow: hidden;
}

/* Bottom Navigation Bar */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--nav-height);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.nav-item .nav-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active .nav-icon {
  transform: scale(1.15);
}

.nav-item .badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--primary);
  color: white;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 10px;
  font-weight: 700;
  min-width: 14px;
  text-align: center;
}

/* ============================================================
   TAB 1: LOG VIEW STYLES
   ============================================================ */
.log-container {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
}

.quick-loc-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.gps-btn {
  flex: 1;
  background: #f4ede4;
  border: 1px solid var(--border);
  color: var(--primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.gps-btn:active {
  background: #e6dccf;
}

.card-box {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 16px;
  box-shadow: 0 2px 8px rgba(111, 78, 55, 0.04);
  margin-bottom: 14px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-secondary {
  padding: 0 14px;
  background: #f4ede4;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--primary);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #e6dccf;
}

.btn-secondary:disabled {
  opacity: 0.65;
  cursor: wait;
}

.password-group {
  position: relative;
}

.password-group input {
  padding-right: 40px;
}

.toggle-pwd-btn {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 40px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  opacity: 0.6;
}

.toggle-pwd-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Rich Input Notes */
.rich-input {
  min-height: 70px;
  max-height: 140px;
  overflow-y: auto;
  cursor: text;
  background: #fff;
}

.rich-input[contenteditable]:empty::before {
  content: attr(data-placeholder);
  color: #a89f91;
  pointer-events: none;
  display: block;
}

.rich-input ul {
  margin: 0;
  padding-left: 20px;
}

.rich-input li {
  list-style-type: disc;
}

/* Rating Stars */
.rating-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.stars {
  display: flex;
  gap: 4px;
}

.star {
  font-size: 24px;
  color: #d1c7b7;
  cursor: pointer;
  transition: transform 0.1s, color 0.1s;
}

.star.active, .star:hover {
  color: #f59e0b;
}

.star:active {
  transform: scale(1.2);
}

.rating-text {
  font-size: 12px;
  color: var(--text-muted);
}

/* Primary Action Button */
.btn-primary {
  width: 100%;
  padding: 14px;
  background-color: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(111, 78, 55, 0.2);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background-color: #a89f91;
  cursor: not-allowed;
  box-shadow: none;
}

/* Speed Test Live Indicator Card */
.speed-test-card {
  display: none;
  margin-top: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.speed-test-card.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

.speed-progress-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
}

.speed-gauges {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.gauge-box {
  background: #fdfbf7;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 6px;
}

.gauge-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.gauge-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  margin-top: 2px;
}

.gauge-unit {
  font-size: 9px;
  color: var(--text-muted);
}

.status-message {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  min-height: 20px;
  font-weight: 500;
}

/* ============================================================
   TAB 2: MAP VIEW STYLES
   ============================================================ */
#map-viewport {
  width: 100%;
  height: calc(100vh - var(--header-height) - var(--safe-top) - var(--nav-height) - var(--safe-bottom));
  height: calc(100dvh - var(--header-height) - var(--safe-top) - var(--nav-height) - var(--safe-bottom));
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
  background: #fdfcf6;
}

.map-floating-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.map-legend {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  display: flex;
  gap: 10px;
  font-size: 10px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.map-recenter-btn {
  pointer-events: auto;
  position: absolute;
  right: 12px;
  bottom: 24px;
  z-index: 500;
  width: 44px;
  height: 44px;
  background: #fff;
  border-radius: 22px;
  border: 1px solid var(--border);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--primary);
  cursor: pointer;
  transition: transform 0.2s;
}

.map-recenter-btn:active {
  transform: scale(0.9);
}

/* ============================================================
   TAB 3: HISTORY ARCHIVE STYLES
   ============================================================ */
.history-container {
  max-width: 650px;
  margin: 0 auto;
  padding: 16px;
}

.history-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.history-search-row {
  display: flex;
  gap: 8px;
}

.search-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

.history-filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.history-filter-row::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.filter-pill:focus {
  outline: none;
}

.history-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.btn-icon {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-icon:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-icon.danger {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}

/* History Cards */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}

.history-card:active {
  transform: scale(0.99);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.card-distance {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-gold);
  background: #fdf6ec;
  padding: 2px 6px;
  border-radius: 10px;
}

.card-address {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.card-wifi-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fdfbf7;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #f0e9df;
  margin-bottom: 10px;
  font-size: 12px;
}

.wifi-name {
  font-weight: 700;
  color: var(--text);
}

.wifi-pwd {
  color: var(--text-muted);
  font-family: monospace;
}

.card-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.stat-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: #f9fafb;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}

.stat-pill-label {
  font-size: 9px;
  font-weight: 700;
  color: #9ca3af;
}

.stat-pill-val {
  font-size: 13px;
  font-weight: 800;
}

.card-notes {
  font-size: 12px;
  color: #555;
  background: #fafafa;
  padding: 8px;
  border-radius: 6px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.card-notes ul {
  margin: 0;
  padding-left: 18px;
}

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #f3ede2;
  padding-top: 10px;
  margin-top: 8px;
}

.card-date {
  font-size: 11px;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 6px;
}

.card-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text);
  cursor: pointer;
}

.card-btn.danger {
  color: #dc2626;
  border-color: #fecaca;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* Modal Sheet */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-sheet {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  padding: 20px 20px calc(20px + var(--safe-bottom)) 20px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
}

.modal-close-btn {
  background: #f3ede2;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* Responsive adjustments for Tablets/Desktops */
@media (min-width: 768px) {
  #app {
    max-width: 900px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.05);
  }
}
