/* ========== RESET & BASE ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #121212;
  color: #f5f5f5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: #64b5f6;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ========== PAGE SYSTEM ========== */
.page {
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
}

.page.active {
  display: flex;
  flex-direction: column;
}

.page-content {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

/* ========== AUTH PAGES ========== */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 60px;
}

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

.logo img {
  height: 100px;
  width: auto;
  max-width: 250px;
  display: block;
  margin: 0 auto;
}

.auth-link {
  margin-top: 20px;
  font-size: 0.9rem;
  color: #aaa;
  text-align: center;
}

.location-notice {
  margin-top: 32px;
  padding: 12px 16px;
  background: rgba(255, 193, 7, 0.1);
  border: 1px solid rgba(255, 193, 7, 0.3);
  border-radius: 8px;
  font-size: 0.85rem;
  color: #ffc107;
  text-align: center;
  line-height: 1.4;
}

.location-icon {
  font-size: 1.1rem;
  margin-right: 4px;
}

/* ========== HEADER ========== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 16px;
  border-bottom: 1px solid #2a2a2a;
}

.header-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-logo img {
  max-height: 65px;
  width: auto;
  max-width: 80px;
  object-fit: contain;
  display: block;
}

.header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 0;
  max-width: 60%;
}

.header-user {
  font-size: 0.85rem;
  color: #aaa;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========== FORMS ========== */
form {
  width: 100%;
}

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

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #bbb;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 14px 16px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  color: #f5f5f5;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #64b5f6;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23999' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-hint {
  font-size: 0.8rem;
  color: #888;
  margin-bottom: 16px;
}

/* ========== CHECKBOXES (custom) ========== */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  transition: border-color 0.2s, background 0.2s;
  min-height: 52px;
}

.checkbox-label:has(input:checked) {
  border-color: #64b5f6;
  background: rgba(100, 181, 246, 0.08);
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border: 2px solid #555;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.checkbox-label input:checked + .checkbox-custom {
  background: #64b5f6;
  border-color: #64b5f6;
}

