:root {
  --bg-top: #fdfefe;
  --bg: #f2f6fc;
  --bg-accent: #e8effa;
  --panel: #ffffff;
  --panel-alt: #f7f9fd;
  --panel-strong: #ffffff;
  --panel-muted: #eef3fb;
  --primary: #0b63ce;
  --primary-dark: #094b9c;
  --accent: #19a6e6;
  --text: #1a2740;
  --muted: #6e7e96;
  --border: #d7e1f0;
  --border-strong: #c7d9f6;
  --danger: #d63c3c;
  --danger-bg: #fff3f3;
  --danger-border: #f2baba;
  --shadow: 0 18px 40px rgba(15, 32, 62, 0.12);
  --shadow-soft: 0 6px 18px rgba(17, 36, 73, 0.08);
  --button-hover: #eef3fb;
  --star-empty: #c7cedb;
  --toast-bg: #1a2740;
  --toast-text: #ffffff;
  --icon-filter: none;
  --radius: 14px;
  --radius-sm: 10px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-top: #0f1624;
    --bg: #0c1220;
    --bg-accent: #172236;
    --panel: #121a2a;
    --panel-alt: #161f33;
    --panel-strong: #1c2740;
    --panel-muted: #1a2438;
    --primary: #4f8cff;
    --primary-dark: #3a6fd6;
    --accent: #4ec1ff;
    --text: #e8edf7;
    --muted: #9cadc4;
    --border: #23304a;
    --border-strong: #2f4064;
    --danger: #ff6b6b;
    --danger-bg: #3a1b1b;
    --danger-border: #6b2b2b;
    --shadow: 0 18px 40px rgba(5, 10, 20, 0.4);
    --shadow-soft: 0 6px 18px rgba(5, 10, 20, 0.3);
    --button-hover: #1c263b;
    --star-empty: #55607a;
    --toast-bg: #e8edf7;
    --toast-text: #0c1220;
    --icon-filter: invert(1) brightness(1.1);
    color-scheme: dark;
  }
}

html[data-theme="dark"] {
  --bg-top: #0f1624;
  --bg: #0c1220;
  --bg-accent: #172236;
  --panel: #121a2a;
  --panel-alt: #161f33;
  --panel-strong: #1c2740;
  --panel-muted: #1a2438;
  --primary: #4f8cff;
  --primary-dark: #3a6fd6;
  --accent: #4ec1ff;
  --text: #e8edf7;
  --muted: #9cadc4;
  --border: #23304a;
  --border-strong: #2f4064;
  --danger: #ff6b6b;
  --danger-bg: #3a1b1b;
  --danger-border: #6b2b2b;
  --shadow: 0 18px 40px rgba(5, 10, 20, 0.4);
  --shadow-soft: 0 6px 18px rgba(5, 10, 20, 0.3);
  --button-hover: #1c263b;
  --star-empty: #55607a;
  --toast-bg: #e8edf7;
  --toast-text: #0c1220;
  --icon-filter: invert(1) brightness(1.1);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg-top: #fdfefe;
  --bg: #f2f6fc;
  --bg-accent: #e8effa;
  --panel: #ffffff;
  --panel-alt: #f7f9fd;
  --panel-strong: #ffffff;
  --panel-muted: #eef3fb;
  --primary: #0b63ce;
  --primary-dark: #094b9c;
  --accent: #19a6e6;
  --text: #1a2740;
  --muted: #6e7e96;
  --border: #d7e1f0;
  --border-strong: #c7d9f6;
  --danger: #d63c3c;
  --danger-bg: #fff3f3;
  --danger-border: #f2baba;
  --shadow: 0 18px 40px rgba(15, 32, 62, 0.12);
  --shadow-soft: 0 6px 18px rgba(17, 36, 73, 0.08);
  --button-hover: #eef3fb;
  --star-empty: #c7cedb;
  --toast-bg: #1a2740;
  --toast-text: #ffffff;
  --icon-filter: none;
  color-scheme: light;
}

html,
body {
  height: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Lucida Sans", "Verdana", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 10% 10%, var(--bg-top), var(--bg)) fixed;
  overflow: hidden;
}

h2 {
  margin: 0;
  font-size: 18px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--panel-alt);
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text);
  transition: 0.2s ease;
}

button:hover {
  background: var(--button-hover);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--primary);
  color: #ffffff;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.danger {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

button.danger:hover {
  background: var(--danger-bg);
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: linear-gradient(120deg, var(--bg-top), var(--bg-accent));
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary);
  color: #ffffff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.search {
  flex: 1;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
}

