:root {
  --bg-1: #0d1822;
  --bg-2: #122638;
  --bg-3: #1e3650;
  --panel: rgba(9, 18, 28, 0.68);
  --panel-strong: rgba(11, 21, 34, 0.92);
  --text: #edf3ff;
  --muted: #a6b7cf;
  --line: rgba(175, 202, 238, 0.24);
  --line-strong: rgba(176, 204, 243, 0.45);
  --primary: #80c3ff;
  --primary-strong: #4ca3ff;
  --danger: #ff8679;
  --warning: #ffc283;
  --success: #87e8b5;
  --shadow: 0 12px 28px rgba(1, 9, 19, 0.3);
  --ring: rgba(128, 195, 255, 0.4);
  --density-pad: 1rem;
  --density-gap: 0.95rem;
}

html[data-theme='dawn'] {
  --bg-1: #291f28;
  --bg-2: #4b2c39;
  --bg-3: #6b3c42;
  --panel: rgba(41, 22, 33, 0.7);
  --panel-strong: rgba(50, 26, 36, 0.92);
  --text: #fff0f0;
  --muted: #f2c8c2;
  --line: rgba(255, 202, 188, 0.28);
  --line-strong: rgba(255, 208, 194, 0.45);
  --primary: #ffbc8d;
  --primary-strong: #ff9a5c;
  --ring: rgba(255, 176, 134, 0.45);
}

html[data-theme='ocean'] {
  --bg-1: #09212c;
  --bg-2: #0f3442;
  --bg-3: #12526b;
  --panel: rgba(7, 25, 34, 0.66);
  --panel-strong: rgba(8, 30, 41, 0.93);
  --text: #e5fcff;
  --muted: #9ccfd6;
  --line: rgba(165, 230, 242, 0.22);
  --line-strong: rgba(169, 232, 245, 0.42);
  --primary: #6ee5ef;
  --primary-strong: #2fd4dd;
  --ring: rgba(110, 229, 239, 0.4);
}

html[data-theme='night'] {
  --bg-1: #0d1822;
  --bg-2: #122638;
  --bg-3: #1e3650;
}

html[data-density='compact'] {
  --density-pad: 0.78rem;
  --density-gap: 0.72rem;
}

html[data-density='spacious'] {
  --density-pad: 1.24rem;
  --density-gap: 1.06rem;
}

html[data-high-contrast='true'] {
  --line: rgba(255, 255, 255, 0.4);
  --line-strong: rgba(255, 255, 255, 0.62);
  --ring: rgba(255, 255, 255, 0.62);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 7% 14%, rgba(128, 195, 255, 0.14) 0, transparent 40%),
    radial-gradient(circle at 88% 80%, rgba(255, 194, 131, 0.12) 0, transparent 42%),
    linear-gradient(142deg, var(--bg-1), var(--bg-2), var(--bg-3));
  background-attachment: fixed;
}

h1,
h2,
h3 {
  font-family: 'Syne', sans-serif;
  margin: 0;
  letter-spacing: 0.2px;
}

a {
  color: var(--primary);
}

code {
  font-family: 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
  font-size: 0.9em;
}

#loading-screen {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(128, 195, 255, 0.22), transparent 44%),
    radial-gradient(circle at 86% 76%, rgba(255, 194, 131, 0.22), transparent 42%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2));
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.8rem;
  z-index: 9999;
  transition: opacity 0.8s ease;
}

#loading-screen p {
  margin: 0;
  color: var(--muted);
}

.pulsing-image {
  width: 118px;
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.16);
    opacity: 0.72;
  }
}

#toast-region {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: grid;
  gap: 0.6rem;
  z-index: 10000;
}

.toast {
  min-width: 250px;
  max-width: 420px;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--panel-strong);
  color: var(--text);
  animation: toastIn 220ms ease;
}

.toast.success {
  border-color: rgba(135, 232, 181, 0.52);
}

.toast.error {
  border-color: rgba(255, 134, 121, 0.55);
}

.toast.warn {
  border-color: rgba(255, 194, 131, 0.55);
}

