:root {
  --bg: #00121c;
  --surface: #001e2e;
  --surface-light: #003049;
  --text: #f8fafc;
  --text-muted: #8fb3c7;
  --accent: #0095DA;
  --accent-hover: #007bb8;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 1.25rem;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

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

html {
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: radial-gradient(ellipse at top, #003049 0%, var(--bg) 60%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 1.5rem;
}

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

.logo {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.logo svg {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--accent);
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.025em;
}

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

.header .subtitle {
  color: #7dd3fc;
}

.gates {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}

.gate-card {
  background: linear-gradient(145deg, var(--surface) 0%, #00263a 100%);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow), 0 0 0 1px rgba(0, 149, 218, 0.08);
  border: 1px solid rgba(0, 149, 218, 0.12);
}

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

.gate-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
}

.status {
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  background: rgba(0, 149, 218, 0.1);
  color: var(--accent);
  transition: background 0.2s, color 0.2s;
}

.status-open {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.status-closed {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.status-unknown {
  background: rgba(245, 158, 11, 0.15);
  color: var(--warning);
}

.gate-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.9rem 1rem;
  border: none;
  border-radius: 0.875rem;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  cursor: pointer;
  transition: transform 0.1s, filter 0.2s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

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

.btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

.btn .spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.btn-open {
  background: linear-gradient(135deg, var(--success), #16a34a);
}

.btn-open:hover,
.btn-open:focus {
  filter: brightness(1.1);
}

.btn-close {
  background: linear-gradient(135deg, var(--danger), #dc2626);
}

.btn-close:hover,
.btn-close:focus {
  filter: brightness(1.1);
}

.btn-toggle-manual {
  width: 100%;
  margin-top: 0.75rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(0, 149, 218, 0.3);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
}

.btn-toggle-manual:hover,
.btn-toggle-manual:focus {
  background: rgba(0, 149, 218, 0.1);
}

.manual-controls {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid rgba(0, 149, 218, 0.12);
}

.manual-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

.manual-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.manual-relay {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  gap: 0.5rem;
}

.manual-relay span {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

.btn-manual-on {
  background: linear-gradient(135deg, var(--accent), #007bb8);
}

.btn-manual-on:hover,
.btn-manual-on:focus {
  filter: brightness(1.1);
}

.btn-manual-off {
  background: linear-gradient(135deg, #64748b, #475569);
}

.btn-manual-off:hover,
.btn-manual-off:focus {
  filter: brightness(1.1);
}

.info {
  background: linear-gradient(145deg, rgba(0, 30, 46, 0.8) 0%, rgba(0, 38, 58, 0.6) 100%);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid rgba(0, 149, 218, 0.12);
}

.info h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.info p {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.info p:last-child {
  margin-bottom: 0;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: linear-gradient(145deg, var(--surface) 0%, #00263a 100%);
  color: var(--text);
  padding: 0.875rem 1.5rem;
  border-radius: 9999px;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 100;
  white-space: nowrap;
  border: 1px solid rgba(0, 149, 218, 0.2);
}

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

.toast--success {
  border-color: rgba(34, 197, 94, 0.3);
}

.toast--error {
  border-color: rgba(239, 68, 68, 0.3);
}

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

@media (max-width: 360px) {
  .app {
    padding: 1rem;
  }

  .logo h1 {
    font-size: 1.5rem;
  }

  .gate-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}