.search input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px;
}

.search input:focus {
  outline: none;
}

.icon-button {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 0;
  background: var(--panel-alt);
}

.tool-button {
  background: transparent;
  border: none;
}

.tool-button:hover {
  background: var(--panel-muted);
}

.tool-button.danger {
  color: var(--danger);
  background: transparent;
  border: none;
}

.tool-button.danger:hover {
  background: var(--danger-bg);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: var(--space-3);
  padding: var(--space-3);
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.folder-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
}

.folder-search input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px;
  min-width: 0;
}

.folder-search input:focus {
  outline: none;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-footer {
  margin-top: auto;
}

.sidebar-footer .sidebar-actions {
  flex-direction: row;
  justify-content: flex-end;
}

.tree {
  overflow: auto;
  padding-right: 4px;
  padding-left: 2%;
  min-height: 0;
}

.tree-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-list[role="group"] {
  margin-left: 6px;
  padding-left: 6px;
  border-left: 1px dashed var(--border);
}

.tree-node {
  margin: 4px 0;
}

.tree-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 10px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  text-align: left;
  cursor: pointer;
}

.tree-item.root-folder {
  margin-left: calc(-2%);
  padding-left: 10px;
}

.tree-item.virtual-folder {
  margin-left: calc(-2%);
  padding-left: 10px;
}

.tree-item.active {
  background: var(--bg-accent);
  border-color: var(--border-strong);
}

.tree-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tree-name {
  flex: 1;
}

.tree-toggle,
.tree-spacer {
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border: none;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.tree-toggle::before {
  content: "";
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid var(--muted);
  transition: transform 0.2s ease;
  transform: rotate(0deg);
}

.tree-toggle.expanded::before {
  transform: rotate(90deg);
}

.tree-toggle:hover::before {
  border-left-color: var(--primary);
}

.icon {
  display: inline-block;
  flex-shrink: 0;
}

.icon.folder {
  width: 18px;
  height: 12px;
  border: 2px solid var(--primary);
  border-radius: 3px;
  position: relative;
}

.icon.folder::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 2px;
  width: 10px;
  height: 5px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
}

.icon.device {
  width: 18px;
  height: 12px;
  border: 2px solid var(--accent);
  border-radius: 3px;
  position: relative;
}

.icon.device::after {
  content: "";
  position: absolute;
  left: 4px;
  bottom: -4px;
  width: 10px;
  height: 2px;
  background: var(--accent);
  border-radius: 999px;
}

.icon-star {
  width: 14px;
  height: 14px;
  display: inline-block;
  background: var(--star-empty);
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
}

.icon.recent {
  width: 18px;
  height: 18px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  position: relative;
}

.icon.recent::after {
  content: "";
  position: absolute;
  width: 2px;
  height: 7px;
  background: var(--muted);
  left: 50%;
  top: 3px;
  transform: translateX(-50%);
}

.icon.recent::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 2px;
  background: var(--muted);
  left: 50%;
  top: 9px;
  transform: translateX(-10%);
}

.icon.favorite {
  width: 16px;
  height: 16px;
  display: inline-block;
  background: #f4b400;
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
}

.device-star.active .icon-star,
.details-favorite.active .icon-star {
  background: #f4b400;
}

.content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  overflow: hidden;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  font-size: 14px;
}

.breadcrumbs button {
  background: transparent;
  border: none;
  color: var(--primary);
  padding: 0;
}

.breadcrumbs .crumb-divider {
  color: var(--muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.controls select {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
}

.content-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: var(--space-3);
  min-height: 0;
}

.list,
.details {
  background: var(--panel-alt);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  border: 1px solid var(--border);
  min-height: 0;
  overflow: hidden;
}

.list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.list-title {
  font-weight: 700;
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow: auto;
  min-height: 0;
}

.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 10px;
  background: var(--panel-strong);
  border-radius: 12px;
  border: 1px solid transparent;
}

.device-row.active {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-soft);
}

.device-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: transparent;
  border: none;
  text-align: left;
  padding: 0;
}

.device-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.device-star {
  background: transparent;
  border: 1px solid transparent;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  margin-left: 4px;
}

.device-star:hover {
  background: var(--panel-muted);
}

