:root {
  color-scheme: light;
  --ink: #17201f;
  --muted: #6d7774;
  --line: #dfe6e2;
  --surface: #ffffff;
  --canvas: #f2f5f2;
  --forest: #174f3f;
  --forest-dark: #103a2f;
  --mint: #dff3e9;
  --good: #177f52;
  --warn: #a66a09;
  --bad: #b43a3a;
  --shadow: 0 22px 60px rgba(24, 51, 43, .10);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar { height: 76px; padding: 0 5vw; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.92); backdrop-filter: blur(12px); position: sticky; top: 0; z-index: 10; }
.brand, .topbar-actions, .channel-heading, .security-strip { display: flex; align-items: center; }
.brand { gap: 13px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.brand span.connection-ready { color: var(--good); }
.brand-mark { width: 52px; height: 52px; border-radius: 17px; display: grid; place-items: center; color: white; font-weight: 800; font-size: 22px; background: linear-gradient(145deg, #1a5d49, #0d352b); box-shadow: 0 12px 25px rgba(23,79,63,.24); }
.brand-mark.small { width: 40px; height: 40px; border-radius: 13px; font-size: 17px; }
.topbar-actions { gap: 20px; }
.mode-pill { padding: 8px 12px; border: 1px solid #cfe4da; border-radius: 999px; background: #f6fcf9; color: var(--forest); font-size: 12px; font-weight: 700; }
.mode-pill span, .local-note span, .modal-status span { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: #39a66e; box-shadow: 0 0 0 4px rgba(57,166,110,.12); }
.text-button { border: 0; background: transparent; color: var(--muted); padding: 8px; }
.back-link { text-decoration: none; }

.page-shell { width: min(1180px, 90vw); margin: 0 auto; padding: 58px 0 72px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 30px; margin-bottom: 32px; }
.eyebrow { margin: 0 0 9px; color: var(--forest); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.hero h1 { margin: 0; font: 700 clamp(34px, 5vw, 54px)/1.02 Georgia, serif; letter-spacing: -.035em; }
.hero p:not(.eyebrow) { max-width: 640px; margin: 16px 0 0; color: var(--muted); font-size: 17px; line-height: 1.6; }
.summary-card { min-width: 190px; padding: 20px 24px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 12px 35px rgba(24,51,43,.06); }
.summary-card span { display: block; color: var(--muted); font-size: 12px; }
.summary-card .summary-number { color: var(--forest); font: 700 34px/1 Georgia, serif; margin-bottom: 6px; }
.hero-actions { display: flex; align-items: stretch; gap: 12px; }
.hero-actions > .primary-button { min-width: 165px; }

.portal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.portal-card { padding: 24px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: 0 12px 35px rgba(24,51,43,.045); }
.portal-card-heading { display: flex; align-items: center; gap: 14px; }
.portal-mark { width: 48px; height: 48px; flex: 0 0 48px; display: grid; place-items: center; border-radius: 16px; color: white; background: linear-gradient(145deg, #276e5a, #103a2f); font-weight: 850; }
.portal-title { min-width: 0; flex: 1; }
.portal-title h2 { margin: 0 0 5px; font-size: 19px; }
.portal-title p { margin: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.portal-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 24px 0 13px; }
.portal-stats > div { padding: 14px; border-radius: 14px; background: #f5f8f6; }
.portal-stats strong, .portal-stats span { display: block; }
.portal-stats strong { color: var(--forest); font-size: 23px; }
.portal-stats span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.portal-limits { margin: 0 0 20px; color: var(--muted); font-size: 12px; }
.portal-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.portal-open { display: grid; place-items: center; text-decoration: none; }
.portal-editor { width: min(620px, 100%); text-align: left; }
.portal-form { display: grid; gap: 14px; margin-top: 22px; }
.portal-form label span { display: block; margin-bottom: 7px; color: #52605c; font-size: 12px; font-weight: 700; }
.portal-form input { width: 100%; height: 46px; padding: 0 13px; border: 1px solid #cad5d0; border-radius: 12px; outline: none; background: white; }
.portal-form input:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(23,79,63,.09); }
.limit-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.channel-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.channel-card { min-height: 235px; padding: 24px; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: 0 12px 35px rgba(24,51,43,.045); transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
.channel-card:hover { transform: translateY(-2px); border-color: #c4d4cc; box-shadow: var(--shadow); }
.channel-heading { gap: 14px; }
.channel-heading > div:nth-child(2) { min-width: 0; flex: 1; }
.channel-heading h2 { margin: 0 0 4px; font-size: 20px; }
.channel-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.channel-icon { width: 48px; height: 48px; flex: 0 0 48px; display: grid; place-items: center; border-radius: 16px; font-size: 13px; font-weight: 900; color: white; }
.channel-icon.telegram { background: #2b8ec6; }
.channel-icon.whatsapp { background: #1d9c61; }
.channel-icon.max { background: #7a62e6; font-size: 11px; }
.status-badge { padding: 6px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.status-badge.loading, .status-badge.offline { color: #68716f; background: #eef1ef; }
.status-badge.connected, .status-badge.configured { color: var(--good); background: #e4f6ed; }
.status-badge.waiting_qr, .status-badge.connecting, .status-badge.password_required { color: var(--warn); background: #fff1d9; }
.status-badge.configuration_required, .status-badge.logged_out, .status-badge.error { color: var(--bad); background: #fde8e8; }
.channel-details { flex: 1; padding: 24px 0 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.primary-button, .secondary-button { min-height: 42px; padding: 10px 16px; border-radius: 13px; font-weight: 750; transition: transform .15s ease, background .15s ease; }
.primary-button { border: 0; color: white; background: var(--forest); box-shadow: 0 9px 18px rgba(23,79,63,.18); }
.primary-button:hover:not(:disabled) { background: var(--forest-dark); transform: translateY(-1px); }
.secondary-button { border: 1px solid var(--line); color: var(--ink); background: #f8faf9; }
button:disabled { opacity: .52; cursor: not-allowed; box-shadow: none; }
.wide { width: 100%; }

.team-access-card { margin-top: 20px; padding: 26px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: 0 12px 35px rgba(24,51,43,.045); }
.team-access-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.team-access-heading h2 { margin: 3px 0 8px; font: 700 27px/1.1 Georgia, serif; }
.team-access-heading p:not(.eyebrow) { max-width: 820px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.team-access-list { display: grid; gap: 10px; margin-top: 20px; }
.team-access-row { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(230px, .8fr) auto; align-items: center; gap: 18px; padding: 17px; border: 1px solid var(--line); border-radius: 17px; background: #fbfcfb; }
.team-access-name { margin-bottom: 5px; font-weight: 850; }
.team-access-meta, .team-access-progress { color: var(--muted); font-size: 12px; line-height: 1.45; }
.team-access-progress.error { color: var(--bad); }
.team-access-controls { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 9px; }
.team-access-toggle { display: inline-flex; align-items: center; gap: 8px; color: #52605c; font-size: 12px; font-weight: 750; cursor: pointer; }
.team-access-toggle input { width: 18px; height: 18px; accent-color: var(--forest); }
.team-access-sync { min-height: 38px; padding: 8px 12px; border: 1px solid #bfd4ca; border-radius: 10px; color: var(--forest); background: #f2faf6; font-size: 12px; font-weight: 800; }

.security-strip { gap: 14px; margin-top: 20px; padding: 20px 24px; border: 1px solid #cfe1d8; border-radius: 20px; background: #eaf6f0; }
.shield { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 13px; color: white; background: var(--forest); font-weight: 900; }
.security-strip strong, .security-strip span { display: block; }
.security-strip span { color: #587068; font-size: 13px; margin-top: 4px; }

.modal-backdrop { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px; background: rgba(11,26,22,.62); backdrop-filter: blur(8px); }
.modal-card { width: min(470px, 100%); position: relative; padding: 32px; border-radius: 28px; background: white; box-shadow: 0 35px 100px rgba(0,0,0,.28); text-align: center; }
.modal-card.accounts-card { width: min(960px, 100%); max-height: min(760px, calc(100vh - 40px)); overflow: auto; text-align: left; }
.modal-close { position: absolute; top: 16px; right: 17px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eff3f1; font-size: 24px; line-height: 1; color: #60706b; }
.modal-card h2 { margin: 0; font: 700 31px/1.1 Georgia, serif; }
.modal-copy { color: var(--muted); line-height: 1.55; }
.qr-frame { width: 280px; height: 280px; margin: 22px auto; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 24px; background: #f7faf8; overflow: hidden; }
.qr-frame img { width: 248px; height: 248px; object-fit: contain; }
.qr-loader { width: 42px; height: 42px; border: 4px solid #dce6e1; border-top-color: var(--forest); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.modal-status { color: var(--muted); font-size: 13px; }
.password-form { display: flex; gap: 10px; margin: 20px 0; text-align: left; }
.password-form label { flex: 1; }
.password-form span, .login-form label span { display: block; margin-bottom: 7px; color: #52605c; font-size: 12px; font-weight: 700; }
.password-form input, .login-form input { width: 100%; height: 46px; padding: 0 13px; border: 1px solid #cad5d0; border-radius: 12px; outline: none; background: white; }
.password-form input:focus, .login-form input:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(23,79,63,.09); }
.account-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; margin: 24px 0 18px; padding: 17px; border: 1px solid var(--line); border-radius: 18px; background: #f7faf8; }
.account-form label span { display: block; margin-bottom: 7px; color: #52605c; font-size: 12px; font-weight: 700; }
.account-form input { width: 100%; height: 44px; padding: 0 13px; border: 1px solid #cad5d0; border-radius: 12px; outline: none; background: white; }
.account-form input:focus { border-color: var(--forest); box-shadow: 0 0 0 4px rgba(23,79,63,.09); }
.accounts-meta { margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.accounts-list { display: grid; gap: 10px; }
.account-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, .9fr) auto; align-items: center; gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 17px; }
.account-name { margin-bottom: 5px; font-weight: 800; }
.account-description { color: var(--muted); font-size: 12px; line-height: 1.45; }
.route-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px; }
.route-controls label { min-width: 0; color: #52605c; font-size: 11px; font-weight: 750; }
.route-controls select { display: block; width: 100%; height: 38px; margin-top: 6px; padding: 0 34px 0 10px; border: 1px solid #cad5d0; border-radius: 10px; outline: none; color: var(--ink); background: white; }
.route-controls select:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(23,79,63,.09); }
.route-save { min-height: 38px; padding: 8px 11px; border: 1px solid #bfd4ca; border-radius: 10px; color: var(--forest); background: #f2faf6; font-size: 12px; font-weight: 800; }
.account-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.account-actions button { min-height: 38px; padding: 8px 12px; border-radius: 11px; font-size: 12px; font-weight: 750; }
.account-stop { border: 1px solid var(--line); color: var(--muted); background: white; }
.account-delete { border: 1px solid #e7bcbc; color: var(--bad); background: #fff8f8; }
.account-delete:hover { border-color: #d99595; background: #fdeaea; }
.accounts-empty { padding: 24px; border: 1px dashed #cad5d0; border-radius: 17px; color: var(--muted); text-align: center; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 380px; padding: 14px 18px; border-radius: 14px; color: white; background: #24302d; box-shadow: var(--shadow); }

.login-body { display: grid; place-items: center; background: radial-gradient(circle at 20% 20%, #dff0e7 0, transparent 34%), radial-gradient(circle at 80% 80%, #dbe6f1 0, transparent 36%), #f3f6f4; }
.login-shell { width: min(440px, 92vw); padding: 35px 0; }
.login-card { padding: 42px; border: 1px solid rgba(209,221,215,.9); border-radius: 30px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.login-card .brand-mark { margin-bottom: 30px; }
.login-card h1 { margin: 0; font: 700 38px/1.05 Georgia, serif; letter-spacing: -.025em; }
.login-lead { margin: 14px 0 28px; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 17px; }
.form-error { margin-bottom: 18px; padding: 11px 13px; border-radius: 11px; color: #943434; background: #fdeaea; font-size: 13px; }
.local-note { margin: 24px 0 0; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 1050px) {
  .channel-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .portal-grid { grid-template-columns: 1fr; }
  .account-row { grid-template-columns: minmax(0, 1fr) minmax(220px, .9fr); }
  .account-actions { grid-column: 1 / -1; }
  .team-access-row { grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr); }
  .team-access-controls { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 760px) {
  .topbar { padding: 0 4vw; }
  .mode-pill { display: none; }
  .page-shell { width: 92vw; padding-top: 36px; }
  .hero { display: block; }
  .hero-actions { margin-top: 22px; }
  .summary-card { margin-top: 22px; width: 100%; }
  .channel-grid { grid-template-columns: 1fr; }
  .channel-card { min-height: 220px; }
  .team-access-heading { display: block; }
  .team-access-heading .secondary-button { margin-top: 16px; }
  .team-access-row { grid-template-columns: 1fr; }
  .team-access-controls { grid-column: auto; justify-content: stretch; }
  .team-access-sync { width: 100%; }
  .security-strip { align-items: flex-start; }
  .security-strip span { line-height: 1.45; }
  .modal-card { padding: 28px 20px; }
  .account-form, .account-row { grid-template-columns: 1fr; }
  .route-controls { grid-template-columns: minmax(0, 1fr) auto; }
  .account-actions { justify-content: stretch; }
  .account-actions button { flex: 1; }
  .qr-frame { width: 250px; height: 250px; }
  .qr-frame img { width: 220px; height: 220px; }
  .login-card { padding: 32px 25px; }
  .portal-card-heading { align-items: flex-start; }
  .portal-actions, .limit-grid { grid-template-columns: 1fr; }
}
