:root {
    --primary: #1a7a1a;
    --primary-dark: #0f5a0f;
    --accent: #2C4A1E;
    --bg: #f0f2f5;
    --card: #ffffff;
    --text: #1c1e21;
    --text-secondary: #65676b;
    --border: #ced0d4;
    --danger: #dc3545;
    --warning: #f9a825;
    --header-h: 56px;
    --bottom-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    padding-top: var(--header-h);
    padding-bottom: var(--bottom-h);
    min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ── HEADER ── */
.site-header {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--primary);
    color: white;
    display: flex; align-items: center;
    padding: 0 12px; gap: 8px;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,.1);
}
.site-header .logo {
    font-size: 18px; font-weight: bold;
    color: white; text-decoration: none;
    display: flex; align-items: center; gap: 6px;
}
.site-header .logo:hover { text-decoration: none; }
.site-header .spacer { flex: 1; }

/* ── Header search bar ── */
.hd-search {
    flex: 1;
    margin: 0 8px;
    max-width: 420px;
}
.hd-search input {
    width: 100%;
    padding: 8px 14px;
    background: rgba(255,255,255,0.95);
    border: none;
    border-radius: 18px;
    font-size: 14px;
    color: var(--text);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.hd-search input::-webkit-search-decoration,
.hd-search input::-webkit-search-cancel-button,
.hd-search input::-webkit-search-results-button,
.hd-search input::-webkit-search-results-decoration { -webkit-appearance: none; }
.hd-search input:focus {
    background: white;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.4);
}

/* Header icon group — баруун тал руу түлхэх */
.head-actions {
    margin-left: auto;
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
@media (min-width: 768px) {
    .hd-search { max-width: 420px; }
}
.site-header .head-btn {
    background: rgba(255,255,255,0.15);
    border: none; color: white;
    width: 38px; height: 38px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    position: relative;
    font-size: 18px;
}
.site-header .head-btn:hover { background: rgba(255,255,255,0.25); }
.notif-badge {
    position: absolute;
    top: -2px; right: -2px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    min-width: 18px; height: 18px;
    font-size: 10px; font-weight: bold;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}

/* ── BOTTOM NAV ── */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--bottom-h);
    background: var(--card);
    display: flex;
    border-top: 1px solid var(--border);
    z-index: 999;
}
.bottom-nav a {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-secondary);
    font-size: 10px;
    text-decoration: none;
    transition: color 0.15s;
    padding: 4px 0;
}
.bottom-nav a .ico { font-size: 22px; line-height: 1; margin-bottom: 2px; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a:hover { color: var(--primary); text-decoration: none; }

/* ── CONTAINER ── */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 12px;
}

/* ── CARD ── */
.card {
    background: var(--card);
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,.1);
    margin-bottom: 12px;
    overflow: hidden;
}
.card-body { padding: 12px 14px; }
.card-header {
    padding: 10px 14px;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid #f0f0f0;
}
.card-header .avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}
.card-header .meta { flex: 1; min-width: 0; }
.card-header .name { font-weight: 600; font-size: 14px; }
.card-header .when { font-size: 11px; color: var(--text-secondary); }

/* ── FORM ── */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 13px; font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-secondary);
}
.form-control, input[type=text], input[type=number], input[type=email],
input[type=password], input[type=tel], input[type=date], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: white;
    font-family: inherit;
}
.form-control:focus, input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26,122,26,0.15);
}
textarea { min-height: 80px; resize: vertical; }

/* ── BUTTON ── */
.btn {
    display: inline-block;
    padding: 10px 18px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; text-decoration: none; }
