* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --border: #e8eaee;
    --text: #17181c;
    --muted: #8a8f98;
    --blue: #2a6de5;
    --blue-dark: #1f5bc4;
    --blue-bg: #eaf1fd;
    --green: #1d8a46;
    --green-bg: #e5f6eb;
    --red: #d2504c;
    --red-bg: #fce9e9;
    --teal: #12857a;
    --teal-bg: #e3f3f1;
    --shadow: 0 1px 2px rgba(23, 24, 28, 0.05);
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    min-height: 100vh;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

button { font: inherit; cursor: pointer; background: none; border: none; color: inherit; }
input { font: inherit; color: inherit; border: none; outline: none; background: transparent; width: 100%; }
a { color: inherit; text-decoration: none; }

/* ---------- layout ---------- */

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

/* ---------- sidebar ---------- */

.sidebar {
    width: 264px;
    flex-shrink: 0;
    background: #f9fafb;
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-center { justify-content: center; margin-bottom: 6px; }

.brand-mark {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--blue), var(--blue-dark));
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
}

.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }

.side-search {
    display: flex; align-items: center; gap: 8px;
    background: #eef0f3;
    border-radius: 10px;
    padding: 9px 12px;
    color: var(--muted);
}
.side-search svg { width: 16px; height: 16px; }

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

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--muted);
    font-weight: 500;
    border: 1px solid transparent;
}
.nav-item:hover { color: var(--text); background: #f1f2f4; }
.nav-item.active {
    background: var(--card);
    color: var(--text);
    font-weight: 600;
    border-color: var(--border);
    box-shadow: var(--shadow);
}

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

/* ---------- topbar ---------- */

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 14px 28px;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
}

.topbar-search {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 14px;
    color: var(--muted);
    width: 340px; max-width: 45vw;
}
.topbar-search svg { width: 16px; height: 16px; }

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

.icon-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

