:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --border: #334155;
  --radius: 16px;
  --alarm: #ef4444;
  --important: #f59e0b;
  --attention: #3b82f6;
  --notice: #64748b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--danger); }

.view { max-width: 540px; margin: 0 auto; padding: 16px; }

/* ---- Login ---- */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  padding: 32px 24px;
}
.login-card .logo {
  width: 88px; height: 88px;
  border-radius: 22px;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.login-card h1 { font-size: 1.6rem; margin-bottom: 4px; }
.login-card p { margin-bottom: 24px; }
#login-form { display: flex; flex-direction: column; gap: 12px; }

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 1rem;
}
input:focus { outline: none; border-color: var(--primary); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 0.85rem;
}
.btn-ghost:hover { color: var(--text); }

/* ---- App header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 20px;
}
.app-header strong { display: block; font-size: 1.1rem; }

/* ---- Cards ---- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { font-size: 1.05rem; margin-bottom: 2px; }
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint {
  margin-top: 16px;
  padding: 14px;
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
}
.ios-share {
  display: inline-block;
  border: 1px solid var(--muted);
  border-radius: 5px;
  padding: 0 5px;
}

/* ---- Switch ---- */
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex-shrink: 0; }
.switch.small { width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-elev-2);
  border-radius: 999px;
  transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute;
  height: 22px; width: 22px; left: 4px; bottom: 4px;
  background: white; border-radius: 50%; transition: 0.2s;
}
.switch.small .slider::before { height: 18px; width: 18px; }
input:checked + .slider { background: var(--success); }
input:checked + .slider::before { transform: translateX(22px); }
.switch.small input:checked + .slider::before { transform: translateX(18px); }

/* ---- Channel list ---- */
.channel-list { list-style: none; margin-top: 14px; }
.channel-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}
.channel-list li:first-child { border-top: none; }
.channel-list strong { display: block; }

/* ---- History ---- */
.history-list { list-style: none; margin-top: 8px; }
.history-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 14px 14px;
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--notice);
  margin-left: -3px;
}
.history-item:first-child { border-top: none; }
.history-item.channel-alarm { border-left-color: var(--alarm); }
.history-item.channel-important { border-left-color: var(--important); }
.history-item.channel-attention { border-left-color: var(--attention); }
.history-item.channel-notice { border-left-color: var(--notice); }
.history-item.clickable { cursor: pointer; }
.history-item.clickable:hover { background: rgba(255,255,255,0.03); }
.history-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-main span { word-break: break-word; }
.history-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--muted);
  white-space: nowrap;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 100;
  max-width: 90%;
}
.toast.error { background: var(--danger); }
