:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #fafbfc;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --text: #1a1d21;
    --muted: #667085;
    --faint: #98a2b3;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: #eef2ff;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
    --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18);
    --sidebar: 244px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: Poppins, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

h1,
h2,
h3,
h4 {
    margin: 0;
    font-weight: 600;
    letter-spacing: -.01em;
}

h1 {
    font-size: 22px;
}

h2 {
    font-size: 17px;
}

h3 {
    font-size: 14px;
}

p {
    margin: 0;
}

/* ---------- układ ---------- */

.shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    gap: 26px;
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #e5ff00, #ff2a46 55%, #ff14ef);
    display: grid;
    place-items: center;
    color: #fff;
    flex-shrink: 0;
}

.brand-name {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}

.brand-sub {
    font-size: 11px;
    color: var(--faint);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-weight: 500;
    cursor: pointer;
    border: 0;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 13.5px;
    transition: background-color .15s, color .15s;
}

.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.nav-item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-count {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 1px 7px;
    color: var(--muted);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.main {
    flex: 1;
    margin-left: var(--sidebar);
    min-width: 0;
    padding: 22px 26px 60px;
}

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

.page-head p {
    color: var(--muted);
    font-size: 13px;
    margin-top: 2px;
}

/* ---------- karty ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card + .card {
    margin-top: 16px;
}

.card-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.card-body {
    padding: 18px;
}

.card-hint {
    font-size: 12px;
    color: var(--faint);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

/* ---------- profil ---------- */

.profile {
    display: flex;
    align-items: center;
    gap: 14px;
}

.profile img,
.profile .avatar-fallback {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-2);
    flex-shrink: 0;
    padding: 2px;
    border: 2px solid transparent;
    background-image: linear-gradient(var(--surface), var(--surface)), linear-gradient(135deg, #e5ff00, #ff2a46 55%, #ff14ef);
    background-origin: border-box;
    background-clip: content-box, border-box;
}

.profile-meta {
    display: flex;
    gap: 16px;
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 1px;
}

.profile-meta b {
    color: var(--text);
}

/* ---------- statystyki ---------- */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
    gap: 10px;
}

.stat {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
}

.stat-value {
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -.02em;
}

.stat-label {
    font-size: 11.5px;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ---------- formularze ---------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--muted);
}

input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=search],
select,
textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13.5px;
    transition: border-color .15s, box-shadow .15s;
}

input:focus,
select:focus,
textarea:focus {
    outline: 0;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

input[type=file] {
    font-size: 13px;
}

input[type=file]::file-selector-button {
    margin-right: 10px;
    padding: 7px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.search-field {
    position: relative;
}

.search-field svg {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    width: 15px;
    height: 15px;
    color: var(--faint);
}

.search-field input {
    padding-left: 33px;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
    cursor: pointer;
}

.checkline input {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    margin: 0;
}

/* ---------- przyciski ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, opacity .15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--accent-hover);
}

.btn svg {
    width: 15px;
    height: 15px;
}

.btn-ghost {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn-ghost:hover {
    background: var(--surface-2);
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12.5px;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: all .15s;
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.icon-btn.danger:hover {
    background: var(--danger-soft);
    border-color: #fecaca;
    color: var(--danger);
}

.icon-btn svg {
    width: 15px;
    height: 15px;
}

/* ---------- posty ---------- */

.toolbar {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.toolbar .field {
    min-width: 190px;
}

.toolbar .grow {
    flex: 1;
    min-width: 240px;
}

.post-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 16px;
}

.post {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    transition: box-shadow .2s, transform .2s;
}

.post:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.post-media {
    position: relative;
    aspect-ratio: 9 / 16;
    background: var(--surface-2);
    overflow: hidden;
}

.post-media img,
.post-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.post-badges {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    gap: 5px;
}

.badge {
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .72);
    color: #fff;
    backdrop-filter: blur(4px);
    letter-spacing: .02em;
}

.badge.new {
    background: rgba(5, 150, 105, .85);
}

.badge.saved {
    background: rgba(79, 70, 229, .85);
}

.post-body {
    padding: 11px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
    flex: 1;
}

.post-date {
    font-size: 11.5px;
    color: var(--faint);
}

.post-desc {
    font-size: 12.5px;
    color: var(--muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.9em;
}

.post-row {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: auto;
}

.priority-input {
    width: 58px;
    padding: 4px 7px;
    font-size: 12.5px;
    text-align: center;
}

.tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    padding: 2px 5px 2px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 500;
}

.chip button {
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
    padding: 0 2px;
    opacity: .6;
    font-size: 13px;
    line-height: 1;
}

.chip button:hover {
    opacity: 1;
}

.tag-add {
    display: flex;
    gap: 5px;
}

.tag-add input {
    padding: 4px 8px;
    font-size: 12.5px;
}

/* ---------- tabela tagów ---------- */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    text-align: left;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--faint);
    font-weight: 600;
    padding: 0 12px 9px;
}