@keyframes toastIn {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.app-shell {
  width: min(1080px, 95vw);
  margin: 1.4rem auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
  opacity: 0;
  transition: opacity 0.7s ease;
}

.app-shell.fade-in {
  opacity: 1;
}

.dashboard-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.dashboard-header h1 {
  text-align: center;
  font-size: clamp(1.06rem, 2.1vw, 1.65rem);
}

.header-meta,
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.48rem;
  flex-wrap: wrap;
}

.header-actions {
  justify-content: flex-end;
}

.status-tag,
.connection-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  border-radius: 999px;
  padding: 0.3rem 0.64rem;
  font-size: 0.76rem;
  color: var(--muted);
}

.connection-tag.offline {
  color: var(--danger);
  border-color: rgba(255, 134, 121, 0.5);
}

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

button {
  border: none;
  border-radius: 9px;
  padding: 0.52rem 0.82rem;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

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

.primary-btn {
  background: linear-gradient(130deg, var(--primary), var(--primary-strong));
  color: #07131f;
  font-weight: 700;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  color: var(--text);
}

.danger-btn {
  background: linear-gradient(120deg, #ff9a88, var(--danger));
  color: #2d0e08;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--density-gap);
}

.summary-card {
  padding: var(--density-pad);
  border: 1px solid color-mix(in srgb, var(--line) 74%, transparent);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  box-shadow: var(--shadow);
}

.summary-label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.summary-value {
  margin: 0.34rem 0 0;
  font-weight: 700;
  font-size: 1rem;
  word-break: break-word;
}

.insights-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.68rem;
}

.insight-pill {
  border: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 0.52rem 0.76rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  gap: 0.5rem;
}

.insight-pill strong {
  color: var(--text);
  font-weight: 700;
}

.quick-links {
  padding: var(--density-pad);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
}

.quick-links-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.quick-links h2 {
  font-size: 1.02rem;
}

.quick-links input {
  width: min(320px, 100%);
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 9px;
  padding: 0.5rem 0.62rem;
  background: rgba(0, 0, 0, 0.14);
  color: var(--text);
}

.card-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--density-gap);
  padding: 0;
  margin: 0;
}

.card {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  min-height: 142px;
}

.card.hidden {
  display: none;
}

.card a {
  position: relative;
  display: block;
  height: 100%;
  min-height: 142px;
  text-decoration: none;
  color: white;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
}

.card a::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2, 5, 8, 0.2), rgba(2, 5, 8, 0.72));
}

.card-title {
  position: absolute;
  left: 0.66rem;
  bottom: 0.54rem;
  z-index: 2;
  font-weight: 700;
}

.tabs {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 0.52rem;
  position: sticky;
  top: 0.55rem;
  z-index: 20;
  padding: 0.42rem;
  border: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  border-radius: 12px;
  background: color-mix(in srgb, var(--panel-strong) 84%, transparent);
  backdrop-filter: blur(10px);
  scrollbar-width: thin;
}

.tabs::-webkit-scrollbar {
  height: 6px;
}

.tabs::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--line-strong) 75%, transparent);
  border-radius: 999px;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  color: var(--text);
  padding: 0.42rem 0.72rem;
  font-size: 0.82rem;
  white-space: nowrap;
}

.tab-btn.active {
  background: linear-gradient(122deg, rgba(128, 195, 255, 0.28), rgba(76, 163, 255, 0.18));
  border-color: var(--line-strong);
}

.danger-tab {
  border-color: rgba(255, 134, 121, 0.5);
}

.tab-content {
  display: none;
  border: 1px solid color-mix(in srgb, var(--line) 74%, transparent);
  border-radius: 16px;
  padding: var(--density-pad);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  box-shadow: var(--shadow);
}

.tab-content.active {
  display: block;
  animation: fadePanel 240ms ease;
}

