:root {
    --ink:      #161c22;
    --ink-soft: #5b6670;
    --paper:    #f4f5f2;
    --surface:  #ffffff;
    --line:     #e0e4dd;
    --green:    #1f7a4d;
    --green-bg: #e8f5ec;
    --amber:    #a86400;
    --red:      #b3261e;
    --radius:   8px;
    --shadow:   0 1px 2px rgba(22, 28, 34, .06), 0 4px 14px rgba(22, 28, 34, .04);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-variant-numeric: tabular-nums;
}

h1 { font-size: 20px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 6px; }
a { color: var(--ink); }
code { background: #eef0ec; padding: 1px 4px; border-radius: 4px; font-size: 13px; }

.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.bad   { color: var(--red); }

/* ---------------------------------------------------------------- topbar */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 20;
}
.brand {
    display: inline-flex; align-items: center; gap: 8px;
    font-weight: 650; text-decoration: none; letter-spacing: -.01em;
}
.brand-mark {
    display: grid; place-items: center;
    width: 22px; height: 22px; border-radius: 6px;
    background: var(--green); color: #fff; font-size: 13px;
}
.topbar nav { display: flex; gap: 14px; font-size: 14px; }
.topbar nav a { color: var(--ink-soft); text-decoration: none; }
.topbar nav a:hover { color: var(--ink); }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.inline { display: inline; }

/* ----------------------------------------------------------------- karty */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.empty { text-align: center; padding: 40px 20px; }
.empty p { color: var(--ink-soft); margin: 0 0 14px; }

/* -------------------------------------------------------------- przyciski */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 14px; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--surface); color: var(--ink);
    font: inherit; font-weight: 550; text-decoration: none; cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #f7f8f5; }