.user-chip { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.user-name { white-space: nowrap; }

.logout-link { color: var(--muted); font-size: 13px; }
.logout-link:hover { color: var(--red); }

.avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: #e4e6ea;
    color: #5c6270;
    font-size: 11px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.avatar-user { background: var(--blue-bg); color: var(--blue); }

/* ---------- content ---------- */

.content { padding: 26px 28px; display: flex; flex-direction: column; gap: 24px; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: var(--shadow);
}

.stat-head { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 500; font-size: 13px; }
.stat-head svg { width: 16px; height: 16px; }

.stat-value { display: flex; align-items: center; gap: 10px; margin: 10px 0 6px; }
.stat-value strong { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }

.delta { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.delta-up { background: var(--green-bg); color: var(--green); }
.delta-down { background: var(--red-bg); color: var(--red); }

.stat-sub { color: var(--muted); font-size: 12px; }

/* ---------- contacts header ---------- */

.contacts-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.contacts-head h1 { font-size: 20px; font-weight: 700; }

.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; gap: 7px;
    padding: 7px 14px;
    border-radius: 6px;
    font-weight: 600; font-size: 13px;
}
.btn svg { width: 16px; height: 16px; }

.btn-light { background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); }
.btn-light:hover { background: #f7f8fa; }

.btn-primary { background: var(--blue); color: #fff; border: 1px solid var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }

.btn-block { width: 100%; justify-content: center; padding: 9px; font-size: 14px; }

/* ---------- table card ---------- */

.table-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-toolbar {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 16px;
    flex-wrap: wrap;
}

.tabs { display: flex; background: #f1f2f4; border-radius: 10px; padding: 4px; gap: 2px; }

.tab {
    padding: 7px 16px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 500; font-size: 13px;
}
.tab.active { background: var(--card); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

.table-search {
    display: flex; align-items: center; gap: 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    color: var(--muted);
    width: 240px;
}
.table-search svg { width: 15px; height: 15px; }

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; min-width: 820px; }

thead th {
    background: #f7f8fa;
    color: var(--muted);
    font-size: 12px; font-weight: 500;
    text-align: left;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td { padding: 13px 16px; border-bottom: 1px solid #f0f1f4; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }

.cell-name { display: flex; align-items: center; gap: 10px; font-weight: 600; }

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

.pill {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 12px; font-weight: 600;
    border: 1px solid transparent;
}
.pill-prospect { color: var(--blue); background: var(--blue-bg); border-color: #cdddf9; }
.pill-customer { color: var(--teal); background: var(--teal-bg); border-color: #c4e5e1; }
.pill-lead { color: #5c6270; background: #f1f2f4; border-color: #dfe1e6; }
.pill-inactive { color: var(--red); background: var(--red-bg); border-color: #f5cfce; }

.th-actions, .td-actions { text-align: right; }
.no-results { text-align: center; padding: 28px; }

/* ---------- login page ---------- */

.auth-wrap {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(23, 24, 28, 0.07);
    padding: 40px;
    width: 100%; max-width: 380px;
    text-align: center;
}

.auth-card h1 { font-size: 22px; font-weight: 700; margin-top: 10px; }
.auth-sub { color: var(--muted); margin: 6px 0 24px; }

.auth-error {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #f5cfce;
    border-radius: 10px;
    padding: 10px;
    font-size: 13px;
    margin-bottom: 18px;
}

.field { display: block; text-align: left; margin-bottom: 10px; }
.field span {
    display: block;
    font-size: 12px; font-weight: 600;
    margin-bottom: 4px;
    color: #3f4450;
}
.field input {
    border: 1px solid #d0d4dc;
    border-radius: 5px;
    padding: 7px 10px;
    background: #fff;
    font-size: 13px;
}
.field input:focus { border-color: var(--blue); background: var(--card); }

.qr-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    display: inline-block;
    margin-bottom: 12px;
}
.qr-box svg { width: 190px; height: 190px; display: block; }

.qr-alt { color: var(--muted); font-size: 12px; margin-bottom: 18px; }
.qr-alt code {
    display: inline-block;
    margin-top: 4px;
    background: #f4f5f7;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    word-break: break-all;
}

.code-input {
    text-align: center;
    font-size: 20px !important;
    letter-spacing: 8px;
    font-weight: 600;
}

.auth-back { display: block; margin-top: 16px; color: var(--muted); font-size: 13px; }
.auth-back:hover { color: var(--text); }

.auth-divider {
    display: flex; align-items: center; gap: 12px;
    margin: 18px 0;
    color: var(--muted); font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
    content: ""; flex: 1; height: 1px; background: var(--border);
}

.ms-btn { margin-top: 0; }
.ms-logo { width: 16px; height: 16px; stroke: none; }

/* ---------- users page ---------- */

.card-title { font-size: 15px; font-weight: 700; }

table.table-fit { min-width: 0; }

.td-email { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

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

.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 18px;
}
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.field select {
    width: 100%;
    border: 1px solid #d0d4dc;
    border-radius: 5px;
    padding: 7px 10px;
    background: #fff;
    font: inherit; font-size: 13px; color: inherit;
    outline: none;
}
.field select:focus { border-color: var(--blue); background: var(--card); }

.email-hint { font-size: 12px; margin-top: 6px; font-weight: 500; }
.hint-muted { color: var(--muted); }
.hint-ok { color: var(--green); }
.hint-warn { color: var(--blue); }
.hint-err { color: var(--red); }

.flash { border-radius: 10px; padding: 12px 16px; font-size: 13px; font-weight: 500; }
.flash-ok { background: var(--green-bg); color: var(--green); border: 1px solid #c8e9d4; }
.flash-err { background: var(--red-bg); color: var(--red); border: 1px solid #f5cfce; }

.inline-form { display: inline; }

.btn-danger { background: var(--card); border: 1px solid #f5cfce; color: var(--red); padding: 6px 14px; }
.btn-danger:hover { background: var(--red-bg); }

.add-user-form { padding: 12px 16px 14px; border-top: 1px solid var(--border); }

.form-footer {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; flex-wrap: wrap; margin-top: 2px;
}
.form-footer p { font-size: 11.5px; max-width: 460px; line-height: 1.45; }

/* ---------- field market research ---------- */

.row-link { font-weight: 600; }
.row-link:hover { color: var(--blue); }

.back-link { color: var(--muted); font-size: 13px; display: inline-block; margin-bottom: 6px; }
.back-link:hover { color: var(--text); }

.project-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.project-notes { margin-top: 8px; font-size: 13px; max-width: 640px; }

.field-wide { grid-column: 1 / -1; }

.field textarea {
    width: 100%;
    border: 1px solid #d0d4dc;
    border-radius: 5px;
    padding: 7px 10px;
    background: #fff;
    font: inherit; font-size: 13px; color: inherit;
    outline: none; resize: vertical;
}
.field textarea:focus { border-color: var(--blue); background: var(--card); }

.price-row { display: flex; gap: 8px; }
.currency-select {
    width: 82px !important;
    border: 1px solid #d0d4dc;
    border-radius: 5px;
    padding: 7px 6px;
    background: #fff;
    font: inherit; font-size: 13px; color: inherit; outline: none;
}

.file-input { padding: 8px !important; }
.file-input::file-selector-button {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    padding: 6px 12px;
    margin-right: 10px;
    font: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer;
}

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

.item-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 10px;
}

.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.item-name { font-weight: 700; }
.item-sub { font-size: 12px; margin-top: 2px; }
.item-price { font-weight: 700; font-size: 18px; white-space: nowrap; }
.item-price span { font-size: 12px; color: var(--muted); font-weight: 600; }

.item-details { font-size: 13px; color: #4b5060; white-space: pre-line; }

.photo-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-strip img {
    width: 72px; height: 72px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.item-foot {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    font-size: 12px;
    border-top: 1px solid #f0f1f4;
    padding-top: 10px;
    margin-top: auto;
    flex-wrap: wrap;
}
.map-link { color: var(--blue); font-weight: 600; }

.bulk-line { font-size: 13px; color: #4b5060; background: #f7f8fa; border-radius: 8px; padding: 8px 12px; }

.fmr-block {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    display: flex; flex-direction: column; gap: 10px;
    background: #fbfcfd;
}
.fmr-price-line { font-size: 13px; color: var(--muted); }

.fmr-form-wrap summary { list-style: none; cursor: pointer; display: inline-flex; width: fit-content; }
.fmr-form-wrap summary::-webkit-details-marker { display: none; }
.fmr-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

.item-delete { margin-top: 2px; align-self: flex-end; }

.geo-banner {
    position: fixed;
    left: 50%; bottom: 14px;
    transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 8px 24px rgba(23, 24, 28, 0.15);
    padding: 8px 10px 8px 18px;
    display: flex; align-items: center; gap: 12px;
    z-index: 40;
    max-width: calc(100vw - 24px);
}

.loc-btn { position: relative; }
.loc-dot {
    position: absolute;
    top: 5px; right: 5px;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #c1c5cd;
    border: 2px solid var(--card);
}
.loc-dot.loc-on { background: var(--green); animation: locpulse 2s ease-in-out infinite; }
.loc-dot.loc-off { background: var(--red); }

@keyframes locpulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(29, 138, 70, 0.4); }
    50% { box-shadow: 0 0 0 5px rgba(29, 138, 70, 0); }
}

.live-map-wrap { padding: 0 16px 12px; }
.live-map-wrap iframe {
    width: 100%; height: 300px;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: block;
}
.live-map-foot {
    display: flex; justify-content: space-between; align-items: center;
    gap: 10px; flex-wrap: wrap;
    padding-top: 8px;
    font-size: 12px;
}
.live-loc-note { padding: 0 16px 12px; font-size: 12px; }

@media (max-width: 700px) {
    .live-map-wrap iframe { height: 220px; }
}

.diff-up { color: var(--green); font-weight: 700; }
.diff-down { color: var(--red); font-weight: 700; }
.report-note { font-size: 12px; max-width: 640px; }

/* research list: table on desktop, tap cards on mobile */
.research-cards { display: none; }
.research-card { gap: 6px; }
.research-card:active { background: #f7f8fa; }
.research-card-foot { font-size: 12px; }

@media (max-width: 700px) {
    .research-table-wrap { display: none; }
    .research-cards { display: grid; gap: 12px; }

    .contacts-head { flex-direction: column; align-items: stretch; }
    .head-actions { width: 100%; }
    .head-actions .btn { flex: 1; justify-content: center; }

    .items-grid { grid-template-columns: 1fr; }
    .item-price { font-size: 16px; }
    .fmr-form-wrap summary { width: 100%; justify-content: center; }
    .form-footer { flex-direction: column; align-items: stretch; }
    .form-footer .btn, .form-footer .row-actions { width: 100%; }
    .form-footer .row-actions .btn { flex: 1; justify-content: center; }
    .geo-banner { bottom: 10px; padding: 7px 8px 7px 14px; font-size: 12px; }
}

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

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(23, 24, 28, 0.45);
    display: none;
    align-items: center; justify-content: center;
    padding: 20px;
    z-index: 50;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--card);
    border-radius: 14px;
    padding: 26px;
    width: 100%; max-width: 540px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 18px 50px rgba(23, 24, 28, 0.25);
}
.modal .card-title { margin-bottom: 16px; }
.modal-grid { margin-top: 4px; }
.modal-note { font-size: 12px; margin: 4px 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
}

.menu-btn { display: none; }

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(23, 24, 28, 0.4);
    z-index: 55;
}

@media (max-width: 860px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 60;
        width: 272px;
        transform: translateX(-110%);
        transition: transform 0.22s ease;
        box-shadow: 8px 0 30px rgba(23, 24, 28, 0.15);
        overflow-y: auto;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-backdrop.open { display: block; }

    .menu-btn { display: flex; flex-shrink: 0; }

    .topbar { padding: 12px 14px; gap: 10px; }
    .topbar-search { max-width: none; flex: 1; width: auto; }
    .content { padding: 16px; }
    .user-name { display: none; }
    .logout-link { white-space: nowrap; }

    .contacts-head h1 { font-size: 18px; }
    .head-actions .btn { padding: 8px 12px; font-size: 12px; }
    .table-toolbar { padding: 12px; }
    .tabs { overflow-x: auto; max-width: 100%; }
    .table-search { width: 100%; }
}

@media (max-width: 400px) {
    .items-grid { grid-template-columns: 1fr; }
    .row-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 620px) {
    .stats { grid-template-columns: 1fr; }
}

/* ---------- responsive auth pages (login / 2FA) ---------- */

@media (max-width: 560px) {
    /* 16px stops mobile browsers auto-zooming on focus */
    .field input, .field select, .field textarea { font-size: 16px; }
}

@media (max-width: 480px) {
    .auth-wrap {
        padding: 16px;
        align-items: flex-start;
        padding-top: 7vh;
    }
    .auth-card {
        padding: 28px 20px;
        max-width: 100%;
    }
    .auth-card h1 { font-size: 20px; }
    .qr-box { padding: 10px; }
    .qr-box svg { width: min(190px, 62vw); height: min(190px, 62vw); }
    .code-input { letter-spacing: 5px; }
}

@media (max-height: 620px) {
    .auth-wrap { align-items: flex-start; padding-top: 16px; }
}
