:root {
    --p-accent: #a259ff;
    --p-blue: #1cb5e0;
    --p-green: #59b43f;
    --p-red: #ff4d6d;
    --p-amber: #ffb020;
    --p-bg: #0b0f1a;
    --p-surface: #141a2c;
    --p-surface-alt: #1a2138;
    --p-border: #2a3352;
    --p-text: #e8ecf5;
    --p-muted: #8a93ad;
}

/* Motyw jasny - przelacznik w stopce sidebaru, zapamietywany per przegladarke
   (localStorage panelu, niezalezny od motywu publicznej strony). */
:root[data-theme="light"] {
    --p-bg: #f2f4f9;
    --p-surface: #ffffff;
    --p-surface-alt: #f1f4f8;
    --p-border: #dde2ee;
    --p-text: #12182b;
    --p-muted: #6b7386;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--p-bg);
    color: var(--p-text);
    -webkit-font-smoothing: antialiased;
}

#app { min-height: 100vh; }

a { color: inherit; }

button {
    font-family: inherit;
    cursor: pointer;
}

input, select, textarea {
    font-family: inherit;
    font-size: 14px;
    color: var(--p-text);
    background: var(--p-surface);
    border: 1px solid var(--p-border);
    border-radius: 8px;
    padding: 9px 11px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--p-accent);
}

/* ---------------- LOGIN ---------------- */

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

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

.login-logo {
    display: block;
    height: 34px;
    margin: 0 0 14px;
    background: #fff;
    border-radius: 8px;
    padding: 8px 12px;
}

.login-box .login-sub {
    color: var(--p-muted);
    font-size: 13px;
    margin: 0 0 24px;
}

.login-box label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--p-muted);
    margin: 14px 0 6px;
}

.login-box input {
    width: 100%;
}

.login-box .btn-primary {
    width: 100%;
    margin-top: 22px;
}

.login-error {
    margin-top: 14px;
    color: var(--p-red);
    font-size: 13px;
}

/* ---------------- SHELL / LAYOUT ---------------- */

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

.sidebar {
    width: 220px;
    flex: 0 0 auto;
    background: var(--p-surface);
    border-right: 1px solid var(--p-border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    padding: 0 0 22px;
}

/* Logo ma ciemny napis "mikup.pl" - na ciemnym tle sidebaru byloby prawie
   niewidoczne, wiec dostaje jasna "kartke" pod spodem niezaleznie od
   wybranego motywu panelu. */
.sidebar-logo-img {
    display: block;
    height: 34px;
    max-width: 100%;
    background: #fff;
    border-radius: 8px;
    padding: 6px 10px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 9px;
    color: var(--p-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.nav-link:hover { background: var(--p-surface-alt); color: var(--p-text); }

.nav-badge {
    margin-left: auto;
    background: var(--p-red);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 20px;
    min-width: 8px;
    text-align: center;
}

.nav-link.is-active {
    background: linear-gradient(90deg, rgba(28,181,224,0.18), rgba(162,89,255,0.18));
    color: var(--p-text);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--p-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn-logout, .btn-theme-toggle {
    width: 100%;
    background: transparent;
    border: 1px solid var(--p-border);
    color: var(--p-muted);
    border-radius: 9px;
    padding: 9px;
    font-size: 13px;
    font-weight: 600;
}

.btn-theme-toggle::before {
    content: "☾ Tryb jasny";
}

:root[data-theme="light"] .btn-theme-toggle::before {
    content: "☀ Tryb ciemny";
}

.btn-logout:hover, .btn-theme-toggle:hover { color: var(--p-text); border-color: var(--p-muted); }

/* ---------------- POWIADOMIENIA (Dashboard) ---------------- */

.notif-group-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--p-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 0 0 10px;
}

.notif-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--p-border);
    font-size: 13px;
}

.notif-row:last-child { border-bottom: none; }
.notif-row-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-row-date { color: var(--p-muted); flex: 0 0 auto; font-size: 12px; }

.btn-logout:hover { color: var(--p-red); border-color: var(--p-red); }

.main {
    flex: 1;
    min-width: 0;
    padding: 28px 32px 60px;
}

.page-title {
    font-size: 22px;
    font-weight: 800;
    margin: 0 0 22px;
}

/* ---------------- COMMON UI ---------------- */

.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    background: var(--p-surface-alt);
    color: var(--p-text);
    border: 1px solid var(--p-border);
}