.checkbox-label input:checked + .checkbox-custom::after {
  content: '';
  width: 6px;
  height: 12px;
  border: solid #121212;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

/* ========== TOGGLE BUTTON ========== */
.toggle-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-wrapper {
  flex-shrink: 0;
}

.toggle-btn {
  padding: 10px 24px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  color: #aaa;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 80px;
  text-align: center;
}

.toggle-btn.active {
  background: #4CAF50;
  border-color: #4CAF50;
  color: #fff;
  font-weight: 600;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: #64b5f6;
  color: #121212;
}

.btn-outline {
  background: transparent;
  border: 1px solid #555;
  color: #ccc;
  padding: 8px 14px;
  font-size: 0.8rem;
  min-height: 36px;
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.8rem;
  min-height: 36px;
}

.btn-back {
  background: transparent;
  color: #aaa;
  padding: 8px 0;
  font-size: 0.9rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

/* ========== MENU BUTTONS ========== */
.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.btn-menu {
  width: 100%;
  padding: 20px 24px;
  font-size: 1.15rem;
  font-weight: 800;
  border-radius: 12px;
  letter-spacing: 0.08em;
}

.btn-checkin {
  background: #4CAF50;
  color: #fff;
}

.btn-transport {
  background: #00BCD4;
  color: #fff;
}

.btn-aggression {
  background: #f44336;
  color: #fff;
}

.btn-btk {
  background: #2a2a2a;
  color: #f5f5f5;
  border: 1px solid #444;
}

/* ========== PAGE TITLES ========== */
.page-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 24px;
  letter-spacing: 0.03em;
}

.title-checkin { color: #4CAF50; }
.title-transport { color: #00BCD4; }
.title-aggression { color: #f44336; }
.title-btk { color: #e0e0e0; }

.page-top-bar {
  margin-bottom: 8px;
}

.page-bottom-bar {
  margin-top: 24px;
}

/* ========== ERROR / SUCCESS MESSAGES ========== */
.error-msg {
  padding: 10px 14px;
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid rgba(244, 67, 54, 0.3);
  border-radius: 8px;
  color: #ef9a9a;
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.4;
}

.success-msg {
  padding: 10px 14px;
  background: rgba(76, 175, 80, 0.12);
  border: 1px solid rgba(76, 175, 80, 0.3);
  border-radius: 8px;
  color: #a5d6a7;
  font-size: 0.9rem;
  margin-bottom: 16px;
  line-height: 1.4;
}

/* ========== OFFLINE BANNER ========== */
.offline-banner {
  padding: 10px 14px;
  background: rgba(255, 152, 0, 0.12);
  border: 1px solid rgba(255, 152, 0, 0.3);
  border-radius: 8px;
  color: #ffcc80;
  font-size: 0.85rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.offline-banner[hidden] {
  display: none;
}

.offline-icon {
  font-size: 1.1rem;
}

/* ========== SOS BUTTON ========== */
.sos-button {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
}

.sos-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 56px;
  background: #d32f2f;
  border-radius: 28px;
  text-decoration: none !important;
  color: #fff;
  box-shadow: 0 4px 20px rgba(211, 47, 47, 0.5);
  transition: transform 0.2s, box-shadow 0.2s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sos-text {
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  line-height: 1;
}

/* ========== LOCATION GUIDE OVERLAY ========== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay[hidden] {
  display: none;
}

.overlay-content {
  background: #1e1e1e;
  border-radius: 16px;
  padding: 32px 24px 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}

.overlay-icon {
  font-size: 3rem;
  color: #ffc107;
  margin-bottom: 12px;
}

.overlay-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  margin-bottom: 10px;
}

.overlay-desc {
  font-size: 0.9rem;
  color: #aaa;
  line-height: 1.5;
  margin-bottom: 24px;
}

.guide-os-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64b5f6;
  margin-bottom: 12px;
}

.guide-list {
  text-align: left;
  padding-left: 20px;
  margin-bottom: 24px;
}

.guide-list li {
  font-size: 0.9rem;
  color: #ccc;
  line-height: 1.6;
  margin-bottom: 6px;
}

.guide-list li strong {
  color: #fff;
}

#geo-guide-retry {
  margin-bottom: 10px;
}

#geo-guide-dismiss {
  width: 100%;
  text-align: center;
  justify-content: center;
  color: #888;
}

/* ========== ONBOARDING ========== */
.onboarding-icon {
  font-size: 1.1em;
}

.guide-desktop-note {
  font-size: 0.9rem;
  color: #aaa;
  line-height: 1.5;
  margin-bottom: 24px;
}

/* ========== TOAST ========== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  padding: 12px 24px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
  color: #f5f5f5;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-success {
  border-color: rgba(76, 175, 80, 0.5);
  color: #a5d6a7;
}

.toast.toast-warning {
  border-color: rgba(255, 152, 0, 0.5);
  color: #ffcc80;
}

.toast.toast-error {
  border-color: rgba(244, 67, 54, 0.5);
  color: #ef9a9a;
}

/* ========== LOADING SPINNER on buttons ========== */
.btn.loading {
  pointer-events: none;
  opacity: 0.7;
}

.btn.loading::after {
  content: '';
  width: 18px;
  height: 18px;
  margin-left: 10px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== HISTORY PAGE ========== */
.menu-divider {
  border: none;
  border-top: 1px solid #2a2a2a;
  margin: 24px 0 12px;
}

.btn-history {
  background: #1e1e1e;
  color: #aaa;
  border: 1px solid #333;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 14px 24px;
}

.title-history {
  color: #e0e0e0;
}

.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 16px;
}

.btn-retry {
  background: #ff9800;
  color: #121212;
  font-weight: 700;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-card {
  padding: 14px 16px;
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 8px;
}

.history-card.card-unsynced {
  border-color: rgba(255, 152, 0, 0.5);
  background: rgba(255, 152, 0, 0.06);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.history-card-type {
  font-weight: 700;
  font-size: 0.95rem;
}

.history-card-status {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
}

.status-synced {
  color: #a5d6a7;
  background: rgba(76, 175, 80, 0.12);
}

.status-unsynced {
  color: #ffcc80;
  background: rgba(255, 152, 0, 0.15);
}

.history-card-summary {
  font-size: 0.9rem;
  color: #ccc;
  line-height: 1.4;
}

.history-card-time {
  font-size: 0.8rem;
  color: #777;
  margin-top: 4px;
}

.history-empty {
  color: #666;
  font-size: 0.9rem;
  text-align: center;
  padding: 24px 0;
}

/* ========== ATTACHMENTS ========== */
.attachment-widget {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment-add {
  display: block;
  cursor: pointer;
}

.attachment-add-btn {
  display: inline-block;
  padding: 10px 14px;
  border: 1px dashed #555;
  border-radius: 8px;
  color: #aaa;
  font-size: 0.9rem;
  text-align: center;
  width: 100%;
  transition: border-color 0.15s, color 0.15s;
}

.attachment-add:hover .attachment-add-btn {
  border-color: #888;
  color: #ddd;
}

.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #1e1e1e;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  font-size: 0.85rem;
}

.attachment-icon {
  flex-shrink: 0;
  font-size: 1rem;
}

.attachment-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #ddd;
}

.attachment-size {
  flex-shrink: 0;
  color: #777;
  font-size: 0.75rem;
}

.attachment-remove {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #888;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.attachment-remove:hover {
  color: #f44336;
}

.history-card-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}

.history-card-footer .history-card-time {
  margin-top: 0;
  flex: 1;
}

.history-card-images {
  font-size: 0.8rem;
  color: #aaa;
}

.history-attach-btn {
  background: transparent;
  border: 1px solid #444;
  color: #aaa;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
}

.history-attach-btn:hover {
  border-color: #888;
  color: #ddd;
}

/* ========== RESPONSIVE ========== */
@media (min-width: 768px) {
  .page-content {
    padding: 32px 24px 120px;
  }

  .btn-menu {
    padding: 24px;
    font-size: 1.25rem;
  }
}
