:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e4e7eb;
  --text: #1a202c;
  --text-mute: #6b7280;
  --primary: #d52b1e;
  --primary-hover: #b32319;
  --danger: #b00020;
  --link: #1a73e8;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.badge-count {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 4px;
}
.badge-count:empty,
.badge-count[data-count="0"] { display: none; }

.container {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.note {
  color: var(--text-mute);
  font-size: 12px;
  margin: 6px 0;
}

.note a { color: var(--link); text-decoration: none; }
.note a:hover { text-decoration: underline; }

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.row.align-right {
  justify-content: flex-end;
  margin-top: 14px;
}

label {
  display: block;
  font-size: 12px;
  color: var(--text-mute);
  margin: 4px 0 6px;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
select {
  flex: 1 1 auto;
  min-width: 200px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(213, 43, 30, 0.12);
}

button {
  cursor: pointer;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}
.primary-btn:hover:not(:disabled) { background: var(--primary-hover); }
.primary-btn.large { padding: 11px 28px; font-size: 15px; font-weight: 600; }

.ghost-btn {
  background: #fff;
  border-color: var(--border);
  color: var(--text);
}
.ghost-btn:hover:not(:disabled) { background: #f4f6f8; }

.danger-btn {
  background: #fff;
  border-color: var(--border);
  color: var(--danger);
}
.danger-btn:hover:not(:disabled) { background: #fff5f5; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  margin: 0;
  cursor: pointer;
}
.checkbox input { width: 16px; height: 16px; }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: -4px -4px 16px;
}
.tab {
  background: transparent;
  border: none;
  padding: 10px 16px;
  color: var(--text-mute);
  border-bottom: 2px solid transparent;
  border-radius: 0;
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.mode-panel { padding: 4px 0 0; }
.hidden { display: none !important; }

.status {
  font-size: 13px;
  color: var(--text-mute);
  margin: 8px 0 0;
}
.status.error { color: var(--danger); font-weight: 500; }
.status.ok { color: #0a7c2f; font-weight: 500; }

.loader {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 12px;
  gap: 12px;
}

.filter-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 12px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 12px;
}
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
}
.filter-label {
  font-size: 11px;
  color: var(--text-mute);
  font-weight: 500;
}
.filter-item select {
  min-width: 160px;
  padding: 7px 10px;
  flex: none;
}
.ghost-btn.small { padding: 7px 12px; font-size: 13px; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: #fafafa;
  position: sticky;
  top: 0;
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--text-mute);
  cursor: pointer;
  user-select: none;
}
th:hover { color: var(--text); }
th.sort-asc::after { content: " ▲"; font-size: 10px; }
th.sort-desc::after { content: " ▼"; font-size: 10px; }

tbody tr:hover { background: #fafbfc; }

td.col-title {
  min-width: 380px;
  max-width: 560px;
  white-space: normal;
  word-break: break-word;
  font-weight: 500;
}
td.col-channel {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.col-channel span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
td a {
  color: var(--link);
  text-decoration: none;
}
td a:hover { text-decoration: underline; }

td.col-thumb img {
  width: 96px;
  height: 54px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

td.col-rate {
  font-weight: 600;
  color: var(--primary);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-short { background: #fef3c7; color: #92400e; }
.badge-normal { background: #e0f2fe; color: #075985; }
.badge-trend { background: #dcfce7; color: #166534; margin-left: 4px; }
.badge-trend.down { background: #fee2e2; color: #991b1b; }
.badge-trend.new { background: #fef9c3; color: #854d0e; }

.filter-search { flex: 1 1 200px; min-width: 200px; }
.filter-search input { min-width: 0; width: 100%; padding: 7px 10px; }

.star-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.3;
  transition: opacity 0.1s, transform 0.1s;
}
.star-btn:hover { opacity: 0.7; transform: scale(1.15); }
.star-btn.pinned { opacity: 1; }

/* モーダル */
.modal { position: fixed; inset: 0; z-index: 1000; }
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
}
.modal-body {
  position: relative;
  max-width: 720px;
  margin: 60px auto;
  background: #fff;
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: transparent; border: none; font-size: 24px;
  cursor: pointer; color: var(--text-mute); padding: 0 8px;
}
.modal-footer {
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}

.history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafbfc;
}
.history-item:hover { background: #f3f4f6; }
.history-meta { font-size: 12px; color: var(--text-mute); }
.history-actions { display: flex; gap: 6px; }
.history-actions button { padding: 5px 12px; font-size: 12px; }
.history-empty { color: var(--text-mute); text-align: center; padding: 24px; }

.footer {
  text-align: center;
  color: var(--text-mute);
  font-size: 12px;
  padding: 24px;
}

@media (max-width: 720px) {
  .topbar-inner, .container { padding-left: 12px; padding-right: 12px; }
  input[type="text"], input[type="password"], select { min-width: 140px; }
  td.col-thumb img { width: 64px; height: 36px; }
}