.btn:hover { border-color: var(--p-muted); }

.btn-primary {
    background: linear-gradient(90deg, var(--p-blue), var(--p-accent));
    color: #fff;
    border: none;
}

.btn-danger { color: var(--p-red); border-color: rgba(255,77,109,0.4); }
.btn-danger:hover { background: rgba(255,77,109,0.1); }

.btn-sm { padding: 6px 10px; font-size: 12px; }

.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--p-surface);
    border: 1px solid var(--p-border);
    border-radius: 14px;
    padding: 18px 20px;
}

.stat-card.is-clickable { cursor: pointer; transition: border-color 0.15s; }
.stat-card.is-clickable:hover { border-color: var(--p-accent); }
.stat-card.is-active-filter { border-color: var(--p-accent); background: var(--p-surface-alt); }

.stat-value { position: relative; display: inline-flex; align-items: center; gap: 8px; }

.stat-badge {
    background: var(--p-red);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    padding: 3px 7px;
    border-radius: 20px;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 800;
}

.stat-card .stat-label {
    color: var(--p-muted);
    font-size: 12px;
    font-weight: 600;
    margin-top: 4px;
}

.panel-block {
    background: var(--p-surface);
    border: 1px solid var(--p-border);
    border-radius: 14px;
    padding: 18px 20px;
}

.panel-block h2 {
    font-size: 15px;
    margin: 0 0 12px;
}

.recent-row {
    display: flex;
    justify-content: space-between;
    padding: 9px 0;
    border-bottom: 1px solid var(--p-border);
    font-size: 13px;
}

.recent-row:last-child { border-bottom: none; }
.recent-row .rr-date { color: var(--p-muted); }

/* ---------------- TOOLBAR / SEARCH ---------------- */

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

.toolbar input[type="text"], .toolbar select {
    min-width: 220px;
}

.toolbar .spacer { flex: 1; }

/* ---------------- TABLE ---------------- */

.table-wrap {
    background: var(--p-surface);
    border: 1px solid var(--p-border);
    border-radius: 14px;
    overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--p-muted);
    background: var(--p-surface-alt);
    border-bottom: 1px solid var(--p-border);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--p-border);
    vertical-align: top;
}

tr:last-child td { border-bottom: none; }

tr.is-clickable { cursor: pointer; }
tr.is-clickable:hover td { background: var(--p-surface-alt); }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}

.badge-green { background: rgba(89,180,63,0.15); color: var(--p-green); }
.badge-red { background: rgba(255,77,109,0.15); color: var(--p-red); }

.row-actions { display: flex; gap: 6px; }

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--p-muted);
    font-size: 13px;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    padding: 16px;
    font-size: 13px;
    color: var(--p-muted);
}

/* ---------------- DRAWER (edycja) ---------------- */

.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: flex-end;
    z-index: 50;
}

.drawer {
    width: 100%;
    max-width: 560px;
    height: 100%;
    background: var(--p-surface);
    border-left: 1px solid var(--p-border);
    padding: 24px 26px;
    overflow-y: auto;
}

.drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.drawer-header h2 { margin: 0; font-size: 18px; }

.drawer-close {
    background: none;
    border: none;
    color: var(--p-muted);
    font-size: 20px;
    line-height: 1;
    padding: 4px;
}

.field-group { margin-bottom: 16px; }

.field-group label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: var(--p-muted);
    margin-bottom: 6px;
}

.field-group input, .field-group select, .field-group textarea { width: 100%; }

.field-group textarea { resize: vertical; min-height: 90px; }

.field-list-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.field-list-row input { flex: 1; }

.field-list-row .btn-sm { flex: 0 0 auto; }

.section-heading {
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--p-muted);
    margin: 22px 0 12px;
    padding-top: 16px;
    border-top: 1px solid var(--p-border);
}

.section-heading:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.offer-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 8px 10px;
    align-items: center;
    margin-bottom: 8px;
}

.offer-grid .offer-portal-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--p-text);
}

.drawer-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--p-border);
}

.drawer-actions .btn-primary { flex: 1; }

/* ---------------- OPINIONS ---------------- */

.opinion-card {
    background: var(--p-surface);
    border: 1px solid var(--p-border);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 12px;
}