.btn-secondary {
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: #e4e6eb; color: var(--text); text-decoration: none; }
.btn-danger { background: var(--danger); color: white; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ── BADGE ── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.badge-primary { background: rgba(26,122,26,0.15); color: var(--primary-dark); }
.badge-warn    { background: rgba(249,168,37,0.20); color: #8a5a00; }
.badge-danger  { background: rgba(220,53,69,0.15);  color: #a71d2a; }
.badge-info    { background: rgba(13,110,253,0.15); color: #084298; }

/* ── ALERT/MESSAGE ── */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 13px;
}
.alert-success { background: #d4edda; color: #155724; border-left: 3px solid #28a745; }
.alert-error   { background: #f8d7da; color: #721c24; border-left: 3px solid #dc3545; }
.alert-info    { background: #cce5ff; color: #004085; border-left: 3px solid #007bff; }

/* ── DROPDOWN (header logo menu) ── */
.malmap-dropdown { position: relative; }
.malmap-dropdown-menu {
    position: absolute;
    top: calc(100% + 4px); left: 0;
    background: white; border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,.18);
    min-width: 200px;
    overflow: hidden;
    display: none;
    z-index: 2000;
}
.malmap-dropdown-menu.open { display: block; }
.malmap-dropdown-menu a {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    text-decoration: none; color: var(--text);
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
}
.malmap-dropdown-menu a:last-child { border-bottom: none; }
.malmap-dropdown-menu a:hover { background: var(--bg); text-decoration: none; }

/* ── FEED POST ── */
.post-content {
    padding: 0 14px 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.post-images { display: grid; gap: 2px; }
.post-images.n1 { grid-template-columns: 1fr; }
.post-images.n2 { grid-template-columns: 1fr 1fr; }
.post-images.n3, .post-images.n4 { grid-template-columns: 1fr 1fr; }
.post-image { aspect-ratio: 4/3; overflow: hidden; background: #ddd; }
.post-image img { width: 100%; height: 100%; object-fit: cover; }
.post-actions {
    display: flex;
    border-top: 1px solid #f0f0f0;
}
.post-actions button, .post-actions a {
    flex: 1;
    background: none; border: none;
    padding: 8px;
    color: var(--text-secondary);
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 6px;
    text-decoration: none;
}
.post-actions button:hover, .post-actions a:hover { background: var(--bg); }
.post-actions .liked { color: var(--primary); }

/* ── LISTING CARD (market/lost) ── */
.listing-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.listing-card {
    background: var(--card);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
    text-decoration: none;
    color: var(--text);
}
.listing-card:hover { text-decoration: none; color: var(--text); transform: translateY(-2px); transition: transform 0.15s; }
.listing-card .img {
    aspect-ratio: 4/3;
    background: #e4e6eb;
    overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    font-size: 38px;
}
.listing-card .img img { width: 100%; height: 100%; object-fit: cover; }
.listing-card .body { padding: 10px; }
.listing-card .price {
    font-size: 16px; font-weight: bold;
    color: var(--primary-dark);
    margin-bottom: 4px;
}
.listing-card .title { font-size: 13px; line-height: 1.3; margin-bottom: 6px; }
.listing-card .meta {
    font-size: 11px; color: var(--text-secondary);
    display: flex; justify-content: space-between;
}

/* ── TAB ── */
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--border); }
.tabs a {
    flex: 1;
    padding: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px; font-weight: 600;
    border-bottom: 3px solid transparent;
    text-decoration: none;
}
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a:hover { background: var(--bg); text-decoration: none; }

/* ── PAGE TITLE ── */
.page-title {
    font-size: 18px; font-weight: bold;
    padding: 14px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    margin: -12px -12px 12px;
    display: flex; align-items: center; gap: 8px;
}

/* ── EMPTY STATE ── */
.empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}
.empty .ico { font-size: 48px; margin-bottom: 8px; }

/* ── FAB (Floating Action Button) ── */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-h) + 12px); right: 16px;
    background: var(--primary);
    color: white;
    width: 56px; height: 56px;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    display: flex; align-items: center; justify-content: center;
    font-size: 26px;
    text-decoration: none;
    z-index: 998;
}
.fab:hover { background: var(--primary-dark); color: white; text-decoration: none; }

/* ── CHAT ── */
.chat-window {
    display: flex; flex-direction: column;
    height: calc(100vh - var(--header-h) - var(--bottom-h));
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.chat-msg {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 18px;
    font-size: 14px;
    word-break: break-word;
}
.chat-msg.me { background: var(--primary); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.them { background: white; align-self: flex-start; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.chat-time { font-size: 10px; opacity: 0.7; margin-top: 2px; }
.chat-input-row {
    display: flex; gap: 8px;
    padding: 8px;
    background: var(--card);
    border-top: 1px solid var(--border);
}
.chat-input-row input { flex: 1; }

/* ── UTILITY ── */
.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; }
.flex { display: flex; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; }
.flex-1 { flex: 1; }

@media (min-width: 768px) {
    .container { padding: 16px; }
    .listing-grid { grid-template-columns: 1fr 1fr 1fr; }
}