@keyframes fadePanel {
  from {
    transform: translateY(4px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.tab-content h2 {
  margin-bottom: 0.85rem;
  font-size: 1.12rem;
}

.form-grid {
  display: grid;
  gap: var(--density-gap);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid label {
  display: grid;
  gap: 0.42rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.wide-field {
  grid-column: 1 / -1;
}

.form-grid input,
.form-grid textarea,
.form-grid select,
.activity-toolbar input,
.quick-links input {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 9px;
  padding: 0.54rem 0.62rem;
  background: rgba(0, 0, 0, 0.16);
  color: var(--text);
}

.form-grid input:disabled,
.form-grid textarea:disabled,
.form-grid select:disabled {
  opacity: 0.7;
}

.form-grid button,
.form-grid small,
.form-grid .strength-meter {
  grid-column: 1 / -1;
}

.form-grid textarea {
  min-height: 88px;
  resize: vertical;
}

.progress-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.62rem;
  margin-bottom: 0.95rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(120deg, var(--primary), #87e8b5);
  transition: width 220ms ease;
}

.strength-meter {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(120deg, #ff8b7c, #ffcc70);
  transition: width 180ms ease;
}

.inline-form {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.72rem;
  flex-wrap: wrap;
  border-top: 1px dashed color-mix(in srgb, var(--line) 80%, transparent);
  padding-top: 0.86rem;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.54rem;
  color: var(--text);
}

.compact-form {
  grid-template-columns: 1fr;
}

.helper-line {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.activity-toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.58rem;
}

.activity-list li {
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.14);
  padding: 0.68rem 0.74rem;
  color: #d9e7fb;
  line-height: 1.38;
}

.session-row {
  display: grid;
  gap: 0.5rem;
}

.session-head {
  display: flex;
  justify-content: space-between;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

.session-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.inline-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--line-strong) 80%, transparent);
  color: var(--text);
  border-radius: 999px;
  padding: 0.14rem 0.52rem;
  font-size: 0.74rem;
}

.session-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.session-actions button {
  padding: 0.4rem 0.62rem;
  font-size: 0.82rem;
}

.mini-bars {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.42rem;
  margin: 0.1rem 0 0.8rem;
  align-items: end;
  min-height: 56px;
}

.mini-bar {
  display: grid;
  gap: 0.24rem;
  justify-items: center;
}

.mini-bar-fill {
  width: 100%;
  min-height: 6px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mini-bar-label {
  color: var(--muted);
  font-size: 0.7rem;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--density-gap);
  margin-top: 0.7rem;
}

.tools-output {
  margin-top: 0.85rem;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  padding: 0.68rem;
  color: #d4e9ff;
  min-height: 84px;
  white-space: pre-wrap;
  word-break: break-word;
}

.danger-note {
  color: #ffd5d0;
  margin-top: 0;
}

.hide {
  opacity: 0;
  pointer-events: none;
}

.cookie-popup {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  max-width: 520px;
  margin: 0 auto;
  z-index: 9998;
  display: flex;
  gap: 0.66rem;
  justify-content: space-between;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
  border-radius: 12px;
  padding: 0.78rem;
  background: var(--panel-strong);
  transition: opacity 0.3s ease;
}

.cookie-popup p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--muted);
}

.cookie-popup button {
  background: var(--primary-strong);
  color: #02131c;
  font-weight: 700;
}

footer {
  margin-top: 0.2rem;
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  padding: var(--density-pad);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.8rem;
}

.left-content,
.right-content {
  display: flex;
  align-items: center;
  gap: 0.56rem;
}

.left-content img {
  width: 40px;
  height: 40px;
}

.center-content {
  text-align: center;
  color: var(--muted);
}

.center-content p {
  margin: 0;
}

.right-content {
  justify-content: flex-end;
}

html[data-reduced-motion='true'] *,
html[data-reduced-motion='true'] *::before,
html[data-reduced-motion='true'] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

@media (max-width: 1180px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .insights-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tool-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .dashboard-header {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .header-meta,
  .header-actions {
    justify-content: center;
  }

  #sync-status {
    display: none;
  }

  .quick-links-header {
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  footer {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .left-content,
  .right-content {
    justify-content: center;
  }
}

@media (max-width: 640px) {
  .summary-grid,
  .insights-strip,
  .card-list {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: min(1260px, 97vw);
    padding: 0.55rem;
    margin: 0.85rem auto;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions button {
    flex: 1 1 auto;
  }

  .dashboard-header h1 {
    font-size: 1.02rem;
  }

  .tabs {
    position: static;
  }

  .cookie-popup {
    align-items: flex-start;
    flex-direction: column;
  }

  .activity-toolbar,
  .session-actions {
    flex-direction: column;
  }

  .activity-toolbar button,
  .session-actions button {
    width: 100%;
  }
}
