/* CSS Reset & Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --success-color: #16a34a;
  --error-color: #dc2626;
  --warning-color: #f59e0b;
  --text-color: #1f2937;
  --text-muted: #6b7280;
  --bg-color: #f9fafb;
  --card-bg: #ffffff;
  --border-color: #e5e7eb;
  --border-radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
  background-color: var(--bg-color);
  background-image: url("sentinel-door.png");
  background-repeat: no-repeat;
  background-position: right bottom;
  background-size: contain;
  background-attachment: fixed;
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(249, 250, 251, 0.85);
  z-index: -1;
}

/* Container */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 16px;
  padding-top: 8px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 2px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Main Content */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Input Section */
.input-section {
  background: var(--card-bg);
  padding: 12px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.input-section label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text-color);
}

.input-section input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1.1rem;
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
  text-align: center;
}

.input-section input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

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

.input-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

.validation-message {
  font-size: 0.75rem;
  margin-top: 4px;
  text-align: center;
  min-height: 1em;
}

.validation-message.success {
  color: var(--success-color);
}

.validation-message.error {
  color: var(--error-color);
}

/* Scan Section */
.scan-section {
  text-align: center;
}

#scanButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  background-color: var(--primary-color);
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition:
    background-color 0.2s,
    transform 0.1s;
  box-shadow: var(--shadow);
}

#scanButton:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

#scanButton:active:not(:disabled) {
  transform: scale(0.98);
}

#scanButton:disabled {
  background-color: var(--text-muted);
  cursor: not-allowed;
}

#scanButton.scanning {
  background-color: var(--warning-color);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.scan-status {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

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

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

/* Device Section */
.device-section {
  background: var(--card-bg);
  padding: 12px;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

.device-section h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-color);
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.no-devices {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 12px;
}

/* Device Item */
.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  gap: 10px;
}

.device-info {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-status {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.device-status.connected {
  color: var(--success-color);
}

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

/* Device Buttons Container */
.device-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Tag In Button */
.tag-in-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
  background-color: var(--success-color);
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition:
    background-color 0.2s,
    transform 0.1s;
  white-space: nowrap;
}

.tag-in-button:hover:not(:disabled) {
  background-color: #15803d;
}

.tag-in-button:active:not(:disabled) {
  transform: scale(0.96);
}

.tag-in-button:disabled {
  background-color: var(--text-muted);
  cursor: not-allowed;
}

.tag-in-button.sending {
  background-color: var(--warning-color);
}

.tag-in-button.success {
  background-color: var(--success-color);
}

.tag-in-button.error {
  background-color: var(--error-color);
}

/* Repeat Button */
.repeat-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
  background-color: var(--primary-color);
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition:
    background-color 0.2s,
    transform 0.1s;
  white-space: nowrap;
}

.repeat-button:hover:not(:disabled) {
  background-color: var(--primary-hover);
}

.repeat-button:active:not(:disabled) {
  transform: scale(0.96);
}

.repeat-button:disabled {
  background-color: var(--text-muted);
  cursor: not-allowed;
}

.repeat-button.sending {
  background-color: var(--warning-color);
}

/* Compatibility Warning */
.compatibility-warning {
  background-color: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--border-radius);
  padding: 10px;
  text-align: center;
}

.compatibility-warning p {
  color: #92400e;
  font-size: 0.8rem;
}

/* iOS Notice */
.ios-notice {
  background-color: #dbeafe;
  border: 1px solid #3b82f6;
  border-radius: var(--border-radius);
  padding: 10px;
  text-align: center;
}

.ios-notice p {
  color: #1e40af;
  font-size: 0.8rem;
}

.ios-notice a {
  color: #1d4ed8;
  font-weight: 600;
  text-decoration: underline;
}

.ios-notice a:hover {
  color: #1e40af;
}

/* Footer */
footer {
  text-align: center;
  padding: 10px 0;
  margin-top: auto;
}

footer p {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .container {
    padding: 10px;
  }

  header h1 {
    font-size: 1.4rem;
  }

  .input-section input {
    font-size: 1rem;
    padding: 8px 10px;
  }

  #scanButton {
    padding: 8px 16px;
    font-size: 0.9rem;
  }

  .device-item {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .device-buttons {
    display: flex;
    gap: 6px;
  }

  .tag-in-button,
  .repeat-button {
    flex: 1;
    padding: 8px 12px;
  }
}

/* Accessibility - Focus Visible */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }

  * {
    transition-duration: 0.01ms !important;
  }
}
