:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #152033;
  --muted: #718096;
  --faint: #98a4b5;
  --line: #e5eaf1;
  --line-strong: #d7dee9;
  --blue: #1769ff;
  --blue-soft: #eaf1ff;
  --purple: #7c4dff;
  --purple-soft: #f0ebff;
  --green: #12a06a;
  --amber: #d98200;
  --sidebar: #ffffff;
  --shadow: 0 12px 36px rgba(28, 45, 75, .08);
  --sidebar-width: 248px;
}

[data-theme="dark"] {
  --bg: #0e1420;
  --panel: #141c2a;
  --panel-soft: #182232;
  --text: #edf2fa;
  --muted: #9ba9bd;
  --faint: #718096;
  --line: #263246;
  --line-strong: #35435a;
  --blue: #5c91ff;
  --blue-soft: #1d3158;
  --purple: #a98bff;
  --purple-soft: #34275d;
  --green: #4bd3a0;
  --amber: #ffbb54;
  --sidebar: #111927;
  --shadow: 0 16px 42px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { background: var(--bg); color: var(--text); font-family: "DM Sans", system-ui, sans-serif; margin: 0; min-height: 100vh; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; transition: grid-template-columns .25s ease; }
.app-shell.sidebar-collapsed { --sidebar-width: 76px; }
.sidebar { background: var(--sidebar); border-right: 1px solid var(--line); display: flex; flex-direction: column; height: 100vh; overflow: hidden; padding: 18px 14px 14px; position: sticky; top: 0; z-index: 20; }
.sidebar-brand { align-items: center; display: flex; height: 46px; justify-content: space-between; margin-bottom: 20px; padding: 0 6px; }
.brand-lockup { align-items: center; display: flex; gap: 11px; text-decoration: none; }
.brand-mark { align-items: end; display: inline-flex; gap: 2px; height: 22px; justify-content: center; width: 24px; }
.brand-mark span { background: var(--blue); border-radius: 3px; display: block; width: 5px; }
.brand-mark span:nth-child(1) { height: 9px; }
.brand-mark span:nth-child(2) { height: 18px; }
.brand-mark span:nth-child(3) { height: 13px; }
.brand-name { font-size: 1.25rem; font-weight: 700; letter-spacing: -.035em; }
.icon-button { align-items: center; background: transparent; border: 0; border-radius: 9px; color: var(--muted); display: inline-flex; height: 36px; justify-content: center; padding: 0; width: 36px; }
.icon-button:hover { background: var(--panel-soft); color: var(--text); }
.sidebar-toggle { font-size: 1.45rem; transition: transform .25s ease; }
.sidebar-nav, .sidebar-section { display: grid; gap: 4px; }
.sidebar-section { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 18px; }
.sidebar-caption { color: var(--faint); font-size: .68rem; font-weight: 700; letter-spacing: .11em; padding: 0 12px 8px; text-transform: uppercase; white-space: nowrap; }
.nav-item { align-items: center; background: transparent; border: 0; border-radius: 10px; color: var(--muted); display: grid; font-size: .87rem; font-weight: 500; gap: 10px; grid-template-columns: 22px minmax(0, 1fr) auto; min-height: 42px; padding: 0 11px; text-align: left; text-decoration: none; white-space: nowrap; width: 100%; }
.nav-item:hover { background: var(--panel-soft); color: var(--text); }
.nav-item.active { background: var(--blue-soft); color: var(--blue); }
.nav-icon { font-size: 1rem; text-align: center; }
.nav-count { color: var(--faint); font-size: .72rem; }
.category-dot { background: var(--faint); border-radius: 50%; height: 8px; margin-left: 7px; width: 8px; }
.dot-ppc { background: var(--blue); }
.dot-ai { background: var(--purple); }
.tag-symbol { font-weight: 700; }
.sidebar-empty { color: var(--faint); font-size: .78rem; padding: 3px 12px 8px; }
.nav-item.subtle { color: var(--faint); }
.sidebar-footer { border-top: 1px solid var(--line); display: grid; gap: 4px; margin-top: auto; padding-top: 14px; }
.sync-indicator { align-items: center; color: var(--muted); display: flex; font-size: .72rem; gap: 8px; min-height: 34px; padding: 0 12px; white-space: nowrap; }
.status-dot { background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 14%, transparent); height: 7px; width: 7px; }
.status-dot.running { animation: pulse 1.4s infinite; background: var(--amber); }
.sidebar-collapsed .brand-name, .sidebar-collapsed .nav-label, .sidebar-collapsed .nav-count, .sidebar-collapsed .sidebar-caption, .sidebar-collapsed .sidebar-empty { display: none; }
.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
.sidebar-collapsed .nav-item { grid-template-columns: 1fr; justify-items: center; padding: 0; }
.sidebar-collapsed .category-dot { margin: 0; }
.sidebar-collapsed .sync-indicator { justify-content: center; padding: 0; }

