:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-elevated: #eef3f8;
  --panel: #ffffff;
  --panel-2: #f9fbfd;
  --text: #111827;
  --muted: #667085;
  --line: #d8e0ea;
  --primary: #3457f5;
  --primary-strong: #2443ca;
  --accent: #0f9f85;
  --warning: #c97706;
  --danger: #d92d20;
  --shadow: 0 18px 48px rgba(15, 23, 42, .10);
  --shadow-soft: 0 8px 22px rgba(15, 23, 42, .07);
  --radius: 8px;
  --focus: 0 0 0 .22rem rgba(52, 87, 245, .18);
  --app-font: Inter, "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1118;
  --bg-elevated: #111823;
  --panel: #161d29;
  --panel-2: #1b2431;
  --text: #f4f7fb;
  --muted: #a9b5c7;
  --line: #2d3848;
  --primary: #7da3ff;
  --primary-strong: #9bb8ff;
  --accent: #39c6a5;
  --warning: #f5b84c;
  --danger: #ff786e;
  --shadow: 0 18px 48px rgba(0, 0, 0, .24);
  --shadow-soft: 0 8px 22px rgba(0, 0, 0, .18);
  --focus: 0 0 0 .22rem rgba(125, 163, 255, .24);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--app-font);
  letter-spacing: 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--line) 18%, transparent) 1px, transparent 1px),
    linear-gradient(180deg, color-mix(in srgb, var(--line) 18%, transparent) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.52), transparent 460px);
}

a {
  color: var(--primary);
  text-underline-offset: 3px;
}

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

h1,
h2,
h3,
h4,
h5,
h6 {
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 16px;
  font-size: clamp(32px, 4vw, 46px);
  line-height: 1.05;
}

p {
  color: var(--text);
}

.muted,
.text-muted {
  color: var(--muted) !important;
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  min-height: 70px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  max-width: 1180px;
  margin-inline: auto;
  position: relative;
}

.brand {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  font-family: var(--app-font);
  font-size: clamp(24px, 2.5vw, 30px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-decoration: none;
  text-rendering: geometricPrecision;
}

.navbar .brand {
  white-space: nowrap;
}

.auth-panel .brand {
  font-size: 26px;
}

[data-theme="dark"] .brand {
  text-shadow: 0 1px 0 rgba(255, 255, 255, .08);
}

.nav-toggle {
  display: inline-grid;
}

.nav-menu {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 12px;
  z-index: 50;
  width: min(260px, calc(100vw - 32px));
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.nav-menu.is-open {
  display: flex;
}

.nav-menu .btn,
.nav-menu .icon-btn {
  width: 100%;
  min-height: 42px;
  justify-content: flex-start;
  text-align: left;
}

.nav-menu .btn-link {
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--text) !important;
  font-weight: 500;
  text-decoration: none;
}

.nav-menu .btn-link:hover,
.nav-menu .btn-link:focus {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary-strong) !important;
}

.nav-menu .icon-btn {
  display: inline-flex;
  justify-content: center;
}

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 36px 16px 64px;
}

.app-page {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  background: var(--bg);
}

.app-sidebar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
}

.sidebar-head,
.mobile-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-close {
  display: none;
}

