/* Soil Sensor Admin Panel
   Layout of design A (light page + left sidebar) with the colours of design C (teal / sky / soft grey, row cards).
   Mobile first: below 900px the sidebar is an off-canvas drawer. */

:root {
    --brand: #0f766e;
    --brand-dark: #115e59;
    --brand-soft: #ccfbf1;
    --bg: #f6f8fb;
    --card: #ffffff;
    --border: #e5e9f0;
    --text: #1f2933;
    --muted: #52606d;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --ok: #166534;
    --ok-soft: #dcfce7;
    --warn-soft: #fef3c7;
    --tile-sky: #e0f2fe;
    --tile-green: #dcfce7;
    --tile-amber: #fef3c7;
    --tile-pink: #fce7f3;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
    --sidebar-w: 248px;
    --topbar-h: 60px;
    --tap: 44px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Bengali", "Nirmala UI", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0 0 .75em; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }
[v-cloak] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons, forms ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--tap); padding: 0 16px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--card); color: var(--text);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn:focus-visible, .icon-btn:focus-visible, .nav-link:focus-visible, .input:focus-visible { outline: 3px solid rgba(15, 118, 110, .35); outline-offset: 1px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger-soft); border-color: #fecaca; color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

.icon-btn {
    display: inline-grid; place-items: center; width: var(--tap); height: var(--tap);
    border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer;
}

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 14px; }
.input-wrap { position: relative; }
.input {
    width: 100%; min-height: var(--tap); padding: 0 14px;
    border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; color: var(--text); font: inherit;
}
.input-wrap .input { padding-right: 48px; }
.input-wrap .icon-btn { position: absolute; right: 0; top: 0; color: var(--muted); }
.field-error { margin: 6px 0 0; color: var(--danger); font-size: 14px; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 16px; border-radius: 8px; font-size: 14px; }
.alert.error { background: var(--danger-soft); color: #7f1d1d; }
.alert.info { background: var(--tile-sky); color: #075985; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--brand-soft); color: var(--brand); }
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--danger-soft); color: #991b1b; }

.avatar {
    display: inline-grid; place-items: center; flex-shrink: 0;
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 13px;
}

/* ---------- panel shell ---------- */
.shell { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: min(var(--sidebar-w), 86vw);
    display: flex; flex-direction: column;
    padding: 16px 12px;
    background: var(--brand); color: #ecfdf5;
    transform: translateX(-102%);
    transition: transform .22s ease;
    overflow-y: auto;
}
body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }

.backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 42, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
body.nav-open .backdrop { opacity: 1; pointer-events: auto; }
body.nav-open { overflow: hidden; }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 800; font-size: 17px; color: #fff; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); }
.brand small { display: block; font-weight: 500; font-size: 12px; color: #99f6e4; }

.nav-group { margin-top: 14px; }
.nav-group-label { padding: 0 12px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #99f6e4; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    min-height: var(--tap); padding: 0 12px; margin-bottom: 2px;
    border-radius: 8px; color: #ecfdf5; text-decoration: none; font-weight: 600;
}
.nav-link:hover { background: rgba(255, 255, 255, .12); }
.nav-link.on { background: var(--brand-soft); color: var(--brand); }

.sidebar-foot { margin-top: auto; padding-top: 16px; }
.sidebar-foot .nav-link { width: 100%; border: 0; background: transparent; font: inherit; font-weight: 600; cursor: pointer; text-align: left; }

.main-col { min-width: 0; }

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 8px;
    height: var(--topbar-h); padding: 0 12px;
    background: var(--card); border-bottom: 1px solid var(--border);
}
.page-title { flex: 1; min-width: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip { display: flex; align-items: center; gap: 8px; max-width: 50%; padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 14px; }
.user-chip .avatar { width: 32px; height: 32px; background: #fff; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { width: 100%; max-width: 1180px; margin: 0 auto; padding: 12px 8px 24px; }

/* ---------- content blocks ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h2 { font-size: 20px; }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { padding: 14px; border-radius: var(--radius); }
.tile b { display: block; font-size: 26px; line-height: 1.2; }
.tile span { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
a.tile { display: block; color: inherit; text-decoration: none; }
a.tile:hover { box-shadow: var(--shadow); }
.tile small { display: block; margin-top: 2px; font-size: 12px; }
.tile.sky { background: var(--tile-sky); }
.tile.green { background: var(--tile-green); }
.tile.amber { background: var(--tile-amber); }
.tile.pink { background: var(--tile-pink); }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }

.card { padding: 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card h3 { margin-bottom: 12px; font-size: 16px; }

.row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin-bottom: 8px; border-radius: 8px; background: var(--bg);
}
.row-main { flex: 1; min-width: 0; }
.row-title { display: block; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: block; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kv { display: grid; grid-template-columns: 1fr; gap: 2px 16px; margin: 0; }
.kv dt { font-size: 13px; color: var(--muted); }
.kv dd { margin: 0 0 10px; font-weight: 600; word-break: break-word; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- list pages ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .input { flex: 1 1 140px; min-width: 0; }
.toolbar .input.grow { flex: 2 1 220px; }
.toolbar .btn { flex: 0 0 auto; }
.filters-more { width: 100%; }
.filters-more summary { cursor: pointer; color: var(--brand); font-weight: 600; min-height: 32px; }
.filters-more .toolbar { margin: 10px 0 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--tile-sky); color: #075985; font-size: 13px; font-weight: 600; }
.chip a { color: inherit; }

.list { margin: 0 0 12px; padding: 0; list-style: none; }
.row-card {
    display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
    padding: 12px; margin-bottom: 10px;
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.row-card .row-main { flex: 1 1 200px; }
.row-card .row-title { white-space: normal; overflow: visible; }
.row-card .row-sub { white-space: normal; overflow: visible; }
.row-card a.row-title { color: var(--text); text-decoration: none; }
.row-card a.row-title:hover { color: var(--brand); text-decoration: underline; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.row-meta b { color: var(--text); font-weight: 600; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--warn-soft); color: #92400e; font-size: 12px; font-weight: 700; }
.badge.warn { background: var(--warn-soft); color: #92400e; }

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.pager-btns { display: flex; align-items: center; gap: 8px; }
.pager-size { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pager-size .input { width: 84px; min-height: 36px; }
.pager-info, .pager-page { font-size: 13px; color: var(--muted); }

.state { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 28px 12px; color: var(--muted); text-align: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- forms ---------- */
.field-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.field .req { color: var(--danger); }
.help { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
textarea.input { padding: 10px 14px; min-height: 80px; resize: vertical; }
select.input { padding-right: 10px; }
.form-card { max-width: 760px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.section-title { margin: 18px 0 10px; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.radio-row { display: flex; flex-wrap: wrap; gap: 10px; }
.radio-row label { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 14px; border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; cursor: pointer; font-weight: 600; }
.radio-row input:checked + span { color: var(--brand); }

/* ---------- modal, toast ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 12px; background: rgba(15, 23, 42, .5); overflow-y: auto; }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 24px); overflow-y: auto; background: var(--card); border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 8px 8px 18px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.modal-head h3 { font-size: 17px; }
.modal-head .icon-btn { font-size: 26px; line-height: 1; }
.modal-body { padding: 16px 18px 18px; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 8px; }
body.modal-open { overflow: hidden; }

.toasts { position: fixed; left: 12px; right: 12px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { max-width: 520px; padding: 12px 16px; border-radius: 10px; color: #fff; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); pointer-events: auto; }
.toast.ok { background: var(--brand-dark); }
.toast.error { background: var(--danger); }

/* ---------- tabs, details ---------- */
.tabs { display: flex; gap: 6px; margin: 0 0 14px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { min-height: var(--tap); padding: 0 16px; border: 0; border-bottom: 3px solid transparent; background: transparent; font: inherit; font-weight: 700; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); }
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-head .avatar { width: 52px; height: 52px; font-size: 18px; }
.detail-head h2 { font-size: 20px; }
.detail-head .row-actions { margin-left: 0; }
.back-link { display: inline-flex; align-items: center; min-height: 36px; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.stack > * + * { margin-top: 16px; }
.num-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.num-grid .cell { padding: 10px 12px; border-radius: 8px; background: var(--bg); }
.num-grid .cell span { display: block; font-size: 12px; color: var(--muted); }
.num-grid .cell b { font-size: 18px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--bg); white-space: nowrap; }
.table td.new { color: var(--ok); font-weight: 600; }
.table td.old { color: var(--danger); text-decoration: line-through; text-decoration-color: rgba(185, 28, 28, .45); }

.history-item { padding: 12px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.history-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-bottom: 8px; font-size: 14px; }
.history-head .time { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---------- dashboard ---------- */
.bars { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; align-items: end; height: 170px; padding-top: 8px; }
.bar { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 4px; font-size: 12px; color: var(--muted); }
.bar i { display: block; width: 100%; max-width: 44px; min-height: 3px; border-radius: 6px 6px 0 0; background: var(--brand); }
.bar b { color: var(--text); font-size: 13px; }
.quick-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick-links a { display: flex; align-items: center; gap: 10px; min-height: var(--tap); padding: 8px 12px; border-radius: 8px; background: var(--bg); color: var(--text); text-decoration: none; font-weight: 600; }
.quick-links a:hover { background: var(--brand-soft); }

.alert[hidden], [hidden] { display: none !important; }

/* ---------- login / error pages ---------- */
.auth-body {
    min-height: 100vh; display: grid; place-items: center; padding: 16px;
    background: linear-gradient(135deg, var(--brand-soft), var(--tile-sky));
}
.auth-card {
    width: 100%; max-width: 400px; padding: 28px 24px;
    background: var(--card); border-radius: 14px; box-shadow: 0 10px 30px rgba(15, 118, 110, .18);
}
.auth-logo { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; background: var(--brand-soft); color: var(--brand); }
.auth-card h1 { margin-bottom: 4px; text-align: center; font-size: 22px; }
.auth-card .sub { margin-bottom: 20px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-card .big-code { margin-bottom: 4px; text-align: center; font-size: 48px; font-weight: 800; color: var(--brand); }
.auth-card .center { text-align: center; }

/* ---------- tablet and up ---------- */
@media (min-width: 600px) {
    .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kv { grid-template-columns: 160px 1fr; }
    .kv dd { margin-bottom: 8px; }
    .content { padding: 16px 12px 32px; }
    .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .field-grid .field { grid-column: span 2; }
    .field-grid .field.half { grid-column: span 1; }
    .num-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .quick-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- desktop: fixed sidebar ---------- */
@media (min-width: 900px) {
    .sidebar { transform: none; width: var(--sidebar-w); box-shadow: none; }
    .backdrop { display: none; }
    body.nav-open { overflow: auto; }
    .main-col { margin-left: var(--sidebar-w); }
    .menu-btn { display: none; }
    .topbar { padding: 0 24px; }
    .page-title { font-size: 20px; }
    .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
    .grid-2 { grid-template-columns: 1.55fr 1fr; }
    .content { padding: 16px 14px 32px; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .backdrop { transition: none; }
}