.workspace { min-width: 0; }
.topbar { align-items: center; backdrop-filter: blur(16px); background: radial-gradient(circle at 27% 0%, color-mix(in srgb, var(--blue) 10%, transparent), transparent 31%), color-mix(in srgb, var(--bg) 91%, transparent); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; min-height: 74px; padding: 10px clamp(20px, 3.2vw, 48px); position: sticky; top: 0; z-index: 15; }
.topbar::after { background: linear-gradient(90deg, var(--blue), var(--purple), transparent 72%); bottom: -1px; content: ""; height: 2px; left: 0; opacity: .72; position: absolute; width: min(46%, 620px); }
.topbar-title { align-items: center; display: flex; gap: 11px; }
.page-kicker, .section-kicker { color: var(--faint); display: block; font-size: .65rem; font-weight: 700; letter-spacing: .12em; margin-bottom: 3px; }
.topbar h1 { font-size: clamp(1.28rem, 2vw, 1.6rem); font-weight: 700; letter-spacing: -.035em; margin: 0; }
.headline-copy { display: grid; gap: 2px; }
.header-signal { align-items: end; background: linear-gradient(145deg, var(--blue), var(--purple)); border-radius: 11px; box-shadow: 0 7px 18px color-mix(in srgb, var(--blue) 24%, transparent); display: inline-flex; gap: 2px; height: 36px; justify-content: center; padding-bottom: 9px; width: 36px; }
.header-signal span { background: #fff; border-radius: 2px; display: block; opacity: .94; width: 3px; }
.header-signal span:nth-child(1) { height: 7px; }
.header-signal span:nth-child(2) { height: 15px; }
.header-signal span:nth-child(3) { height: 10px; }
.live-label { align-items: center; color: var(--muted); display: flex; font-size: .61rem; font-weight: 600; gap: 5px; letter-spacing: .06em; text-transform: uppercase; }
.live-label i { background: var(--green); border-radius: 50%; box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent); height: 5px; width: 5px; }
.headline-count { border-left: 1px solid var(--line-strong); color: var(--muted); font-size: .76rem; margin-left: 4px; padding-left: 15px; white-space: nowrap; }
.headline-count strong { color: var(--text); }
.mobile-brand-mark { display: none; }
.topbar-actions { align-items: center; display: flex; gap: 9px; }
.topbar-actions form { margin: 0; }
.btn-filter, .btn-refresh, .btn-primary-signal, .btn-quiet { align-items: center; border-radius: 9px; display: inline-flex; font-size: .82rem; font-weight: 600; gap: 7px; justify-content: center; min-height: 40px; padding: 0 14px; text-decoration: none; }
.btn-filter { background: var(--panel); border: 1px solid var(--line-strong); color: var(--text); position: relative; }
.btn-filter:hover { border-color: var(--blue); }
.btn-refresh, .btn-primary-signal { background: var(--blue); border: 1px solid var(--blue); color: #fff; }
.btn-refresh:hover, .btn-primary-signal:hover { filter: brightness(1.08); }
.btn-refresh:disabled { cursor: wait; opacity: .65; }
.active-filter-dot { background: var(--blue); border: 2px solid var(--panel); border-radius: 50%; height: 8px; position: absolute; right: -3px; top: -3px; width: 8px; }
.theme-mobile { display: none; }
.refresh-icon { font-size: 1.05rem; }
.spin { animation: spin 1s linear infinite; display: inline-block; }

.main-content { margin: 0 auto; max-width: 1120px; padding: 12px clamp(20px, 3.2vw, 48px) 70px; }
.notice-stack { display: grid; gap: 8px; }
.notice { border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 9px; color: var(--muted); font-size: .84rem; margin-bottom: 12px; padding: 11px 14px; }
.notice.success { border-left-color: var(--green); }
.notice.warning { border-left-color: var(--amber); }

.filter-drawer { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); display: none; margin-bottom: 18px; padding: 22px; }
.filter-drawer.open { display: block; animation: slideDown .2s ease; }
.drawer-head { align-items: center; display: flex; justify-content: space-between; margin-bottom: 20px; }
.drawer-head h2 { font-size: 1.1rem; font-weight: 700; margin: 0; }
.filter-grid { display: grid; gap: 15px; grid-template-columns: 1.5fr repeat(3, 1fr); }
.field { display: grid; gap: 6px; }
.field label, .tag-menu label { color: var(--muted); font-size: .72rem; font-weight: 600; }
.field input, .field select, .tag-create-form input, .tag-menu select { background: var(--panel-soft); border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); min-height: 40px; outline: none; padding: 0 11px; width: 100%; }
.field input:focus, .field select:focus, .tag-create-form input:focus, .tag-menu select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 15%, transparent); }
.input-with-icon { position: relative; }
.input-with-icon span { color: var(--faint); left: 11px; position: absolute; top: 8px; }
.input-with-icon input { padding-left: 32px; }
.filter-footer { align-items: center; border-top: 1px solid var(--line); display: flex; justify-content: space-between; margin-top: 18px; padding-top: 16px; }
.check-control { align-items: center; color: var(--muted); display: flex; font-size: .8rem; gap: 8px; }
.check-control input { accent-color: var(--blue); height: 16px; width: 16px; }
.filter-buttons { display: flex; gap: 8px; }
.btn-quiet { border: 0; color: var(--muted); }
.drawer-backdrop { background: rgba(6, 12, 24, .5); bottom: 0; display: none; left: 0; position: fixed; right: 0; top: 0; z-index: 1040; }
.drawer-backdrop.open { display: block; }