.table td {
    padding: 9px 12px;
    border-top: 1px solid var(--border);
    vertical-align: middle;
}

.table tr:hover td {
    background: var(--surface-2);
}

/* ---------- token ---------- */

.token-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 15px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.token-status .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--faint);
    flex-shrink: 0;
}

.token-status.ok {
    background: var(--success-soft);
    border-color: #a7f3d0;
}

.token-status.ok .dot {
    background: var(--success);
}

.token-status.warn {
    background: var(--warning-soft);
    border-color: #fde68a;
}

.token-status.warn .dot {
    background: var(--warning);
}

.token-status.bad {
    background: var(--danger-soft);
    border-color: #fecaca;
}

.token-status.bad .dot {
    background: var(--danger);
}

.meter {
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}

.meter span {
    display: block;
    height: 100%;
    background: var(--success);
    transition: width .3s;
}

.meter.warn span {
    background: var(--warning);
}

.meter.bad span {
    background: var(--danger);
}

.kv {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 5px 16px;
    font-size: 12.5px;
}

.kv dt {
    color: var(--faint);
}

.kv dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

code.token {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    word-break: break-all;
}

/* ---------- pasek postępu ---------- */

.progress {
    height: 6px;
    border-radius: 999px;
    background: var(--border);
    overflow: hidden;
}

.progress span {
    display: block;
    height: 100%;
    background: var(--accent);
    transition: width .2s;
}

.alert {
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    font-size: 12.5px;
    border: 1px solid;
}

.alert.info {
    background: var(--accent-soft);
    border-color: #c7d2fe;
    color: #3730a3;
}

.alert.ok {
    background: var(--success-soft);
    border-color: #a7f3d0;
    color: #065f46;
}

.alert.bad {
    background: var(--danger-soft);
    border-color: #fecaca;
    color: #991b1b;
}

.alert.warn {
    background: var(--warning-soft);
    border-color: #fde68a;
    color: #92400e;
}

.alert ul {
    margin: 6px 0 0;
    padding-left: 18px;
}

/* ---------- toasty ---------- */

.toasts {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.toast {
    background: #101828;
    color: #fff;
    padding: 10px 15px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    animation: toast-in .2s ease-out;
    max-width: 340px;
}

.toast.bad {
    background: var(--danger);
}

.toast.ok {
    background: var(--success);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
}

/* ---------- modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .5);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 90;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    max-width: 420px;
    width: 100%;
    padding: 22px;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    font-size: 16px;
    margin-bottom: 6px;
}

.modal p {
    color: var(--muted);
    font-size: 13px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

/* ---------- logowanie ---------- */

.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 32px 28px;
}

.login-card .brand {
    justify-content: center;
    margin-bottom: 22px;
    padding: 0;
}

.login-card .field + .field {
    margin-top: 13px;
}

.login-card .btn {
    width: 100%;
    margin-top: 20px;
    padding: 10px;
}

/* ---------- pomocnicze ---------- */

.stack {
    display: flex;
    flex-direction: column;
    gap: 13px;
}

.row {
    display: flex;
    gap: 9px;
    align-items: center;
    flex-wrap: wrap;
}

.muted {
    color: var(--muted);
}

.faint {
    color: var(--faint);
    font-size: 12px;
}

.hidden {
    display: none !important;
}

.empty-state {
    text-align: center;
    padding: 44px 20px;
    color: var(--faint);
}

.sidebar-toggle {
    display: none;
}

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.is-open {
        transform: none;
    }

    .main {
        margin-left: 0;
        padding: 16px 14px 50px;
    }

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