.opinion-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.opinion-meta { font-size: 12px; color: var(--p-muted); margin-top: 4px; }
.opinion-product { font-size: 12px; color: var(--p-blue); font-weight: 700; margin-bottom: 4px; }
.opinion-text { font-size: 14px; margin: 10px 0; white-space: pre-wrap; }
.opinion-nick { font-weight: 700; }
.opinion-avg { color: var(--p-accent); font-weight: 700; }

.opinion-comments {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--p-border);
}

.comment-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 12px;
    padding: 6px 0;
    color: var(--p-muted);
}

.comment-row strong { color: var(--p-text); }

.opinion-edit-box textarea { width: 100%; margin-top: 8px; }
.opinion-edit-box input { width: 100%; margin-top: 8px; }

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--p-surface-alt);
    border: 1px solid var(--p-border);
    color: var(--p-text);
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 100;
}

.toast.is-error { border-color: var(--p-red); color: var(--p-red); }

.loading-state { padding: 40px; text-align: center; color: var(--p-muted); }

/* ---------------- PRODUKTY: wiersz rozwijany + kolapsy w edycji ---------------- */

.expand-arrow { width: 22px; color: var(--p-muted); font-size: 11px; }

tr.detail-row td { background: var(--p-surface-alt); padding: 0; border-bottom: 1px solid var(--p-border); }

.product-detail-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 16px 20px;
}

.product-detail-panel h4 {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--p-muted);
}

.detail-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.detail-list li { padding: 4px 0; }
.detail-list a { color: var(--p-blue); }

.detail-kv { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--p-border); }
.detail-kv:last-child { border-bottom: none; }
.detail-kv span:first-child { color: var(--p-muted); }

.detail-empty { color: var(--p-muted); font-size: 12px; margin: 0; }

.collapsible-section { border: 1px solid var(--p-border); border-radius: 10px; margin-bottom: 14px; overflow: hidden; }

.collapsible-header {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    background: var(--p-surface-alt);
    user-select: none;
}

.collapsible-header:hover { filter: brightness(1.05); }

.collapsible-body { padding: 14px; }

.content-readonly {
    white-space: pre-wrap;
    font-size: 13px;
    line-height: 1.5;
    padding: 10px 12px;
    border: 1px solid var(--p-border);
    border-radius: 8px;
    background: var(--p-surface-alt);
    max-height: 220px;
    overflow-y: auto;
}

.image-row { align-items: center; }
.image-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; flex: 0 0 auto; border: 1px solid var(--p-border); }

/* ---------------- STATYSTYKI: proste wykresy bez zewnetrznych bibliotek ---------------- */

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 140px;
    padding-top: 10px;
    overflow-x: auto;
}

.bar-chart-col {
    flex: 1 0 8px;
    min-width: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}

.bar-chart-bar {
    width: 100%;
    min-height: 2px;
    background: var(--p-accent, var(--p-blue));
    border-radius: 3px 3px 0 0;
}

.bar-chart-label {
    font-size: 9px;
    color: var(--p-muted);
    margin-top: 4px;
}

.hbar-list { display: flex; flex-direction: column; gap: 10px; }

.hbar-row {
    display: grid;
    grid-template-columns: 120px 1fr 40px;
    align-items: center;
    gap: 10px;
    font-size: 12px;
}

.hbar-label { color: var(--p-text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.hbar-track {
    background: var(--p-surface-alt);
    border-radius: 6px;
    height: 10px;
    overflow: hidden;
}

.hbar-fill { height: 100%; background: var(--p-accent, var(--p-blue)); border-radius: 6px; }

.hbar-count { text-align: right; color: var(--p-muted); font-weight: 700; }

/* ---------------- KONTAKT ---------------- */

tr.contact-unread td { font-weight: 700; }
tr.contact-unread .expand-arrow { color: var(--p-accent); font-size: 10px; }

@media (max-width: 720px) {
    .product-detail-panel { grid-template-columns: 1fr; }
    .shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 12px 14px; }
    .sidebar-logo { display: none; }
    .nav-link { padding: 8px 10px; font-size: 13px; }
    .sidebar-footer { margin-top: 0; margin-left: auto; border-top: none; padding-top: 0; }
    .main { padding: 18px; }
    .drawer { max-width: 100%; }
}
