:root {
  --bg: #0b1016;
  --bg-raised: #111923;
  --bg-soft: #16212e;
  --border: #223143;
  --border-soft: #1a2735;
  --text: #e8eef6;
  --muted: #8ca0b5;
  --accent: #54c7a1;
  --accent-strong: #38ad87;
  --blue: #6aa8ff;
  --amber: #e6b35a;
  --red: #ef7b7b;
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; }
h1, h2, h3, p { margin: 0; }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex: 0 0 250px; background: #0e151e; border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 2px 6px 24px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(145deg, #2dbb93, #1d7f68); font-weight: 800; letter-spacing: .04em;
}
.brand strong { display: block; font-size: 17px; }
.brand span { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.nav { display: flex; flex-direction: column; gap: 5px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; border: 0; background: transparent; color: var(--muted);
  padding: 10px 12px; border-radius: 9px; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.active { background: rgba(84, 199, 161, .12); color: var(--accent); }
.nav-icon { width: 18px; height: 18px; display: inline-flex; }
.nav-icon svg { width: 18px; height: 18px; }
.sidebar-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; padding: 0 8px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-dot.online { background: var(--accent); box-shadow: 0 0 0 4px rgba(84, 199, 161, .12); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 4px rgba(239, 123, 123, .12); }
.status-dot.warning { background: var(--amber); }

.main { min-width: 0; flex: 1; padding: 26px 34px 60px; max-width: 1600px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 26px; }
.topbar h1 { font-size: 26px; letter-spacing: -.02em; }
.topbar p { color: var(--muted); margin-top: 4px; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.page { display: none; animation: fade .18s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.btn {
  border: 1px solid var(--border); background: var(--bg-raised); color: var(--text); border-radius: 8px;
  padding: 9px 14px; cursor: pointer; transition: .15s ease; white-space: nowrap;
}
.btn:hover { border-color: #334a63; background: var(--bg-soft); }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #04120d; font-weight: 700; }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: rgba(239, 123, 123, .35); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }
.link-button { border: 0; background: transparent; color: var(--accent); cursor: pointer; padding: 0; }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: linear-gradient(180deg, var(--bg-raised), #0f1721); border: 1px solid var(--border-soft); border-radius: 12px; padding: 16px; }
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .value { font-size: 27px; font-weight: 750; margin-top: 5px; letter-spacing: -.02em; }
.stat-card .hint { color: var(--muted); font-size: 11px; margin-top: 3px; }
.panel-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; }
.panel { background: var(--bg-raised); border: 1px solid var(--border-soft); border-radius: 12px; padding: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; }
.panel-head.standalone { margin: 24px 0 12px; }
.panel h2 { font-size: 15px; }
.muted { color: var(--muted); }
.simple-list { display: flex; flex-direction: column; gap: 2px; }
.simple-row { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid var(--border-soft); }
.simple-row:last-child { border-bottom: 0; }
.simple-row .grow { flex: 1; min-width: 0; }
.simple-row strong { font-weight: 600; }
.simple-row .meta { color: var(--muted); font-size: 11px; }

.toolbar { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-bottom: 18px; }
.location-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.location-chip { border: 1px solid var(--border); background: var(--bg-raised); color: var(--muted); border-radius: 99px; padding: 5px 11px; font-size: 12px; }
.connection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.connection-card { background: var(--bg-raised); border: 1px solid var(--border-soft); border-radius: 13px; padding: 17px; display: flex; flex-direction: column; gap: 13px; }
.connection-card.offline { border-color: rgba(239, 123, 123, .2); }
.connection-card.disabled { opacity: .62; }
.conn-head { display: flex; gap: 12px; align-items: flex-start; }
.conn-icon {
  width: 42px; height: 42px; border-radius: 11px; background: var(--bg-soft); border: 1px solid var(--border);
  display: grid; place-items: center; flex: 0 0 auto;
}
.conn-icon svg { width: 22px; height: 22px; }
.conn-title { flex: 1; min-width: 0; }
.conn-title strong { font-size: 15px; }
.conn-title .sub { color: var(--muted); font-size: 11px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-status { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.conn-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; color: var(--muted); font-size: 11px; }
.conn-meta strong { display: block; color: var(--text); font-size: 12px; font-weight: 500; margin-top: 1px; }
.conn-actions { display: flex; gap: 7px; flex-wrap: wrap; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.scan-progress { background: var(--bg-soft); border-radius: 7px; padding: 9px 10px; font-size: 11px; color: var(--muted); display: none; }
.scan-progress.visible { display: block; }
.progress-track { height: 4px; background: #0b121a; border-radius: 99px; overflow: hidden; margin-top: 7px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; width: 0; transition: width .3s ease; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 15px; }
.input { background: #0d151f; border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 9px 11px; min-width: 0; }
.input:focus { outline: 0; border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(84, 199, 161, .1); }
#file-search { flex: 1 1 240px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); padding: 9px 8px; white-space: nowrap; }
.data-table td { border-bottom: 1px solid var(--border-soft); padding: 9px 8px; vertical-align: middle; }
.data-table tr:hover td { background: rgba(255, 255, 255, .018); }
.data-table .name-cell { display: flex; align-items: center; gap: 8px; min-width: 180px; }
.data-table .path-cell { color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-check { width: 34px; }
.badge { display: inline-flex; align-items: center; border-radius: 99px; padding: 3px 7px; font-size: 10px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.badge.green { color: var(--accent); border-color: rgba(84, 199, 161, .28); background: rgba(84, 199, 161, .08); }
.badge.amber { color: var(--amber); border-color: rgba(230, 179, 90, .28); background: rgba(230, 179, 90, .08); }
.badge.red { color: var(--red); border-color: rgba(239, 123, 123, .28); background: rgba(239, 123, 123, .08); }
.badge.blue { color: var(--blue); border-color: rgba(106, 168, 255, .28); background: rgba(106, 168, 255, .08); }
.mono { font-family: "SFMono-Regular", Consolas, monospace; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; color: var(--muted); font-size: 12px; }
.pager { display: flex; align-items: center; gap: 10px; }

.reference-panel { display: flex; justify-content: space-between; gap: 22px; align-items: center; margin-bottom: 14px; }
.reference-panel p { color: var(--muted); font-size: 12px; margin-top: 4px; max-width: 580px; }
.reference-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.duplicate-list { display: flex; flex-direction: column; gap: 12px; }
.duplicate-group { background: var(--bg-raised); border: 1px solid var(--border-soft); border-radius: 11px; padding: 14px 16px; }
.duplicate-group.candidate { border-color: rgba(230, 179, 90, .2); }
.dup-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 9px; }
.dup-head strong { font-size: 13px; }
.dup-file { display: grid; grid-template-columns: 28px minmax(120px, 1fr) minmax(100px, .7fr) minmax(200px, 1.4fr); gap: 10px; padding: 7px 4px; border-top: 1px solid var(--border-soft); font-size: 11px; align-items: center; }
.dup-file .path { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dup-file .source { color: var(--text); }
.empty { border: 1px dashed var(--border); border-radius: 10px; padding: 26px; text-align: center; color: var(--muted); }

.settings-panel { max-width: 760px; }
.settings-panel p { margin: 6px 0 18px; }
.settings-form { display: flex; flex-direction: column; gap: 15px; }
.settings-form label { display: flex; flex-direction: column; gap: 7px; color: var(--muted); font-size: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.setting-note { color: var(--muted); font-size: 11px; border: 1px solid var(--border-soft); border-radius: 8px; padding: 10px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(3, 7, 11, .75); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--bg-raised); border: 1px solid var(--border); border-radius: 14px; width: min(720px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h2 { font-size: 17px; }
.modal-body { padding: 20px; overflow: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { color: var(--muted); font-size: 12px; }
.form-field .hint { color: var(--muted); font-size: 10px; }
.form-field input, .form-field select, .form-field textarea {
  background: #0d151f; border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 9px 11px;
}
.form-field textarea { min-height: 88px; resize: vertical; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: 0; border-color: var(--accent-strong); }
.form-section-title { grid-column: 1 / -1; margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--border-soft); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.browse-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.browse-path { color: var(--muted); font-size: 12px; word-break: break-all; }
.browse-list { border: 1px solid var(--border-soft); border-radius: 9px; overflow: hidden; }
.browse-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border-soft); font-size: 12px; }
.browse-row:last-child { border-bottom: 0; }
.browse-row .browse-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browse-row .browse-size { color: var(--muted); font-size: 11px; }
.browse-row button { padding: 4px 8px; font-size: 11px; }
.secret-note { color: var(--amber); font-size: 11px; }

.toast-stack { position: fixed; right: 22px; bottom: 22px; display: flex; flex-direction: column; gap: 9px; z-index: 100; }
.toast { background: #16222f; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 9px; padding: 11px 14px; max-width: 380px; font-size: 12px; box-shadow: var(--shadow); animation: toast-in .2s ease; }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }

@media (max-width: 1000px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(110px, 1fr)); }
  .panel-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .sidebar { width: 76px; flex-basis: 76px; padding: 18px 10px; }
  .brand > div:last-child, .nav-item { font-size: 0; gap: 0; justify-content: center; }
  .nav-item { justify-content: center; }
  .sidebar-foot { display: none; }
  .main { padding: 20px 18px 50px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .reference-panel { flex-direction: column; align-items: flex-start; }
}
@media (max-width: 560px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(100px, 1fr)); }
  .topbar { flex-direction: column; }
  .top-actions { width: 100%; }
  .top-actions .btn { flex: 1; }
}
