:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #0891b2;
  --accent-dark: #0e7490;
  --green: #059669;
  --red: #dc2626;
  --border: #e2e8f0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
}

.screen-inner {
  max-width: 420px;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

.app-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 1rem;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 25%, transparent);
}

.app-icon.has-custom-logo {
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  background: var(--card);
}

.app-icon.has-custom-logo .site-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  padding: 6px;
}

h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; }
h3 { font-size: 0.875rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 0.75rem; }

.lead { color: var(--muted); margin-bottom: 1.5rem; line-height: 1.5; }
.hint { font-size: 0.8125rem; color: var(--muted); margin: 0.5rem 0 1rem; }

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.375rem;
}

input[type="text"],
input[type="password"],
input[type="url"] {
  width: 100%;
  padding: 0.875rem 1rem;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-family: inherit;
}

.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { opacity: 0.5; }
.btn-primary:not(:disabled):active { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-sm { padding: 0.5rem 0.875rem; font-size: 0.8125rem; }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}

.btn-icon.light { color: #fff; }

.error {
  color: var(--red);
  background: #fef2f2;
  padding: 0.75rem;
  border-radius: 10px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.mobile-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.user-line { font-size: 0.8125rem; color: var(--muted); margin-top: 0.25rem; }

.panel { padding: 1.25rem; }

.panel textarea {
  width: 100%;
  min-height: 100px;
  padding: 0.875rem 1rem;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 0.5rem;
  font-family: inherit;
}

.active-banner {
  background: #ecfeff;
  border: 1px solid #a5f3fc;
  color: var(--accent-dark);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.interval-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1rem 0;
}

.interval-btn {
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.interval-btn.selected {
  border-color: var(--accent);
  background: #ecfeff;
  color: var(--accent-dark);
}

.progress-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.progress-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.progress-bar {
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #06b6d4);
  border-radius: 999px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.btn-scan {
  padding: 1.125rem;
  font-size: 1.125rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 4px 16px rgba(8, 145, 178, 0.3);
}

.scan-history { margin-top: 0.5rem; }

.scan-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.scan-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.875rem 1rem;
}

.scan-list .name { font-weight: 600; font-size: 0.9375rem; }
.scan-list .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.screen-scan {
  background: #000;
  display: flex;
  flex-direction: column;
}

.scan-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  padding-top: calc(0.75rem + var(--safe-top));
  color: #fff;
  background: rgba(0,0,0,0.6);
  font-weight: 500;
}

.scan-header .spacer { width: 44px; }

.scanner-root {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-root video {
  max-height: 100% !important;
}

.scan-footer {
  padding: 1rem 1.25rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  background: rgba(0,0,0,0.85);
  color: #fff;
}

.scan-footer label { color: #94a3b8; font-size: 0.8125rem; }

.scan-footer input {
  flex: 1;
  margin-bottom: 0;
  background: #1e293b;
  border-color: #334155;
  color: #fff;
}

.manual-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.375rem;
}

.scan-feedback {
  min-height: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 0.9375rem;
  font-weight: 500;
}

.scan-feedback.ok { color: #34d399; }
.scan-feedback.err { color: #f87171; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.5rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 0.875rem 1.25rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 100;
  max-width: calc(100% - 2rem);
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