.sidebar-user {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

.avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.sidebar-user strong,
.sidebar-user span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-meta {
  min-width: 0;
}

.sidebar-user-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-user-top strong {
  min-width: 0;
}

.sidebar-theme-toggle {
  width: 34px;
  height: 34px;
}

.sidebar-theme-toggle .fa-moon {
  display: none;
}

[data-theme="dark"] .sidebar-theme-toggle .fa-sun {
  display: none;
}

[data-theme="dark"] .sidebar-theme-toggle .fa-moon {
  display: inline-block;
}

.sidebar-user span {
  color: var(--muted);
  font-size: 13px;
}

.sidebar-nav {
  display: grid;
  gap: 14px;
}

.sidebar-section,
.sidebar-danger {
  display: grid;
  gap: 5px;
}

.sidebar-danger {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.sidebar-label {
  padding: 0 10px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sidebar-link {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
}

.sidebar-link i {
  width: 18px;
  color: var(--muted);
}

.sidebar-link:hover,
.sidebar-link:focus,
.sidebar-link.active {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary-strong);
}

.sidebar-link.active i,
.sidebar-link:hover i {
  color: var(--primary-strong);
}

.sidebar-link.danger {
  color: var(--danger);
}

.mobile-topbar {
  display: none;
}

.app-content {
  width: min(1180px, 100%);
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.link-form .form-label {
  margin-bottom: 6px;
  color: var(--muted) !important;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.link-switch {
  min-width: min(420px, 100%);
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  cursor: pointer;
}

.link-switch-copy {
  display: grid;
  gap: 2px;
}

.link-switch-copy strong {
  font-size: 14px;
}

.link-switch-copy small {
  color: var(--muted);
  font-size: 12px;
}

.page-head h1 {
  margin: 0;
}

.compact-stat {
  padding: 18px;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 18px;
}

.profile-photo {
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 14%, var(--panel));
  color: var(--primary-strong);
  font-size: 34px;
  font-weight: 900;
}

.info-list {
  display: grid;
  gap: 10px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.info-row span:first-child {
  color: var(--muted);
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.invoice-preview {
  max-width: 820px;
  margin: 0 auto;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.hero {
  min-height: calc(100vh - 70px);
  display: grid;
  align-items: center;
  color: #fff;
  background:
    linear-gradient(rgba(9, 16, 31, .62), rgba(9, 16, 31, .36)),
    url("../images/hero.svg") center/cover;
}

.hero-inner {
  width: min(1060px, 100%);
  margin: 0 auto;
  padding: 8vh 16px 14vh;
}

.hero h1 {
  max-width: 760px;
  margin: 16px 0;
  color: #fff;
  font-size: clamp(48px, 8vw, 96px);
  line-height: .95;
  font-weight: 800;
}

.hero p {
  max-width: 720px;
  margin-bottom: 28px;
  color: #eaf0ff;
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.58;
}

.panel,
.auth-panel,
.price-card,
.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.panel {
  padding: 24px;
}

.panel > :last-child,
.auth-panel > :last-child,
.price-card > :last-child,
.stat > :last-child {
  margin-bottom: 0;
}

.auth-wrap {
  min-height: calc(100vh - 70px);
  display: grid;
  place-items: center;
  padding: 34px 16px;
}

.auth-panel {
  width: min(470px, 100%);
  padding: 30px;
}

.auth-panel h1 {
  margin-top: 24px !important;
  margin-bottom: 8px;
}

.auth-panel .icon-btn[data-theme-toggle] {
  margin-top: 10px;
}

details {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
}

summary {
  cursor: pointer;
  padding: 12px 14px;
  color: var(--text);
  font-weight: 500;
}

details form {
  padding: 0 14px 14px;
}

.grid {
  display: grid;
  gap: 18px;
}

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

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

.stat {
  padding: 22px;
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
  background: var(--accent);
}

.stat:nth-child(2)::before {
  background: var(--primary);
}

.stat:nth-child(3)::before {
  background: var(--warning);
}

.stat span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 8px;
  color: var(--text);
  font-size: clamp(30px, 5vw, 40px);
  line-height: 1;
}

.form-control,
.form-select,
textarea,
input,
select {
  min-height: 44px;
  border-color: var(--line) !important;
  border-radius: 7px !important;
  background: var(--panel) !important;
  color: var(--text) !important;
  caret-color: var(--text) !important;
  box-shadow: none !important;
}

.form-control:focus,
.form-select:focus,
textarea:focus,
input:focus,
select:focus {
  border-color: var(--primary) !important;
  box-shadow: var(--focus) !important;
}

::placeholder,
textarea::placeholder,
input::placeholder {
  color: var(--muted) !important;
  opacity: 1;
}

label,
.form-check-label,
summary,
details,
button,
input,
select,
textarea,
.btn,
.btn-link,
.table,
.table th,
.table td {
  color: var(--text) !important;
}

.form-check-input {
  width: 18px;
  height: 18px;
  margin-top: 0;
  border-color: var(--line);
  background-color: var(--panel);
}

.form-check-input:checked {
  border-color: var(--primary);
  background-color: var(--primary);
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  opacity: .72;
}

[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

.btn {
  min-height: 40px;
  border-radius: 7px;
  font-weight: 500;
  letter-spacing: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  color: #fff !important;
  background: var(--primary);
  border-color: var(--primary);
}

.btn-primary:hover,
.btn-primary:focus {
  color: #fff !important;
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

.btn-success {
  color: #fff !important;
  background: var(--accent);
  border-color: var(--accent);
}

.btn-outline-primary {
  color: var(--primary) !important;
  border-color: color-mix(in srgb, var(--primary) 60%, var(--line));
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
  color: #fff !important;
  background: var(--primary);
  border-color: var(--primary);
}

.btn-outline-secondary,
.btn-outline-light {
  color: var(--text) !important;
  border-color: var(--line);
  background: transparent;
}

.btn-outline-secondary:hover,
.btn-outline-light:hover {
  color: var(--text) !important;
  background: var(--panel-2);
  border-color: var(--line);
}

.btn-outline-danger {
  color: var(--danger) !important;
  border-color: color-mix(in srgb, var(--danger) 62%, var(--line));
}

.btn-outline-danger:hover,
.btn-outline-danger:focus {
  color: #fff !important;
  background: var(--danger);
  border-color: var(--danger);
}

.btn-light {
  color: var(--text) !important;
  background: #fff;
  border-color: #fff;
}

.btn-link {
  color: var(--primary) !important;
}

.icon-btn {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  box-shadow: none;
}

.icon-btn:hover,
.icon-btn:focus {
  border-color: var(--primary);
  color: var(--primary) !important;
  box-shadow: var(--focus);
}

.icon-btn.danger {
  color: var(--danger) !important;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  min-width: 720px;
  margin-bottom: 0;
  color: var(--text);
  border-color: var(--line);
}

.table thead th {
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text) !important;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.table td,
.table th {
  padding: 14px 12px;
  border-color: var(--line);
  vertical-align: middle;
}

.table td {
  background: var(--panel);
}

.table tbody tr:hover td {
  background: color-mix(in srgb, var(--primary) 5%, var(--panel));
}

.table a,
#quickResult a,
#newApiKey a {
  color: var(--primary) !important;
  font-weight: 500;
}

.actions {
  white-space: nowrap;
}

.status-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.status-pill.success {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.status-pill.warning {
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 42%, var(--line));
  background: color-mix(in srgb, var(--warning) 10%, transparent);
}

.status-pill.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.status-pill.accent {
  color: var(--primary-strong);
  border-color: color-mix(in srgb, var(--primary) 42%, var(--line));
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.status-pill.neutral {
  color: var(--muted);
  background: var(--panel-2);
}

.table-empty {
  padding: 28px 16px !important;
  color: var(--muted) !important;
  text-align: center;
}

.price-card {
  padding: 26px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.price-card h2 {
  margin: 0;
}

.price-card p {
  min-height: 72px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.price-card:nth-child(2) {
  border-color: color-mix(in srgb, var(--primary) 46%, var(--line));
  box-shadow: var(--shadow);
}

.price {
  color: var(--text);
  font-size: clamp(34px, 5vw, 44px);
  font-weight: 800;
  line-height: 1;
}

.badge-soft {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  padding: 5px 10px;
  border: 1px solid color-mix(in srgb, var(--primary) 26%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 600;
}

.code-block {
  max-width: 100%;
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  white-space: pre-wrap;
}

.toast-box {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  display: grid;
  gap: 8px;
}

.app-toast {
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.app-toast-error {
  border-left-color: var(--danger);
}

[data-theme="dark"] .navbar,
[data-theme="dark"] .panel,
[data-theme="dark"] .auth-panel,
[data-theme="dark"] .stat,
[data-theme="dark"] .price-card,
[data-theme="dark"] .app-toast,
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] textarea,
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] .icon-btn,
[data-theme="dark"] details {
  background-color: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}

[data-theme="dark"] .table {
  --bs-table-bg: var(--panel);
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--line);
  --bs-table-striped-bg: var(--panel-2);
  --bs-table-striped-color: var(--text);
  --bs-table-hover-bg: #202b3a;
  --bs-table-hover-color: var(--text);
  background: var(--panel) !important;
  color: var(--text) !important;
}

[data-theme="dark"] .table th,
[data-theme="dark"] .table td,
[data-theme="dark"] .table > :not(caption) > * > * {
  border-color: var(--line) !important;
  background-color: var(--bs-table-bg) !important;
  color: var(--bs-table-color) !important;
}

[data-theme="dark"] .table thead th {
  background: var(--panel-2) !important;
  color: var(--text) !important;
}

[data-theme="dark"] .table tbody tr:hover td {
  background: #202b3a !important;
}

[data-theme="dark"] .btn-light {
  background: #f4f7fb;
  border-color: #f4f7fb;
  color: #111827 !important;
}

[data-theme="dark"] .badge-soft {
  color: var(--primary-strong);
  border-color: color-mix(in srgb, var(--primary) 32%, var(--line));
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: #c3ccdb !important;
}

@media (max-width: 760px) {
  .app-page {
    display: block;
  }

  .app-sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-105%);
    width: min(310px, calc(100vw - 36px));
    box-shadow: var(--shadow);
    transition: transform .2s ease;
  }

  .sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .sidebar-close,
  .mobile-topbar {
    display: flex;
  }

  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    min-height: 64px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
  }

  .shell {
    padding-top: 28px;
  }

  .grid-3,
  .grid-2,
  .profile-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .auth-panel,
  .price-card,
  .stat {
    padding: 20px;
  }

  .link-switch {
    width: 100%;
  }
}

@media (max-width: 760px) {
  .navbar,
  .navbar .container {
    min-height: 64px;
  }

  .nav-menu {
    right: 16px;
    left: 16px;
    width: auto;
  }

  .hero {
    min-height: 86vh;
  }

  .hero-inner {
    padding-top: 8vh;
  }

  .hero h1 {
    font-size: clamp(44px, 18vw, 68px);
  }

  .hero p {
    font-size: 17px;
  }

  .auth-wrap {
    padding: 22px 12px;
  }

  .auth-panel {
    padding: 22px;
  }

  .table {
    min-width: 680px;
  }
}

@media (max-width: 420px) {
  .brand {
    font-size: 24px;
  }

  .auth-panel .brand {
    font-size: 24px;
  }

  .btn,
  .form-control,
  .form-select,
  textarea,
  input,
  select {
    min-height: 42px;
  }
}
