/* MilkyWay ASO — dark, minimal, Astro-flavoured */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0c0d12;
  --panel: #14161d;
  --panel-2: #1a1d26;
  --panel-3: #222634;
  --border: #262a38;
  --text: #e8eaf2;
  --text-dim: #9aa0b4;
  --text-faint: #5c627a;
  --accent: #7c5cff;
  --accent-2: #4f8cff;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --radius: 10px;
  font-size: 14px;
}

html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 240px; min-width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.side-head { padding: 16px 14px 10px; }
.logo { font-size: 16px; font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.logo em { font-style: normal; background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

#app-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.app-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px; border-radius: var(--radius);
  cursor: pointer; position: relative;
  border: 1px solid transparent;
}
.app-item:hover { background: var(--panel-2); }
.app-item.active { background: var(--panel-3); border-color: var(--border); }
.app-item img { width: 32px; height: 32px; border-radius: 7px; background: var(--panel-3); }
.app-item .ai-meta { min-width: 0; flex: 1; }
.app-item .ai-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-item .ai-sub { font-size: 11px; color: var(--text-faint); display: flex; gap: 5px; align-items: center; }
.app-item .ai-del {
  opacity: 0; border: none; background: none; color: var(--text-faint);
  cursor: pointer; font-size: 13px; padding: 4px; border-radius: 6px;
}
.app-item:hover .ai-del { opacity: 1; }
.app-item .ai-del:hover { color: var(--red); background: rgba(248,113,113,.1); }

.side-add { margin: 10px 12px 6px; }
.side-io { display: flex; gap: 6px; padding: 0 12px; }
.side-io .btn { flex: 1; }
.side-foot { padding: 8px 14px 14px; font-size: 11px; color: var(--text-faint); text-align: center; line-height: 1.4; }
#storage-note { border-bottom: 1px dotted var(--text-faint); cursor: help; }

/* ---------- buttons / inputs ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: filter .12s, background .12s;
}
.btn:hover { background: var(--panel-3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-accent {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border: none; color: #fff;
}
.btn-accent:hover { filter: brightness(1.12); background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-lg { padding: 11px 22px; font-size: 15px; border-radius: 10px; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }

input[type=text], textarea, select {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 11px; font-size: 13px; font-family: inherit;
  outline: none;
}
input[type=text]:focus, textarea:focus, select:focus { border-color: var(--accent); }
::placeholder { color: var(--text-faint); }

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#empty-state { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-card { text-align: center; max-width: 420px; padding: 40px; }
.empty-icon { font-size: 54px; margin-bottom: 18px; }
.empty-card h1 { font-size: 24px; margin-bottom: 10px; }
.empty-card p { color: var(--text-dim); margin-bottom: 26px; line-height: 1.5; }

#workspace { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#app-header {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 22px 12px; border-bottom: 1px solid transparent;
}
#app-header img.hdr-icon { width: 52px; height: 52px; border-radius: 12px; }
.hdr-meta { flex: 1; min-width: 0; }
.hdr-name { font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; display: flex; gap: 12px; flex-wrap: wrap; }
.hdr-sub .star { color: var(--yellow); }
.hdr-actions { display: flex; gap: 8px; align-items: center; }

#tabs { display: flex; gap: 2px; padding: 0 22px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--text-dim); font-size: 13px; font-weight: 600;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

#tab-content { flex: 1; overflow-y: auto; padding: 16px 22px 40px; min-height: 0; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: flex-start; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 200px; }
.add-kw-box { display: flex; gap: 8px; flex: 2; min-width: 300px; }
.add-kw-box textarea { flex: 1; resize: vertical; min-height: 38px; max-height: 120px; height: 38px; }
.progress-note { font-size: 12px; color: var(--text-dim); align-self: center; white-space: nowrap; }

/* ---------- keywords table ---------- */
.kw-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table.kw { width: 100%; border-collapse: collapse; min-width: 860px; }
table.kw th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-faint); padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap; position: sticky; top: 0; background: var(--panel); z-index: 2;
}
table.kw th:hover { color: var(--text-dim); }
table.kw th .arrow { font-size: 9px; margin-left: 3px; }
table.kw td { padding: 9px 12px; border-bottom: 1px solid rgba(38,42,56,.55); font-size: 13px; white-space: nowrap; }
table.kw tbody tr { cursor: pointer; }
table.kw tbody tr:hover { background: var(--panel-2); }
table.kw tbody tr:last-child td { border-bottom: none; }

