:root,
[data-theme="light"] {
  color-scheme: light;
  --site-max-width: 1160px;
  --site-gutter: 20px;
  --bg: #f3f6fb;
  --bg-radial: radial-gradient(circle at 0 0, #eaf3ff 0, transparent 34rem);
  --card: #ffffff;
  --card-border: rgba(228, 234, 242, 0.92);
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --surface-offset: #eef3f8;
  --text: #172033;
  --muted: #65758b;
  --line: #e4eaf2;
  --line-strong: #ccd7e4;
  --primary: #0b5cad;
  --primary-dark: #084f97;
  --primary-soft: #e8f2ff;
  --success: #027a48;
  --success-bg: #ecfdf3;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10141c;
  --bg-radial: radial-gradient(circle at 0 0, rgba(29, 78, 130, 0.28) 0, transparent 34rem);
  --card: #171d29;
  --card-border: rgba(126, 151, 180, 0.2);
  --surface: #151b25;
  --surface-soft: #111827;
  --surface-offset: #1f2a3a;
  --text: #eef3fb;
  --muted: #a8b5c7;
  --line: #2c384a;
  --line-strong: #435268;
  --primary: #68adf4;
  --primary-dark: #8bc3fb;
  --primary-soft: rgba(104, 173, 244, 0.16);
  --success: #55d38b;
  --success-bg: rgba(85, 211, 139, 0.12);
  --danger: #ff8b82;
  --danger-bg: rgba(255, 139, 130, 0.12);
}

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { margin: 0; min-height: 100vh; background: var(--bg-radial), var(--bg); color: var(--text); font: inherit; transition: background .2s ease, color .2s ease; }
h1, h2, h3, p, li, label, span, td, th, input, button, textarea, code, pre { font-family: inherit; }
code { font-size: inherit; font-weight: inherit; }
a { color: var(--primary); text-underline-offset: 3px; }

.shell { max-width: var(--site-max-width); margin: 0 auto; padding: 28px var(--site-gutter) 64px; display: grid; gap: 18px; width: 100%; box-sizing: border-box; }
.card { background: color-mix(in srgb, var(--card) 96%, transparent); border: 1px solid var(--card-border); border-radius: 24px; padding: 24px; box-shadow: 0 18px 45px rgba(18, 38, 63, 0.07); }
.hero { display: flex; justify-content: space-between; gap: 24px; align-items: center; padding: 22px 24px; }
.hero-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.cabinet-tabs { display: flex; align-items: center; gap: 6px; min-height: 56px; padding: 6px; background: rgba(255, 255, 255, 0.88); border: 1px solid rgba(228, 234, 242, 0.95); border-radius: 18px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; box-shadow: 0 12px 30px rgba(18, 38, 63, 0.055); position: sticky; top: 12px; z-index: 5; backdrop-filter: blur(14px); }
.cabinet-tab { flex: 1 0 0; min-width: max-content; height: 44px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 13px; background: transparent; color: #5f6f84; padding: 0 16px; font: inherit; font-size: 14px; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; cursor: pointer; white-space: nowrap; box-shadow: none; transition: background .16s ease, border-color .16s ease, color .16s ease, box-shadow .16s ease; }
.cabinet-tab:hover { background: #f4f8fd; border-color: #eaf0f7; color: #26364b; }
.cabinet-tab.active { background: linear-gradient(180deg, #0d66b8 0%, var(--primary) 100%); border-color: rgba(11, 92, 173, 0.18); color: #fff; box-shadow: 0 8px 18px rgba(11, 92, 173, 0.2); }
.cabinet-tab:active { transform: none; }
.cabinet-tab:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid rgba(11, 92, 173, 0.22); outline-offset: 2px; }

.tab-panels { display: grid; gap: 18px; }
.tab-panel { animation: tabFadeIn .2s ease; }
.tab-panel[hidden] { display: none !important; }
@keyframes tabFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.eyebrow { margin: 0 0 6px; text-transform: uppercase; letter-spacing: .09em; color: #6e7f96; font-size: 12px; font-weight: 800; }
h1, h2 { margin: 0; line-height: 1.15; letter-spacing: -0.03em; }
h1 { font-size: clamp(1.85rem, 4vw, 2.55rem); }
h2 { font-size: clamp(1.28rem, 2.4vw, 1.7rem); }
h3 { color: #27364b; }
.muted { color: var(--muted); font-size: inherit; }
.small { font-size: 0.875rem; line-height: 1.5; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.full { grid-column: 1 / -1; }
.hidden { display: none; }
.error { color: var(--danger); margin: 10px 0 0; }

.section-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 20px; }
.section-head button { flex-shrink: 0; }
.settings-group { margin: 12px 0 -2px; padding-top: 18px; border-top: 1px solid var(--line); }
.settings-help + .settings-group { margin-top: 4px; padding-top: 0; border-top: none; }
.settings-group-title { margin: 0; font-size: 1.02rem; letter-spacing: -0.01em; }
.settings-group-lead { margin: 0 0 12px; }
.settings-help { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 2px; }
.settings-help-card { display: flex; gap: 12px; min-height: 132px; padding: 15px; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(180deg, #fbfdff 0%, #f6faff 100%); }
.settings-help-step { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 0.82rem; font-weight: 900; box-shadow: 0 8px 16px rgba(11, 92, 173, 0.18); }
.settings-help-card h3 { margin: 2px 0 7px; font-size: 0.95rem; letter-spacing: -0.01em; }
.settings-help-card p { margin: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.55; }
.settings-help-card a, .field-guide a { font-weight: 800; }
.field-guide { font-size: 0.8rem; line-height: 1.45; color: #7a889a; font-weight: 400; }
.field-guide strong { color: #4a5d74; font-weight: 700; }

label { display: grid; gap: 7px; }
label span, .field-inline span { color: #34445a; font-size: 0.92rem; font-weight: 750; }
input, textarea, .mapping-input, .field-inline input { width: 100%; border: 1px solid var(--line-strong); border-radius: 14px; padding: 12px 14px; font: inherit; background: #fff; color: inherit; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7); transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
input:hover, textarea:hover, .mapping-input:hover, .field-inline input:hover { border-color: #aebed0; }
input:focus, textarea:focus, .mapping-input:focus, .field-inline input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(11, 92, 173, 0.1); outline: none; }
input::placeholder, textarea::placeholder { color: #9aa8b8; }
textarea { resize: vertical; }

button, .file-upload-btn { border: none; border-radius: 14px; background: var(--primary); color: #fff; padding: 12px 17px; font: inherit; font-weight: 800; cursor: pointer; text-decoration: none; transition: transform .16s ease, box-shadow .16s ease, background .16s ease, filter .16s ease; box-shadow: 0 10px 20px rgba(11, 92, 173, 0.18); }
button:hover, .file-upload-btn:hover { background: var(--primary-dark); }
button:active, .file-upload-btn:active { transform: translateY(1px); box-shadow: 0 5px 12px rgba(11, 92, 173, 0.16); }
button.secondary, .landing-cta.secondary { background: #eef3f8; color: #26364b; box-shadow: none; }
button.secondary:hover, .landing-cta.secondary:hover { background: #e3ebf4; }
button.cabinet-tab, button.cabinet-tab:hover, button.cabinet-tab:active { flex: 1 0 0; width: auto; min-width: max-content; height: 44px; min-height: 44px; padding: 0 16px; font-size: 14px; font-weight: 650; line-height: 1.2; border-radius: 13px; box-shadow: none; transform: none; filter: none; }
button.cabinet-tab { background: transparent; color: #5f6f84; }
button.cabinet-tab:hover { background: #f4f8fd; border-color: #eaf0f7; color: #26364b; }
button.cabinet-tab.active, button.cabinet-tab.active:hover, button.cabinet-tab.active:active { background: linear-gradient(180deg, #0d66b8 0%, var(--primary) 100%); border-color: rgba(11, 92, 173, 0.18); color: #fff; box-shadow: 0 8px 18px rgba(11, 92, 173, 0.2); }
.actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.users-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: #f8fbff; }
.user-row-main { min-width: 0; }
.user-row-name { font-weight: 800; }
.user-row-meta { font-size: 13px; color: var(--muted); }
.user-row-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.user-badge, .saved-badge { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 800; vertical-align: middle; }
.user-badge-pending { background: #fff7ed; color: #9a3412; }
.saved-badge { margin-left: 8px; background: var(--success-bg); color: var(--success); }
.saved-badge.hidden { display: none; }
.notice { margin: 0 0 14px; padding: 12px 14px; border-radius: 14px; background: var(--success-bg); color: var(--success); font-size: 14px; font-weight: 650; }
.notice.error { background: rgba(180, 35, 24, 0.08); color: var(--danger); }
.invite-tg-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin-top: 12px; }
.invite-tg-field { flex: 1 1 240px; min-width: 220px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 18px; background: #fff; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 520px; font-size: inherit; }
th, td { padding: 12px 14px; border-bottom: 1px solid #edf2f7; text-align: left; vertical-align: top; font-size: inherit; line-height: 1.5; }
th { background: #f8fbff; color: #41526a; font-size: 0.86rem; font-weight: 800; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fbfdff; }
.mapping-input { min-width: 88px; border-radius: 12px; padding: 9px 11px; }
.cell-text { color: #3a4b5f; }
.cell-note { color: var(--muted); }
.value-table-toolbar { align-items: end; gap: 12px; margin: 0 0 16px; }
.field-inline { display: grid; gap: 7px; }
.field-inline input { width: 150px; padding: 10px 12px; }
.file-upload-btn { display: inline-flex; align-items: center; justify-content: center; }
.file-upload-btn input { display: none; }
#valueTableNotice.error { color: var(--danger); }

.status-summary { padding: 18px; border-radius: 18px; margin-bottom: 16px; }
.status-summary-ok { background: var(--success-bg); border: 1px solid #abefc6; color: var(--success); }
.status-summary-error { background: var(--danger-bg); border: 1px solid #fecdca; color: var(--danger); }
.status-summary-paused { background: #fffaeb; border: 1px solid #fedf89; color: #b54708; }
.status-paused { background: #fffaeb; color: #b54708; }
.status-clickable { cursor: pointer; }
.status-clickable:hover { filter: brightness(0.97); }
.status-summary .muted { color: inherit; opacity: 0.85; }
.integration-toggle { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px; border-radius: 12px; border: 1px solid #dbe2ea; background: #f8fafc; cursor: pointer; user-select: none; }
.integration-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.integration-toggle-box { flex: 0 0 44px; width: 44px; height: 24px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background 0.15s ease; margin-top: 2px; }
.integration-toggle-box::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s ease; box-shadow: 0 1px 2px rgba(0,0,0,0.15); }
.integration-toggle input:checked + .integration-toggle-box { background: #0b5cad; }
.integration-toggle input:checked + .integration-toggle-box::after { transform: translateX(20px); }
.integration-toggle-text { display: grid; gap: 4px; }
.integration-toggle-text strong { color: #1f2937; }
.status-error-list { margin: 8px 0 0; padding-left: 1.2rem; }
.status-log-details { margin-top: 8px; }
.status-log-details summary { cursor: pointer; color: var(--muted); margin-bottom: 12px; font-weight: 800; }
.status-log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.status-log-item { padding: 13px 15px; border-radius: 14px; border: 1px solid #edf2f7; background: #fafcff; }
.status-log-error { background: var(--danger-bg); border-color: #fecdca; }
.status-log-info { background: #f8fafc; border-color: #e2e8f0; }
.status-log-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.status-log-time { font-size: 0.8125rem; color: var(--muted); }
.status-log-badge { font-size: 0.75rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.status-log-info .status-log-badge { background: var(--primary-soft); color: var(--primary); }
.status-log-error .status-log-badge { background: #fee4e2; color: var(--danger); }
.status-log-text { margin: 0; line-height: 1.5; color: #1f2937; }
.status-log-empty { padding: 8px 0; }

.orders-layout { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr); gap: 16px; align-items: start; }
.order-row { cursor: pointer; transition: background .14s ease; }
.order-row:hover td { background: #f5f9ff; }
.order-row-active td { background: #eef6ff !important; }
.order-row-active:hover td { background: #e3f0ff !important; }
.order-badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.order-badge-done { background: var(--success-bg); color: var(--success); }
.order-badge-error { background: var(--danger-bg); color: var(--danger); }
.order-badge-pending { background: #fff7ed; color: #9a3412; }
.order-detail { border: 1px solid var(--line); border-radius: 18px; background: #f8fbff; padding: 18px; position: sticky; top: 88px; }
.order-detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 16px; }
.order-detail-head h3 { margin: 0; font-size: 1.15rem; word-break: break-word; }
.order-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.order-detail-block { display: grid; gap: 6px; }
.order-detail-block.full { grid-column: 1 / -1; }
.order-detail-label { color: var(--muted); font-size: 0.82rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.order-detail-error { padding: 12px 14px; border-radius: 14px; background: var(--danger-bg); border: 1px solid #fecdca; color: var(--danger); }
.order-products { margin: 0; padding-left: 1.1rem; display: grid; gap: 6px; }
.order-log-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }

.login-consent { margin: 0 0 1.25rem; padding: 0.95rem 1rem; text-align: left; background: #f8fbff; border: 1px solid var(--line); border-radius: 16px; }
.login-consent-row { display: flex; align-items: flex-start; gap: 0.75rem; font-size: 0.875rem; line-height: 1.55; color: var(--muted); cursor: pointer; user-select: none; }
.login-consent-control { position: relative; flex: 0 0 auto; width: 1.125rem; height: 1.125rem; margin-top: 0.12rem; }
.login-consent-checkbox { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.login-consent-mark { display: block; width: 100%; height: 100%; border: 2px solid var(--line-strong); border-radius: 0.35rem; background: #fff; position: relative; transition: background .15s ease, border-color .15s ease, box-shadow .15s ease; }
.login-consent-row:hover .login-consent-mark { border-color: #82a9d6; }
.login-consent-checkbox:checked + .login-consent-mark { background: var(--primary); border-color: var(--primary); }
.login-consent-checkbox:checked + .login-consent-mark::after { content: ""; position: absolute; left: 0.3rem; top: 0.08rem; width: 0.3rem; height: 0.58rem; border-right: 2px solid #fff; border-bottom: 2px solid #fff; transform: rotate(45deg); }
.login-consent-text { min-width: 0; }
.login-consent-row a { color: var(--primary); font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.tg-noscript { color: var(--muted); font-size: 0.875rem; margin: 0; padding: 0.5rem 0; }
.err { color: var(--danger); background: rgba(180, 35, 24, 0.08); padding: 0.75rem 1rem; border-radius: 0.75rem; margin-bottom: 1rem; font-size: 0.875rem; text-align: left; display: none; }
.tg-open-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-width: 260px; padding: 0.9rem 1.35rem; font: inherit; font-weight: 800; font-size: 1rem; color: #fff; background: #2aabee; border: none; border-radius: 14px; cursor: pointer; box-shadow: 0 10px 22px rgba(42, 171, 238, 0.2); }
.tg-open-btn:hover { filter: brightness(1.06); }
.google-open-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-width: 260px; padding: 0.9rem 1.35rem; font: inherit; font-weight: 800; font-size: 1rem; color: #1f2937; background: #fff; border: 1px solid var(--line-strong); border-radius: 14px; cursor: pointer; text-decoration: none; box-shadow: 0 10px 22px rgba(15, 23, 42, 0.06); }
.google-open-btn:hover { background: #f8fafc; }
.login-auth-slot { margin-top: 0.75rem; }
.login-auth-slot + .login-auth-slot { margin-top: 0.85rem; }
.tg-fallback-btn { display: inline-block; margin: 0; padding: 0; font: inherit; font-size: 0.875rem; color: var(--primary); background: none; border: none; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; box-shadow: none; }
.tg-fallback-btn:hover { background: none; filter: brightness(1.08); }
.tg-fallback-btn:active { transform: none; box-shadow: none; }
.pre { margin: 0; white-space: pre-wrap; background: #0f172a; color: #dbeafe; padding: 16px; border-radius: 14px; overflow: auto; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.875rem; }

[data-theme="dark"] h3,
[data-theme="dark"] label span,
[data-theme="dark"] .field-inline span,
[data-theme="dark"] .integration-toggle-text strong,
[data-theme="dark"] .status-log-text,
[data-theme="dark"] .cell-text {
  color: var(--text);
}

[data-theme="dark"] .cabinet-tabs,
[data-theme="dark"] .settings-help-card,
[data-theme="dark"] .table-wrap,
[data-theme="dark"] .user-row,
[data-theme="dark"] .status-log-item,
[data-theme="dark"] .order-detail,
[data-theme="dark"] .login-consent,
[data-theme="dark"] .google-open-btn,
[data-theme="dark"] .integration-toggle {
  background: var(--surface-soft);
  border-color: var(--line);
}

[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] .mapping-input,
[data-theme="dark"] .field-inline input {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: #748298;
}

[data-theme="dark"] th {
  background: var(--surface-soft);
  color: var(--muted);
}

[data-theme="dark"] td {
  border-bottom-color: var(--line);
}

[data-theme="dark"] tbody tr:hover td,
[data-theme="dark"] .order-row:hover td {
  background: rgba(104, 173, 244, 0.08);
}

[data-theme="dark"] .order-row-active td,
[data-theme="dark"] .order-row-active:hover td {
  background: rgba(104, 173, 244, 0.14) !important;
}

[data-theme="dark"] .cabinet-tab {
  color: var(--muted);
}

[data-theme="dark"] .cabinet-tab:hover {
  background: var(--surface-offset);
  border-color: var(--line);
  color: var(--text);
}

[data-theme="dark"] button.secondary,
[data-theme="dark"] .landing-cta.secondary {
  background: var(--surface-offset);
  color: var(--text);
}

@media (max-width: 840px) {
  .shell { padding: 18px 14px 44px; gap: 14px; }
  .card { border-radius: 20px; padding: 18px; }
  .hero { align-items: flex-start; }
  .hero-actions { width: auto; }
  .cabinet-tabs { top: 8px; border-radius: 18px; }
  .cols-2 { grid-template-columns: 1fr; }
  .settings-help { grid-template-columns: 1fr; }
  .settings-help-card { min-height: auto; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .section-head button { width: 100%; }
  .user-row { flex-direction: column; align-items: stretch; }
  .orders-layout { grid-template-columns: 1fr; }
  .order-detail { position: static; }
}

@media (max-width: 560px) {
  .hero { flex-direction: column; gap: 16px; }
  .hero-actions, .hero-actions button, .actions button, .file-upload-btn, .field-inline, .field-inline input { width: 100%; }
  .cabinet-tab, button.cabinet-tab { flex-basis: auto; height: 42px; min-height: 42px; padding: 0 13px; font-size: 13px; }
  .invite-tg-field { min-width: 100%; }
}