.tag-drawer { background: var(--panel); border-left: 1px solid var(--line); bottom: 0; box-shadow: -16px 0 42px rgba(0,0,0,.12); display: block; max-width: 430px; overflow-y: auto; padding: 25px; position: fixed; right: 0; top: 0; transform: translateX(105%); transition: transform .25s ease; width: 100%; z-index: 1050; }
.tag-drawer.open { transform: translateX(0); }
.drawer-description { color: var(--muted); font-size: .8rem; line-height: 1.55; margin: -5px 0 20px; }
.tag-create-form { display: grid; gap: 7px; }
.tag-create-form > label { color: var(--muted); font-size: .72rem; font-weight: 600; }
.tag-create-row { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr) auto; }
.tag-list, .article-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list { margin-top: 12px; }
.tag-admin-pill, .user-tag { align-items: center; background: var(--blue-soft); border-radius: 999px; color: var(--blue); display: inline-flex; font-size: .72rem; font-weight: 600; overflow: hidden; padding-left: 9px; }
.tag-admin-pill a { text-decoration: none; }
.tag-admin-pill form, .user-tag form { display: inline-flex; }
.tag-admin-pill button, .user-tag button { background: transparent; border: 0; color: currentColor; padding: 3px 7px; }
.tag-drawer-list { border-top: 1px solid var(--line); display: grid; margin-top: 22px; padding-top: 10px; }
.tag-drawer-item { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; min-height: 48px; }
.tag-drawer-item > a { align-items: center; display: flex; font-size: .84rem; font-weight: 600; gap: 9px; text-decoration: none; }
.tag-drawer-item > a span { color: var(--blue); }
.tag-empty-state { align-items: center; color: var(--muted); display: flex; flex-direction: column; padding: 52px 20px; text-align: center; }
.tag-empty-state > span { color: var(--blue); font-size: 1.7rem; }
.tag-empty-state strong { color: var(--text); font-size: .9rem; margin-top: 9px; }
.tag-empty-state small { font-size: .73rem; margin-top: 5px; }