.btn--primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn--primary:hover { background: #1a6942; }
.btn--ghost { color: var(--ink-soft); }
.btn--danger { background: var(--red); border-color: var(--red); color: #fff; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* ------------------------------------------------------------ komunikaty */
.flash {
    margin: 0 0 14px; padding: 10px 12px; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--surface); font-size: 14px;
}
.flash--ok    { border-color: #b9dfc7; background: var(--green-bg); color: #14532d; }
.flash--warn  { border-color: #f0d9a8; background: #fdf6e7; color: var(--amber); }
.flash--error { border-color: #f0c0bc; background: #fdeceb; color: var(--red); }

/* ------------------------------------------------------------ formularze */
.form { display: grid; gap: 6px; max-width: 720px; }
.form label { font-size: 13px; font-weight: 600; margin-top: 10px; }
.form input[type=text], .form input:not([type]), .form input[type=password],
.form input[type=search], .form select, input#name, input#sheet_url {
    width: 100%; padding: 9px 11px; font: inherit;
    border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.form .btn { margin-top: 16px; justify-self: start; }
.hint { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.check--inline { margin-top: 16px; }

.danger { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; }
.danger p { margin: 2px 0 0; }

/* ---------------------------------------------------------------- login */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login { width: 100%; max-width: 340px; display: grid; gap: 6px; }
.login h1 { margin: 0; }
.login p { margin: 0 0 8px; font-size: 14px; }
.login label { font-size: 13px; font-weight: 600; margin-top: 8px; }
.login input { width: 100%; padding: 9px 11px; font: inherit; border: 1px solid var(--line); border-radius: var(--radius); }
.login .btn { margin-top: 14px; }
.login-mark {
    display: grid; place-items: center; width: 34px; height: 34px;
    border-radius: 9px; background: var(--green); color: #fff; font-size: 19px; margin: 0 0 4px;
}

/* -------------------------------------------------------------- kampanie */
.campaign-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.campaign { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.campaign--off { opacity: .6; }
.campaign-main { flex: 1 1 220px; }
.campaign-name { font-weight: 600; font-size: 16px; text-decoration: none; }
.campaign-name:hover { text-decoration: underline; }
.campaign-main p { margin: 2px 0 0; }
.campaign-nums { display: flex; align-items: baseline; gap: 5px; }
.num { font-size: 19px; font-weight: 650; }
.num--todo { color: var(--green); }
.num-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); }
.num-sep { color: var(--line); margin: 0 4px; }

/* --------------------------------------------------------------- toolbar */
.toolbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-bottom: 12px;
}
.counters { display: flex; gap: 6px; }
.pill {
    padding: 5px 10px; border-radius: 999px; font-size: 13px;
    border: 1px solid var(--line); background: var(--surface);
}
.pill--todo { border-color: #cfe3d6; }
.pill--done { color: var(--green); background: var(--green-bg); border-color: #c6e3d1; }
.filters { display: flex; gap: 2px; background: #e9ebe6; padding: 2px; border-radius: 999px; }
.tab {
    padding: 5px 12px; border-radius: 999px; font-size: 13px;
    text-decoration: none; color: var(--ink-soft);
}
.tab.is-on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.search { display: flex; gap: 6px; flex: 1 1 240px; }
.search input {
    flex: 1; padding: 8px 11px; font: inherit;
    border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}

/* ---------------------------------------------------------------- tabela */
.table-wrap {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto;
    max-height: calc(100vh - 210px);
}
table.leads { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
.leads thead th {
    position: sticky; top: 0; z-index: 5;
    background: #fbfcfa; border-bottom: 1px solid var(--line);
    text-align: left; padding: 9px 12px; white-space: nowrap;
    font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft);
}
.leads td { padding: 9px 12px; border-bottom: 1px solid #f0f2ee; vertical-align: top; }
.leads tbody tr:hover td { background: #fafbf8; }
.col-check { width: 40px; text-align: center; }
.col-when  { width: 92px; color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.lead-check { width: 17px; height: 17px; accent-color: var(--green); cursor: pointer; }

/* sygnatura: obrobiony lead cofa się w tło, kolejka wizualnie pustoszeje */
.leads tr.is-done td { background: var(--green-bg); color: #4b6b57; }
.leads tr.is-done:hover td { background: #dff0e5; }
.leads tr.is-done td:first-child { box-shadow: inset 3px 0 0 var(--green); }
.leads tr.is-done a { color: #4b6b57; }
.lead td { transition: background-color .18s ease, color .18s ease; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 14px; }

@media (max-width: 640px) {
    main { padding: 12px; }
    .toolbar { gap: 8px; }
    .search { order: 5; flex-basis: 100%; }
    .table-wrap { max-height: calc(100vh - 260px); }
    .leads td, .leads thead th { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}

/* ------------------------------------------------- zakładki kampanii */
.camp-tabs {
    display: flex; gap: 4px; margin-bottom: 14px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid var(--line); padding-bottom: 0;
}
.camp-tab {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 8px 13px; border: 1px solid transparent; border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    color: var(--ink-soft); text-decoration: none; font-size: 14px;
    white-space: nowrap; position: relative; top: 1px;
}
.camp-tab:hover { background: #eceee9; }
.camp-tab.is-on {
    background: var(--surface); border-color: var(--line); border-bottom: 1px solid var(--surface);
    color: var(--ink); font-weight: 600;
}
.camp-tab--off .camp-tab-name { opacity: .55; text-decoration: line-through; }
.camp-tab-count {
    font-size: 12px; padding: 1px 7px; border-radius: 999px;
    background: #e9ebe6; color: var(--ink-soft);
}
.camp-tab.is-on .camp-tab-count { background: var(--green-bg); color: var(--green); }
.camp-tab-dot { color: var(--green); font-size: 20px; line-height: 0; }
.camp-tab--add { font-size: 17px; padding: 6px 12px; color: var(--ink-soft); }

/* ------------------------------------------------------ plakietka NOWY */
.badge-new {
    display: inline-block; padding: 2px 7px; border-radius: 999px;
    background: var(--green); color: #fff;
    font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
    vertical-align: middle;
}
.col-new { width: 56px; }
.pill--new { background: var(--green); border-color: var(--green); color: #fff; }
.leads tr.is-new td:first-child { box-shadow: inset 3px 0 0 var(--green); }
.leads tr.is-new.is-done td:first-child { box-shadow: inset 3px 0 0 var(--green); }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 640px) {
    .camp-tab-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
    .table-wrap { max-height: calc(100vh - 310px); }
}

/* --------------------------------------------------------- źródło leada */
.src {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 7px; line-height: 1;
    background: #eef0eb; border: 1px solid var(--line); color: var(--ink-soft);
    font-size: 11px; font-weight: 700; letter-spacing: .04em; cursor: default;
}
.src svg { display: block; }
.src--fb { background: #e7f0fe; border-color: #cfe0fc; color: #1256b8; }
.src--ig { background: #fdeaf4; border-color: #f6cfe4; color: #a81f74; }
.leads td:has(.src), .leads th[title="platform"] { width: 1%; }
.leads tr.is-done .src { opacity: .75; }

/* ------------------------------------------- konfiguracja kolumn */
.col-config { display: grid; gap: 6px; margin-top: 4px; }
.col-row { display: grid; grid-template-columns: minmax(0, 1fr) 200px; gap: 10px; align-items: center; }
.col-row .check { min-width: 0; }
.col-raw {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px; color: var(--ink-soft);
}
.col-label { padding: 6px 9px !important; font-size: 13px !important; }

/* długie pytania z formularza nie mogą rozpychać tabeli */
.leads thead th { white-space: normal; max-width: 220px; }
.leads thead th.col-check, .leads thead th.col-when, .leads thead th.col-new { white-space: nowrap; }
.leads td { max-width: 260px; }

@media (max-width: 640px) {
    .col-row { grid-template-columns: 1fr; gap: 3px; }
}

/* strzałki kolejności kolumn */
.col-row { grid-template-columns: 44px minmax(0, 1fr) 200px; }
.col-move { display: flex; gap: 2px; }
.col-move button {
    width: 20px; height: 24px; padding: 0; line-height: 1;
    border: 1px solid var(--line); border-radius: 5px;
    background: var(--surface); color: var(--ink-soft); cursor: pointer; font-size: 11px;
}
.col-move button:hover { background: #f2f4ef; color: var(--ink); }
.col-row.just-moved { animation: moved .4s ease; }
@keyframes moved {
    from { background: var(--green-bg); }
    to   { background: transparent; }
}

@media (max-width: 640px) {
    .col-row { grid-template-columns: 44px 1fr; }
    .col-row .col-label { grid-column: 2; }
}

/* sortowanie po dacie */
.sort-link {
    display: inline-flex; align-items: center; gap: 5px;
    text-decoration: none; color: inherit; white-space: nowrap;
}
.sort-link:hover { color: var(--ink); }
.sort-arrow {
    display: inline-grid; place-items: center;
    width: 15px; height: 15px; border-radius: 4px;
    background: var(--green-bg); color: var(--green); font-size: 10px;
}