.device-settings {
  background: transparent;
  border: 1px solid transparent;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.device-settings:hover {
  background: var(--panel-muted);
}

.icon-gear {
  width: 12px;
  height: 12px;
  display: block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 12px 12px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%237a8699' d='M14.8 5.5a1 1 0 0 1 1.4 0l5.3 5.3a1 1 0 0 1 0 1.4l-5.3 5.3a1 1 0 0 1-1.4-1.4l3.6-3.6H3a1 1 0 1 1 0-2h15.9l-3.6-3.6a1 1 0 0 1 0-1.4'/></svg>");
  filter: var(--icon-filter);
}

.icon-pen,
.icon-trash {
  width: 14px;
  height: 14px;
  display: block;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px 14px;
  filter: var(--icon-filter);
}

.icon-pen {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%237a8699' d='M14.1 3.9a2 2 0 0 1 2.8 0l3.2 3.2a2 2 0 0 1 0 2.8l-9.6 9.6l-4.7.8a1 1 0 0 1-1.1-1.1l.8-4.7zm1.4 2.8L6.6 15.6l-.4 2.2l2.2-.4l8.9-8.9z'/></svg>");
}

.icon-trash {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='%23d63c3c' d='M9 3h6l1 2h4a1 1 0 1 1 0 2h-1l-1.2 12.2a2 2 0 0 1-2 1.8H8.2a2 2 0 0 1-2-1.8L5 7H4a1 1 0 1 1 0-2h4zm1.8 6a1 1 0 0 0-2 0l.4 8a1 1 0 0 0 2 0zm6.4 0a1 1 0 0 0-2 0l-.4 8a1 1 0 0 0 2 0z'/></svg>");
}

.details {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow: auto;
  min-height: 0;
}

.details-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}

.details-title {
  font-size: 20px;
  font-weight: 700;
}

.details-sub {
  color: var(--muted);
  font-size: 13px;
}

.details-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.details-grid {
  display: grid;
  gap: var(--space-2);
}

.detail-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: var(--space-2);
  align-items: center;
  background: var(--panel-strong);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.detail-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.detail-value {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.details-favorite {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.empty-state {
  text-align: center;
  padding: var(--space-4);
  color: var(--muted);
}

.empty-title {
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-1);
}

.empty-sub {
  font-size: 14px;
}

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

.checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.mono {
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  word-break: break-all;
}

.hidden {
  display: none !important;
}

.modal-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1000;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 20, 36, 0.45);
}

.modal {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--space-4);
  width: min(520px, 92vw);
  box-shadow: var(--shadow);
  z-index: 1;
}

.modal h3 {
  margin: 0 0 var(--space-2) 0;
  font-size: 20px;
}

.modal-body {
  display: grid;
  gap: var(--space-2);
}

.modal-body label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.modal-body input,
.modal-body select,
.modal-body textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--panel-strong);
}

.modal-body textarea {
  resize: vertical;
  min-height: 80px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 1100;
}

.admin-panel {
  background: var(--panel-alt);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.admin-page {
  flex: 1;
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3);
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
}

.admin-list {
  display: grid;
  gap: var(--space-2);
}

.admin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: center;
  background: var(--panel-strong);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.admin-row .details-actions {
  justify-content: flex-end;
}

.settings-list {
  display: grid;
  gap: var(--space-3);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--panel-strong);
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.setting-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.setting-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.settings-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 20, 36, 0.55);
  display: grid;
  place-items: center;
  z-index: 2000;
  padding: var(--space-4);
}

.auth-standalone {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: radial-gradient(circle at 10% 10%, var(--bg-top), var(--bg)) fixed;
}

.auth-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: var(--space-4);
  width: min(520px, 92vw);
  box-shadow: var(--shadow);
  display: grid;
  gap: var(--space-3);
}

.auth-form {
  display: grid;
  gap: var(--space-2);
}

.auth-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.auth-form input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--panel-strong);
}

.twofa-box {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: var(--space-3);
  align-items: center;
}

.twofa-qr svg {
  width: 160px;
  height: 160px;
  background: var(--panel-strong);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.twofa-qr img {
  width: 160px;
  height: 160px;
  background: var(--panel-strong);
  padding: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 12px;
  color: var(--muted);
}

.theme-switch select {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

.twofa-secret {
  display: grid;
  gap: var(--space-1);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .content-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }

  .content {
    order: 1;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .search {
    order: 3;
    width: 100%;
  }
}

@media (max-width: 600px) {
  .top-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .details-grid .detail-row {
    grid-template-columns: 1fr;
  }

  .twofa-box {
    grid-template-columns: 1fr;
  }
}