.feed-toolbar { align-items: center; color: var(--muted); display: flex; font-size: .72rem; justify-content: flex-end; min-height: 38px; padding: 4px 2px; }
.feed-toolbar strong { color: var(--text); }
.view-density { align-items: center; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 8px; display: flex; padding: 2px; }
.density-button { background: transparent; border: 0; border-radius: 6px; color: var(--faint); height: 28px; width: 30px; }
.density-button.active { background: var(--panel); box-shadow: 0 1px 3px rgba(20,30,50,.1); color: var(--blue); }
.news-feed { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: visible; }
.news-item { display: grid; gap: 15px; grid-template-columns: 8px minmax(0, 1fr) auto; padding: 20px 18px 20px 13px; position: relative; transition: background .16s ease; }
.news-item + .news-item { border-top: 1px solid var(--line); }
.news-item:hover { background: var(--panel-soft); }
.news-item.is-read { opacity: .62; }
.news-status { padding-top: 5px; }
.category-marker { background: var(--faint); border-radius: 3px; display: block; height: 28px; width: 3px; }
.marker-ppc { background: var(--blue); }
.marker-ai { background: var(--purple); }
.news-content { min-width: 0; }
.article-meta { align-items: center; color: var(--faint); display: flex; flex-wrap: wrap; font-size: .7rem; gap: 6px; margin-bottom: 7px; }
.category-label { background: var(--blue-soft); border-radius: 4px; color: var(--blue); font-size: .63rem; font-weight: 700; letter-spacing: .07em; padding: 3px 6px; }
.label-ai { background: var(--purple-soft); color: var(--purple); }
.source-name { color: var(--muted); font-weight: 600; }
.unread-label { color: var(--blue); font-size: .59rem; font-weight: 700; letter-spacing: .08em; }
.news-item h2 { font-size: clamp(.96rem, 1.4vw, 1.08rem); font-weight: 600; letter-spacing: -.012em; line-height: 1.4; margin: 0; }
.news-item h2 a { color: var(--text); text-decoration: none; }
.news-item h2 a:hover { color: var(--blue); }
.external-arrow { color: var(--faint); font-size: .82em; opacity: 0; transition: opacity .16s; }
.news-item:hover .external-arrow { opacity: 1; }
.article-description { color: var(--muted); display: -webkit-box; font-size: .79rem; line-height: 1.55; margin: 8px 0 0; max-width: 850px; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.article-tags { margin-top: 10px; }
.article-actions { align-items: start; display: flex; gap: 5px; opacity: .25; transition: opacity .16s; }
.news-item:hover .article-actions, .article-actions:focus-within { opacity: 1; }
.action-button { align-items: center; background: transparent; border: 1px solid transparent; border-radius: 7px; color: var(--muted); cursor: pointer; display: inline-flex; font-size: .84rem; height: 32px; justify-content: center; list-style: none; padding: 0; width: 32px; }
.action-button:hover { background: var(--blue-soft); color: var(--blue); }
.tag-menu { position: relative; }
.tag-menu summary::-webkit-details-marker { display: none; }
.tag-menu form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); display: grid; gap: 8px; min-width: 220px; padding: 12px; position: absolute; right: 0; top: 38px; z-index: 12; }
.tag-menu .btn-primary-signal { min-height: 34px; }
.news-feed.compact .news-item { padding-bottom: 12px; padding-top: 12px; }
.news-feed.compact .article-description { display: none; }
.empty-state { color: var(--muted); padding: 70px 24px; text-align: center; }
.empty-state > span { color: var(--faint); font-size: 2rem; }
.empty-state h2 { color: var(--text); font-size: 1.1rem; margin: 12px 0 6px; }
.empty-state p { font-size: .82rem; margin-bottom: 18px; }
.empty-state .btn-primary-signal { display: inline-flex; }
.mobile-nav { display: none; }

