/**
 * PageDrop PWA Styles
 * Mobile-first, system fonts, dark/light mode
 */

/* --- Reset & Base --- */

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

:root {
  --brand: #3498db;
  --brand-dark: #2980b9;
  --brand-light: #5dade2;

  --bg: #ffffff;
  --bg-secondary: #f8f9fa;
  --text: #1a1a2e;
  --text-secondary: #6c757d;
  --border: #dee2e6;
  --success: #27ae60;
  --error: #e74c3c;
  --shadow: rgba(0, 0, 0, 0.1);

  --radius: 12px;
  --radius-sm: 8px;
  --transition: 200ms ease;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a2e;
    --bg-secondary: #16213e;
    --text: #e8e8e8;
    --text-secondary: #a0a0b0;
    --border: #2d2d44;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* --- Layout --- */

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- Screens --- */

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  animation: fadeIn var(--transition) forwards;
}

.screen.active {
  display: flex;
}

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

/* --- Header --- */

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.5px;
}

.header p {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* --- Pairing Code Inputs --- */

.pairing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.pairing-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.pairing-grid .label-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.pairing-input {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem;
  font-size: 1.125rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.pairing-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.pairing-input.error {
  border-color: var(--error);
}

.pairing-input.success {
  border-color: var(--success);
}

/* --- Buttons --- */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0.875rem 1.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color var(--transition), transform 100ms ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

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

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

.btn-primary {
  background-color: var(--brand);
  color: #ffffff;
  width: 100%;
}

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

.btn-secondary {
  background-color: transparent;
  color: var(--brand);
  border: 2px solid var(--brand);
  width: 100%;
}

.btn-secondary:hover:not(:disabled) {
  background-color: rgba(52, 152, 219, 0.08);
}

.btn-text {
  background: none;
  border: none;
  color: var(--brand);
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  padding: 0.5rem;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.btn-text:hover {
  text-decoration: underline;
}

/* --- Save Screen --- */

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success);
  flex-shrink: 0;
}

.status-dot.disconnected {
  background-color: var(--error);
}

.status-channel {
  color: var(--text-secondary);
  font-family: "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.8125rem;
}

.url-input-group {
  margin-bottom: 1rem;
}

.url-input {
  width: 100%;
  min-height: 52px;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.url-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.url-input::placeholder {
  color: var(--text-secondary);
}

.title-input {
  width: 100%;
  min-height: 44px;
  padding: 0.75rem 1rem;
  font-size: 0.9375rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  transition: border-color var(--transition);
  margin-top: 0.75rem;
  -webkit-appearance: none;
  appearance: none;
}

.title-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.title-input::placeholder {
  color: var(--text-secondary);
}

.save-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.screen-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

/* --- History Screen --- */

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.history-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.875rem 1rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--success);
}

.history-item.queued {
  border-left-color: var(--brand);
}

.history-item.failed {
  border-left-color: var(--error);
}

.history-title {
  font-weight: 600;
  font-size: 0.9375rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-url {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.125rem;
}

.history-status {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.history-status.sent {
  color: var(--success);
}

.history-status.queued {
  color: var(--brand);
}

.history-status.failed {
  color: var(--error);
}

.history-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 3rem 1rem;
  font-size: 1rem;
}

/* --- Toast --- */

.toast-container {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  pointer-events: none;
  width: calc(100% - 2rem);
  max-width: 440px;
}

.toast {
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
  animation: toastIn 300ms ease forwards;
  pointer-events: auto;
}

.toast.success {
  background-color: var(--success);
  color: #ffffff;
}

.toast.error {
  background-color: var(--error);
  color: #ffffff;
}

.toast.hiding {
  animation: toastOut 300ms ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(16px);
  }
}

/* --- Bookmarklet Section --- */

.bookmarklet-section {
  margin-top: 2rem;
  padding: 1rem;
  background-color: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.bookmarklet-section h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.bookmarklet-section p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
  line-height: 1.6;
}

.bookmarklet-code {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  font-size: 0.75rem;
  font-family: "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--bg);
  color: var(--text);
  resize: vertical;
  -webkit-appearance: none;
  appearance: none;
}

.bookmarklet-code:focus {
  outline: none;
  border-color: var(--brand);
}

/* --- Loading Spinner --- */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  margin-right: 0.5rem;
}

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

/* --- Error Message --- */

.error-message {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  min-height: 1.25rem;
}

/* --- Disconnect link --- */

.disconnect-link {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
  padding: 0.25rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.disconnect-link:hover {
  color: var(--error);
}

/* --- Visually hidden (screen reader only) --- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