.kw-term { font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.num { font-variant-numeric: tabular-nums; }

.pill {
  display: inline-block; min-width: 34px; text-align: center;
  padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pill.pop-hi { background: rgba(124,92,255,.22); color: #b9a5ff; }
.pill.pop-mid { background: rgba(79,140,255,.18); color: #8fb4ff; }
.pill.pop-lo { background: var(--panel-3); color: var(--text-faint); }
.pill.diff-hi { background: rgba(248,113,113,.16); color: var(--red); }
.pill.diff-mid { background: rgba(251,191,36,.14); color: var(--yellow); }
.pill.diff-lo { background: rgba(52,211,153,.14); color: var(--green); }

.rank { font-weight: 700; font-variant-numeric: tabular-nums; }
.rank.top { color: var(--green); }
.rank.mid { color: var(--yellow); }
.rank.low { color: var(--text-dim); }
.rank.none { color: var(--text-faint); font-weight: 400; }

.delta { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--text-faint); font-weight: 400; }

.mini-icons { display: flex; align-items: center; }
.mini-icons img { width: 22px; height: 22px; border-radius: 5px; border: 2px solid var(--panel); margin-left: -7px; }
.mini-icons img:first-child { margin-left: 0; }

.row-del { border: none; background: none; color: var(--text-faint); cursor: pointer; padding: 3px 7px; border-radius: 6px; opacity: 0; font-size: 13px; }
tr:hover .row-del { opacity: 1; }
.row-del:hover { color: var(--red); background: rgba(248,113,113,.1); }

.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--text-faint); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.table-note { padding: 30px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- drawer ---------- */
#drawer-wrap { position: fixed; inset: 0; z-index: 50; }
#drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 520px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 22px; animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.drawer-head h2 { font-size: 20px; overflow-wrap: anywhere; min-width: 0; }
.drawer-close { border: none; background: none; color: var(--text-dim); font-size: 20px; cursor: pointer; }
.drawer-sub { color: var(--text-dim); font-size: 12px; margin-bottom: 16px; display: flex; gap: 14px; flex-wrap: wrap; }

.chart-box { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 18px; }
.chart-box h3, .sec h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-faint); margin-bottom: 10px; }
.chart-empty { color: var(--text-faint); font-size: 12px; text-align: center; padding: 26px 0; }

.sec { margin-bottom: 20px; }
.serp-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; }
.serp-item.mine { background: rgba(124,92,255,.12); outline: 1px solid rgba(124,92,255,.35); }
.serp-item.comp { background: rgba(79,140,255,.08); }
.serp-item img { width: 30px; height: 30px; border-radius: 7px; }
.serp-pos { width: 26px; text-align: right; color: var(--text-faint); font-variant-numeric: tabular-nums; font-weight: 600; }
.serp-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }
.serp-dev { font-size: 11px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.serp-meta { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; font-size: 12px; cursor: pointer; color: var(--text);
  max-width: 100%; overflow-wrap: anywhere; text-align: left;
}
.chip:hover { border-color: var(--accent); }
.chip.added { opacity: .45; cursor: default; }

/* ---------- ratings-by-store drawer ---------- */
.rt-big { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rt-cap { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
table.rt-table { min-width: 0; width: 100%; }
table.rt-table td { white-space: nowrap; }
table.rt-table tbody tr { cursor: default; }
.rt-dim { color: var(--text-faint); font-size: 12px; }
.rt-loc { font-size: 11px; color: var(--text-faint); margin-top: 1px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.rt-stars { color: var(--yellow); font-variant-numeric: tabular-nums; }
tr.rt-cur { background: rgba(124,92,255,.12); }
tr.rt-cur td:first-child { box-shadow: inset 2px 0 0 var(--accent); font-weight: 700; }
.rt-bar-wrap { position: relative; display: block; min-width: 96px; height: 16px; }
.rt-bar {
  position: absolute; left: 0; top: 3px; height: 10px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); opacity: .5;
}
.rt-bar-num { position: relative; font-size: 11px; font-variant-numeric: tabular-nums; line-height: 16px; padding-left: 4px; }

/* ---------- modal ---------- */
#modal-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-start; justify-content: center; }
#modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
#modal {
  position: relative; margin-top: 9vh; width: 560px; max-width: 92vw; max-height: 78vh;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; overflow-y: auto; animation: pop .15s ease-out;
}
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
#modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal-row { display: flex; gap: 8px; margin-bottom: 12px; }
.modal-row input[type=text] { flex: 1; }
.result-item { display: flex; align-items: center; gap: 11px; padding: 8px; border-radius: 9px; cursor: pointer; }
.result-item:hover { background: var(--panel-2); }
.result-item img { width: 40px; height: 40px; border-radius: 9px; }
.ri-meta { flex: 1; min-width: 0; }
.ri-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ri-sub { font-size: 11px; color: var(--text-faint); }
.modal-note { color: var(--text-faint); font-size: 12px; text-align: center; padding: 18px 0; }

/* ---------- suggestions & competitors tabs ---------- */
.sugg-head { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.sugg-grid { display: flex; flex-direction: column; gap: 4px; }
.sugg-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--border); }
.sugg-term { flex: 1; font-weight: 600; font-size: 13px; min-width: 0; overflow-wrap: anywhere; }

.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin-bottom: 22px; }
.comp-card { display: flex; align-items: center; gap: 11px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px; }
.comp-card img { width: 42px; height: 42px; border-radius: 9px; }
.cc-meta { flex: 1; min-width: 0; }
.cc-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cc-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }

.matrix-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table.matrix { border-collapse: collapse; min-width: 100%; }
table.matrix th, table.matrix td { padding: 8px 12px; font-size: 12px; border-bottom: 1px solid rgba(38,42,56,.55); white-space: nowrap; text-align: center; }
table.matrix th { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
table.matrix th:first-child, table.matrix td:first-child { text-align: left; font-weight: 600; }
table.matrix th img { width: 26px; height: 26px; border-radius: 6px; vertical-align: middle; }

.sec-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); margin: 4px 0 10px; }
.hint-text { font-size: 12px; color: var(--text-faint); margin-bottom: 12px; line-height: 1.5; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--panel-3); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 100;
  transition: transform .2s ease; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
#toast.show { transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