.offline-page { align-items: center; display: flex; justify-content: center; min-height: 100vh; padding: 1rem; }
.offline-card { background: var(--panel); border: 1px solid var(--line); border-radius: 1rem; box-shadow: var(--shadow); max-width: 420px; padding: 2rem; text-align: center; }
.offline-card img { border-radius: 22%; margin-bottom: 1rem; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } }

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .topbar { min-height: 62px; padding: 8px 14px; }
  .mobile-brand-mark { display: inline-flex; }
  .page-kicker { display: none; }
  .topbar h1 { font-size: 1.05rem; }
  .header-signal { border-radius: 9px; height: 32px; padding-bottom: 8px; width: 32px; }
  .live-label { font-size: .56rem; }
  .headline-count { font-size: .68rem; padding-left: 10px; }
  .topbar-actions { gap: 4px; }
  .theme-mobile { display: inline-flex; }
  .btn-filter { display: none; }
  .btn-refresh { min-height: 36px; padding: 0 11px; }
  .main-content { padding: 4px 12px 92px; }
  .filter-drawer { border: 0; border-radius: 18px 18px 0 0; bottom: 0; box-shadow: 0 -14px 42px rgba(0,0,0,.18); display: block; left: 0; margin: 0; max-height: 86vh; overflow-y: auto; padding: 22px 18px 28px; position: fixed; right: 0; transform: translateY(105%); transition: transform .25s ease; z-index: 1050; }
  .filter-drawer.open { animation: none; transform: translateY(0); }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .search-field, .field:nth-child(3), .field:nth-child(4) { grid-column: 1 / -1; }
  .filter-footer { align-items: stretch; flex-direction: column; gap: 14px; }
  .filter-buttons { display: grid; grid-template-columns: 1fr 1.5fr; }
  .tag-drawer { border-radius: 18px 18px 0 0; border-left: 0; box-shadow: 0 -14px 42px rgba(0,0,0,.18); max-height: 86vh; max-width: none; padding: 22px 18px 28px; top: auto; transform: translateY(105%); }
  .tag-drawer.open { transform: translateY(0); }
  .news-feed { border-left: 0; border-radius: 10px; border-right: 0; }
  .news-item { gap: 9px; grid-template-columns: 5px minmax(0, 1fr); padding: 17px 13px 17px 9px; }
  .article-actions { grid-column: 2; opacity: 1; }
  .action-button { border-color: var(--line); }
  .article-description { -webkit-line-clamp: 2; }
  .toolbar-context, .view-density { display: none; }
  .mobile-nav { align-items: stretch; background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr); height: 68px; left: 0; padding-bottom: env(safe-area-inset-bottom); position: fixed; right: 0; z-index: 1030; }
  .mobile-nav a, .mobile-nav button { align-items: center; background: transparent; border: 0; color: var(--faint); display: flex; flex-direction: column; font-size: 1.05rem; gap: 2px; justify-content: center; text-decoration: none; }
  .mobile-nav a.active, .mobile-nav button.active { color: var(--blue); }
  .mobile-nav small { font-size: .62rem; font-weight: 600; }
}

@media (max-width: 480px) {
  .topbar-title .brand-mark { width: 20px; }
  .topbar h1 { font-size: 1rem; }
  .btn-refresh span:last-child { display: none; }
  .btn-refresh { width: 38px; }
  .headline-count { display: none; }
  .tag-create-row { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .filter-grid .field { grid-column: 1; }
  .news-item h2 { font-size: .96rem; }
  .article-meta time { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
