:root {
    --blue: #1877f2;
    --blue-dark: #0e5bd8;
    --ink: #172033;
    --muted: #687386;
    --line: #e2e7ef;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --bg: #f3f6fb;
    --danger: #c62828;
    --ok: #137333;
    --warning: #8a5a00;
    --radius: 14px;
    --shadow: 0 8px 28px rgba(20, 35, 60, .06);
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; line-height: 1.5; }
a { color: var(--blue-dark); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid rgba(24, 119, 242, .35); outline-offset: 2px; }

.topbar { position: sticky; top: 0; z-index: 20; min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 12px max(20px, calc((100% - 1180px) / 2)); background: rgba(255, 255, 255, .94); border-bottom: 1px solid var(--line); box-shadow: 0 2px 14px rgba(20, 35, 60, .04); backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-size: 18px; font-weight: 800; letter-spacing: -.02em; text-decoration: none; white-space: nowrap; }
.brand::before { content: "F"; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, var(--blue), #4c9bff); color: #fff; font-size: 17px; box-shadow: 0 4px 10px rgba(24, 119, 242, .25); }
.main-nav { display: flex; align-items: center; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
.nav-list { display: flex; align-items: center; gap: 4px; margin: 0; padding: 0; list-style: none; }
.nav-list li { display: flex; }
.main-nav a, .link-button { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 11px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 650; transition: background .15s ease, color .15s ease, border-color .15s ease; }
.main-nav a:hover, .main-nav a:focus-visible, .link-button:hover, .link-button:focus-visible { background: #eef5ff; border-color: #d7e7ff; color: var(--blue-dark); }
.main-nav a.is-active { border-color: var(--blue); background: var(--blue); color: #fff; font-weight: 750; box-shadow: 0 4px 11px rgba(24, 119, 242, .22); }
.main-nav a.is-active:hover, .main-nav a.is-active:focus-visible { border-color: var(--blue-dark); background: var(--blue-dark); color: #fff; }
.main-nav .inline { display: inline; }
.nav-install { display: none; }
.nav-install[hidden] { display: none !important; }

.container { width: min(1180px, 100%); margin: 0 auto; padding: 30px 20px 72px; }
.page-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-title h1, .page-title h2 { margin: 0; letter-spacing: -.02em; }
.page-title h1 { font-size: clamp(24px, 3vw, 32px); line-height: 1.15; }
.page-title h2 { font-size: 21px; }
.page-title p { margin: 6px 0 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.stat { min-height: 112px; }
.stat strong { display: block; margin-top: 7px; color: var(--ink); font-size: 30px; line-height: 1; letter-spacing: -.04em; }
.dashboard-summary, .analytics-summary { gap: 12px; margin-bottom: 18px; }
.dashboard-summary .stat, .analytics-summary .stat { min-height: 86px; margin-bottom: 0; padding: 15px 18px; }
.dashboard-summary .stat strong, .analytics-summary .stat strong { margin-top: 4px; font-size: 26px; }
.muted { color: var(--muted); }
.grow { min-width: 0; flex: 1; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 16px; border: 1px solid var(--blue); border-radius: 10px; background: var(--blue); color: #fff; text-decoration: none; font-weight: 700; cursor: pointer; transition: transform .15s ease, background .15s ease, box-shadow .15s ease; }
.btn:hover { background: var(--blue-dark); box-shadow: 0 5px 13px rgba(24, 119, 242, .2); transform: translateY(-1px); }
.btn.secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.btn.secondary:hover { border-color: #b9c9df; background: var(--surface-soft); box-shadow: none; }
.btn.danger { border-color: #efb5b5; background: #fff; color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline { display: inline; }

.alert { padding: 13px 15px; border: 1px solid #d7e7ff; border-radius: 10px; margin-bottom: 15px; background: #edf5ff; color: #174ea6; }
.alert.success { border-color: #c6e6cf; background: #e6f4ea; color: var(--ok); }
.alert.error { border-color: #f2c2be; background: #fce8e6; color: var(--danger); }
.alert.warning { border-color: #f1d79b; background: #fff4d6; color: var(--warning); }
.page-token-warning { max-width: 280px; margin: 0 0 0 auto; padding: 10px 12px; font-size: 12px; }

label { display: block; margin-bottom: 7px; font-weight: 700; }
.field { margin-bottom: 18px; }
.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-heading label { margin-bottom: 7px; }
.field-meta { color: var(--muted); font-size: 12px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=datetime-local], input[type=number], input[type=url], textarea, select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cdd4df; border-radius: 10px; background: var(--surface); color: var(--ink); }
textarea { min-height: 160px; resize: vertical; }
input[type=file] { width: 100%; min-height: 44px; padding: 8px; border: 1px dashed #b9c9df; border-radius: 10px; background: var(--surface-soft); }
small { color: var(--muted); }

.checkbox-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.checkbox { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.checkbox label { margin: 0; font-weight: 600; cursor: pointer; }
.checkbox input, .switch-label input, .checkbox-line input { width: 18px; height: 18px; accent-color: var(--blue); }
.page-row { display: flex; align-items: center; gap: 14px; }
.page-row img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid #e6eef9; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; min-width: 680px; border-collapse: collapse; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { background: var(--surface-soft); color: var(--muted); font-size: 11px; letter-spacing: .07em; text-transform: uppercase; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 9px; border-radius: 999px; background: #edf1f7; color: var(--muted); font-size: 12px; font-weight: 700; }
.badge.published, .badge.completed { background: #e6f4ea; color: var(--ok); }
.badge.failed { background: #fce8e6; color: var(--danger); }
.badge.pending, .badge.processing, .badge.partial { background: #fff4d6; color: var(--warning); }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; }
.pagination a { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; min-width: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 650; }
.pagination a:hover { border-color: #b9c9df; background: var(--surface-soft); }
.pagination-disabled { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; min-width: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-soft); color: var(--muted); font-weight: 650; opacity: .55; }
.analytics-history-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.analytics-history-toolbar .field { min-width: 150px; margin: 0; }
.analytics-page-header { align-items: center; }
.analytics-period-form { width: min(100%, 240px); }
.analytics-period-select { min-height: 50px; padding: 12px 14px; font-size: 15px; font-weight: 650; }

footer { padding: 24px; color: var(--muted); text-align: center; }
.login { max-width: 440px; margin: 50px auto; }

@media (max-width: 900px) {
    .topbar { flex-flow: row wrap; align-items: center; gap: 10px 12px; padding: 11px 16px 0; }
    .main-nav { flex: 0 0 calc(100% + 32px); width: calc(100% + 32px); flex-wrap: nowrap; align-items: center; justify-content: flex-start; margin: 0 -16px; padding: 0 16px 10px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
    .nav-list { display: grid; width: max-content; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: max-content; align-items: center; gap: 7px; }
    .nav-list li, .nav-list a { display: flex; width: auto; min-width: max-content; }
    .main-nav a, .link-button { justify-content: flex-start; min-height: 42px; padding: 9px 13px; border-color: var(--line); background: var(--surface-soft); white-space: nowrap; }
    .nav-install:not([hidden]) { display: flex; flex: 0 0 auto; width: auto; border-color: #b9d4fa; background: #edf5ff; color: var(--blue-dark); }
    .main-nav .inline { display: block; flex: 0 0 auto; width: auto; }
    .main-nav .inline .link-button { width: auto; }
    .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
    .topbar { min-height: 60px; padding: 9px 12px 0; }
    .brand { font-size: 16px; }
    .brand::before { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; }
    .main-nav { flex-basis: calc(100% + 24px); width: calc(100% + 24px); margin: 0 -12px; padding: 0 12px 9px; }
    .container { padding: 18px 12px 44px; }
    .page-title, .analytics-history-toolbar { align-items: stretch; flex-direction: column; }
    .page-title { gap: 12px; margin-bottom: 16px; }
    .page-title h1 { font-size: 24px; }
    .page-title h2 { font-size: 19px; }
    .analytics-filter-bar, .analytics-period-form { width: 100%; }
    .page-title .actions, .analytics-history-toolbar .actions { width: 100%; }
    .page-title .actions > *, .analytics-history-toolbar .actions > * { flex: 1 1 145px; }
    .card { padding: 15px; margin-bottom: 14px; border-radius: 12px; }
    .field { margin-bottom: 14px; }
    input[type=text], input[type=email], input[type=password], input[type=datetime-local], input[type=number], input[type=url], textarea, select { padding: 9px 11px; }
    .actions { gap: 8px; }
    .alert { padding: 11px 12px; margin-bottom: 12px; }
    .grid, .checkbox-list { grid-template-columns: 1fr; }
    .dashboard-summary, .analytics-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .dashboard-summary .stat, .analytics-summary .stat { min-height: 76px; padding: 13px 14px; }
    .dashboard-summary .stat strong, .analytics-summary .stat strong { font-size: 23px; }
    .page-row { align-items: flex-start; flex-wrap: wrap; }
    .page-row .grow { min-width: calc(100% - 70px); }
    .page-row .page-token-warning { width: 100%; max-width: none; margin: 0; }
    .page-row > form { width: 100%; }
    .page-row > form .btn { width: 100%; }
    table { min-width: 620px; }
    .pagination { align-items: stretch; flex-direction: column; }
    .pagination .actions { width: 100%; }
    .pagination .actions > * { flex: 1; }
    .pagination a { width: 100%; }
    footer { padding: 18px 12px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
