/* ============================================================
   ভূমি মাপক — Area Calculator (মোবাইল-প্রথম স্টাইল)
   ============================================================ */

:root {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #16a34a;
    --red: #dc2626;
    --bg: #f1f5f9;
    --card: #ffffff;
    --txt: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
}

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

html, body { height: 100%; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, 'Noto Sans Bengali', sans-serif;
    color: var(--txt);
    background: var(--bg);
    overflow: hidden;
}

/* ---------- হেডার ---------- */
.topbar {
    position: relative;
    z-index: 1000;
    height: 56px;
    background: linear-gradient(90deg, var(--blue-dark), var(--blue));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.tb-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 11px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- ফুলস্ক্রিন বাটন ---------- */
.fs-btn {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    background: rgba(255,255,255,.16);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease, transform .1s ease;
}
.fs-btn:hover { background: rgba(255,255,255,.3); }
.fs-btn:active { transform: scale(.93); }
.fs-btn .ico { width: 20px; height: 20px; display: block; }
.fs-btn .ico-fs-exit { display: none; }
body.fs-active .fs-btn .ico-fs { display: none; }
body.fs-active .fs-btn .ico-fs-exit { display: block; }

/* ফুলস্ক্রিন অবস্থায় কমপ্যাক্ট টাইটেল দৃশ্যমান থাকে;
   প্যানেল syncFsUI() এর 'closed' ক্লাসে হ্যান্ডেল ("মাপ ও নিয়ন্ত্রণ") দেখায় */
body.fs-active .tb-main { display: flex; flex: 1 1 auto; min-width: 0; }
body.fs-active .topbar { height: 44px; padding: 0 10px; }
body.fs-active .topbar h1 { font-size: 13px; }
body.fs-active .topbar .sub { font-size: 9.5px; }
body.fs-active #map { top: 44px; }

/* ---------- মানচিত্র ---------- */
#map {
    position: absolute;
    top: 56px; left: 0; right: 0; bottom: 0;
    z-index: 0;
    background: #dbeafe;
}

/* ---------- ম্যাপ লেআউট সুইচার ---------- */
#mapSwitcher {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    gap: 5px;
    background: rgba(255,255,255,.95);
    padding: 5px;
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
    max-width: calc(100vw - 16px);
}
#mapSwitcher button {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--txt);
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s ease;
}
#mapSwitcher button.active {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}
@media (max-width: 480px) {
    #mapSwitcher button { padding: 6px 8px; font-size: 11.5px; }
}

/* ---------- নিচের প্যানেল ---------- */
#panel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    z-index: 1100;
    background: var(--card);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.18);
    max-height: 56vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform .25s ease;
}
#panel .handle {
    height: 36px;
    flex: 0 0 36px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    border-radius: 16px 16px 0 0;
}
#panel .handle .arrow { font-size: 11px; transition: transform .25s ease; }
#panel.closed { transform: translateY(calc(100% - 36px)); }
#panel.closed .handle .arrow { transform: rotate(180deg); }
#panelBody { overflow-y: auto; padding: 10px 12px 14px; -webkit-overflow-scrolling: touch; }

/* ---------- কার্ড ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 8px;
}
.card:last-child { margin-bottom: 0; }

/* ---------- পরিমাপ কার্ড ---------- */
.measure .big {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}
.measure #mValue {
    font-size: 32px;
    font-weight: 800;
    color: var(--blue);
    line-height: 1.1;
    word-break: break-all;
}
.measure #mUnit { font-size: 14px; font-weight: 600; color: var(--muted); }

.measure .rows { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
.measure .rows > div {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 13px;
    color: var(--muted);
}
.measure .rows b { color: var(--txt); font-weight: 600; }
#accuracyRow { display: none; }
.measure .unitbox { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.measure .unitbox label { font-size: 13px; color: var(--muted); }

select {
    font-family: inherit;
    font-size: 14px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f8fafc;
    color: var(--txt);
    outline: none;
    max-width: 100%;
}

/* ---------- মোড / ভিউ বাটন ---------- */
.btnrow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
#actionRow { grid-template-columns: repeat(4, 1fr); }

.btn {
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    padding: 10px 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--txt);
    cursor: pointer;
    transition: all .15s ease;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary.active { background: var(--blue-dark); box-shadow: inset 0 0 0 2px rgba(255,255,255,.35); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 8px 10px; font-size: 12px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
    flex: 1 1 auto;
    min-width: 72px;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    padding: 9px 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--txt);
    cursor: pointer;
    transition: all .15s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.seg button.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- সেভ করা তালিকা ---------- */
.saved { margin-top: 8px; display: flex; gap: 6px; align-items: center; }
.saved select { flex: 1; min-width: 0; }
.saved .btn { flex: 0 0 auto; }

/* ---------- নির্দেশনা ---------- */
.hint { font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.hint b { color: var(--txt); }

/* ---------- টোস্ট / স্ট্যাটাস ---------- */
#toast {
    position: absolute;
    top: 68px; left: 50%;
    transform: translateX(-50%) translateY(-12px);
    background: rgba(15,23,42,.92);
    color: #fff;
    padding: 9px 16px;
    border-radius: 999px;
    font-size: 13px;
    max-width: 90%;
    text-align: center;
    z-index: 1300;
    opacity: 0;
    pointer-events: none;
    transition: all .25s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#statusbar {
    position: absolute;
    bottom: calc(56vh + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(22,163,74,.95);
    color: #fff;
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    z-index: 1200;
    display: none;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
    max-width: 92%;
    text-align: center;
}
#statusbar:not(:empty) { display: block; }

/* ---------- লিফলেট সামান্য সামঞ্জস্য ---------- */
.leaflet-container { font-family: inherit; }
.leaflet-popup-content { font-size: 13px; }

/* ---------- ল্যান্ডস্কেপ / বড় স্ক্রিন ---------- */
@media (min-width: 900px) {
    #panel { left: auto; right: 16px; bottom: 16px; width: 360px; border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
    #panel.closed { transform: translateY(calc(100% - 36px)); }
    #statusbar { bottom: auto; top: 68px; }
}