/*
 * Sidhyati Soil Testing - application shell.
 *
 * Deliberately restrained: one accent colour, flat surfaces, hairline borders and a single
 * shadow depth. Field agents read this on a phone in daylight, so contrast and tap targets
 * matter more than decoration.
 */

:root {
    --ink: #111827;
    --ink-soft: #374151;
    --muted: #6b7280;
    --muted-soft: #9ca3af;

    --surface: #ffffff;
    --surface-sunken: #f7f8fa;
    --surface-raised: #ffffff;

    --line: #e5e7eb;
    --line-strong: #d1d5db;

    --accent: #12604a;
    --accent-hover: #0e4d3b;
    --accent-soft: #e8f1ee;
    --accent-line: #b9d4cb;

    --sidebar-bg: #16232e;
    --sidebar-fg: #aab6c2;
    --sidebar-fg-active: #ffffff;
    --sidebar-hover: #1e2f3d;
    --sidebar-line: #263846;

    --ok: #15803d;
    --ok-soft: #e8f5ee;
    --warn: #b45309;
    --warn-soft: #fdf3e3;
    --danger: #b42318;
    --danger-soft: #fdeceb;
    --info: #1d4ed8;
    --info-soft: #eaeffd;

    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-lg: 0 8px 24px rgba(16, 24, 40, .10);

    --sidebar-width: 244px;
    --topbar-height: 58px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--surface-sunken);
    color: var(--ink);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/*
 * Inline SVG icons have no intrinsic size, so without this they stretch to fill whatever box
 * they are dropped into. Sizing them once here means an icon can be used anywhere safely.
 */
.icon,
.btn > svg,
.nav-link > svg,
.sidebar-toggle > svg,
.th-sort > svg,
.dropdown-item > svg {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
}

.btn-lg > svg { width: 18px; height: 18px; flex-basis: 18px; }
.btn-sm > svg { width: 14px; height: 14px; flex-basis: 14px; }

h1, h2, h3, h4, h5 { color: var(--ink); font-weight: 600; margin: 0; }

/* ----------------------------------------------------------------- shell */

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

.app-sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    transition: transform .18s ease;
}

.app-brand {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 18px;
    border-bottom: 1px solid var(--sidebar-line);
    color: #fff;
    font-weight: 600;
    letter-spacing: -.01em;
}

.app-brand:hover { color: #fff; text-decoration: none; }

.app-brand .brand-mark {
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: var(--radius);
    background: var(--accent);
    color: #fff;
    font-size: 13px; font-weight: 700;
    flex: 0 0 26px;
}

.app-brand .brand-text { font-size: 14px; }
.app-brand .brand-text small { display: block; font-size: 10.5px; color: var(--sidebar-fg); font-weight: 500; }

.app-nav { flex: 1; overflow-y: auto; padding: 14px 10px 24px; }

.app-nav .nav-section {
    padding: 14px 10px 6px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: #64748b;
}

.app-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 1px;
    border-radius: var(--radius);
    color: var(--sidebar-fg);
    font-size: 13.5px;
    font-weight: 500;
}

.app-nav .nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }

.app-nav .nav-link.active { background: var(--accent); color: var(--sidebar-fg-active); }

.app-nav .nav-link svg { opacity: .9; }

.app-nav .nav-link .nav-badge {
    margin-left: auto;
    font-size: 11px;
    background: rgba(255, 255, 255, .12);
    padding: 1px 6px;
    border-radius: 10px;
}

.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 22px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.app-topbar .topbar-title { font-size: 15px; font-weight: 600; }
.app-topbar .topbar-sub { font-size: 12px; color: var(--muted); }

.app-content { padding: 22px; flex: 1; }
.app-content > .container-fluid { padding: 0; max-width: 1560px; }

.sidebar-toggle {
    display: none;
    background: none; border: 1px solid var(--line);
    border-radius: var(--radius);
    width: 34px; height: 34px;
    align-items: center; justify-content: center;
    color: var(--ink-soft); cursor: pointer;
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(17, 24, 39, .45);
    z-index: 1035;
}

/* ------------------------------------------------------------- user chip */

.user-chip {
    display: flex; align-items: center; gap: 9px;
    background: none; border: 0; padding: 4px 6px;
    border-radius: var(--radius); cursor: pointer;
}

.user-chip:hover { background: var(--surface-sunken); }

.avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: grid; place-items: center;
    font-size: 11.5px; font-weight: 700;
    flex: 0 0 30px;
}

.avatar.avatar-lg { width: 40px; height: 40px; font-size: 14px; flex-basis: 40px; }

.user-chip .user-meta { text-align: left; line-height: 1.25; }
.user-chip .user-meta strong { display: block; font-size: 13px; font-weight: 600; color: var(--ink); }
.user-chip .user-meta span { font-size: 11px; color: var(--muted); }

/* ----------------------------------------------------------- page header */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.page-head h1 { font-size: 20px; letter-spacing: -.015em; }
.page-head .page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-head .page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.breadcrumb-trail { font-size: 12px; color: var(--muted-soft); margin-bottom: 4px; }
.breadcrumb-trail a { color: var(--muted); }

/* ----------------------------------------------------------------- cards */

.card {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--line);
    padding: 13px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h2, .card-header h3 { font-size: 14px; font-weight: 600; }
.card-header .card-sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.card-body { padding: 16px; }
.card-footer { background: transparent; border-top: 1px solid var(--line); padding: 11px 16px; }

/* ------------------------------------------------------------ stat tiles */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-tile {
    background: var(--surface-raised);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 15px 16px;
    box-shadow: var(--shadow);
}

.stat-tile .stat-label {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted);
}

.stat-tile .stat-value {
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -.02em;
    margin-top: 6px;
    line-height: 1.1;
}

.stat-tile .stat-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.stat-tile .stat-foot { font-size: 12px; color: var(--muted); margin-top: 5px; }
.stat-tile .stat-foot .up { color: var(--ok); font-weight: 600; }
.stat-tile .stat-foot .down { color: var(--danger); font-weight: 600; }

.stat-tile.accent { border-left: 3px solid var(--accent); }

/* ---------------------------------------------------------------- tables */

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

.table { margin: 0; font-size: 13.5px; color: var(--ink-soft); }

.table > thead > tr > th {
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding: 9px 14px;
    white-space: nowrap;
    vertical-align: middle;
}

.table > tbody > tr > td {
    border-bottom: 1px solid var(--line);
    padding: 11px 14px;
    vertical-align: middle;
}

.table > tbody > tr:last-child > td { border-bottom: 0; }
.table > tbody > tr:hover { background: var(--surface-sunken); }

.table .row-primary { font-weight: 600; color: var(--ink); }
.table .row-secondary { font-size: 12px; color: var(--muted); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }

/* Sortable column headers carry their direction in the link itself. */
.th-sort { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.th-sort:hover { color: var(--ink); text-decoration: none; }
.th-sort .sort-mark { opacity: .35; font-size: 9px; }
.th-sort.is-sorted { color: var(--accent); }
.th-sort.is-sorted .sort-mark { opacity: 1; }

.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty-state .empty-icon { font-size: 26px; opacity: .35; margin-bottom: 8px; }
.empty-state h3 { font-size: 15px; margin-bottom: 4px; }
.empty-state p { font-size: 13px; margin: 0 auto; max-width: 380px; }

/* --------------------------------------------------------------- filters */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.filter-bar .filter-field { display: flex; flex-direction: column; gap: 4px; }
.filter-bar .filter-field label { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.filter-bar .filter-field.grow { flex: 1 1 220px; min-width: 180px; }
.filter-bar .filter-actions { display: flex; gap: 8px; margin-left: auto; }

.result-count { font-size: 12.5px; color: var(--muted); }

/* ---------------------------------------------------------------- inputs */

.form-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 4px; }

.form-control, .form-select {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    font-size: 13.5px;
    padding: 7px 11px;
    color: var(--ink);
    background-color: #fff;
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-control::placeholder { color: var(--muted-soft); }
.form-control[readonly] { background: var(--surface-sunken); }
.form-text { font-size: 11.5px; color: var(--muted); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-label { font-size: 13.5px; }

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

.form-section {
    border-top: 1px solid var(--line);
    margin-top: 6px;
    padding-top: 16px;
}

.form-section:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }

.form-section-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.form-section-sub { font-size: 12px; color: var(--muted); margin-bottom: 14px; }

.text-danger, .validation-message, .field-validation-error { color: var(--danger) !important; font-size: 12px; }
.input-validation-error { border-color: var(--danger) !important; }

/* --------------------------------------------------------------- buttons */

.btn {
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    padding: 7px 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid transparent;
}

.btn:focus-visible { box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-outline-secondary {
    background: #fff;
    border-color: var(--line-strong);
    color: var(--ink-soft);
}

.btn-outline-secondary:hover { background: var(--surface-sunken); border-color: var(--line-strong); color: var(--ink); }

.btn-link { color: var(--accent); padding: 0; font-weight: 500; }
.btn-sm { font-size: 12.5px; padding: 5px 10px; }
.btn-lg { font-size: 15px; padding: 11px 20px; }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-icon { padding: 5px 8px; }

/* ---------------------------------------------------------------- badges */

.badge-soft {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    white-space: nowrap;
}

.badge-soft::before {
    content: "";
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
}

.badge-soft.is-ok { background: var(--ok-soft); color: var(--ok); }
.badge-soft.is-warn { background: var(--warn-soft); color: var(--warn); }
.badge-soft.is-danger { background: var(--danger-soft); color: var(--danger); }
.badge-soft.is-info { background: var(--info-soft); color: var(--info); }
.badge-soft.is-muted { background: #f1f3f5; color: var(--muted); }
.badge-soft.no-dot::before { display: none; }

/* ------------------------------------------------------------- key/value */

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 9px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); }

@media (max-width: 575px) {
    .kv { grid-template-columns: 1fr; gap: 2px 0; }
    .kv dd { margin-bottom: 9px; }
}

/* -------------------------------------------------------- reading meters */

.reading-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(205px, 1fr));
    gap: 12px;
}

.reading-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 13px 14px;
    background: var(--surface);
}

.reading-card .reading-name { font-size: 12px; color: var(--muted); font-weight: 600; }

.reading-card .reading-value {
    font-size: 23px;
    font-weight: 600;
    letter-spacing: -.02em;
    margin: 4px 0 2px;
    font-variant-numeric: tabular-nums;
}

.reading-card .reading-value .unit { font-size: 12.5px; font-weight: 500; color: var(--muted); margin-left: 3px; }

.reading-meter {
    height: 4px;
    border-radius: 3px;
    background: var(--line);
    margin: 9px 0 7px;
    position: relative;
    overflow: hidden;
}

.reading-meter > span {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    border-radius: 3px;
}

.reading-meter > span.is-ok { background: var(--ok); }
.reading-meter > span.is-warn { background: var(--warn); }
.reading-meter > span.is-danger { background: var(--danger); }
.reading-meter > span.is-muted { background: var(--muted-soft); }

.reading-card .reading-range { font-size: 11px; color: var(--muted-soft); }
.reading-card .reading-advice { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.45; }
.reading-card.is-advisory { border-style: dashed; }

/* --------------------------------------------------------------- alerts */

.alert { border-radius: var(--radius); border: 1px solid transparent; font-size: 13.5px; padding: 11px 14px; }
.alert-success { background: var(--ok-soft); border-color: #bfe3cd; color: #14532d; }
.alert-danger { background: var(--danger-soft); border-color: #f4c7c3; color: #7f1d1d; }
.alert-warning { background: var(--warn-soft); border-color: #f2ddb5; color: #78350f; }
.alert-info { background: var(--info-soft); border-color: #c7d5f8; color: #1e3a8a; }

.alert h4 { font-size: 13.5px; margin-bottom: 3px; }
.alert p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ sparkline */

.sparkline { display: flex; align-items: flex-end; gap: 3px; height: 56px; }

.sparkline .bar {
    flex: 1;
    background: var(--accent-soft);
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    position: relative;
}

.sparkline .bar.has-value { background: var(--accent); }
.sparkline-axis { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted-soft); margin-top: 6px; }

/* --------------------------------------------------------------- wizard */

.step-list { display: flex; gap: 0; margin-bottom: 20px; flex-wrap: wrap; }

.step-list .step {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 16px 9px 0;
    color: var(--muted);
    font-size: 13px;
}

.step-list .step .step-num {
    width: 23px; height: 23px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    display: grid; place-items: center;
    font-size: 11.5px; font-weight: 600;
    background: #fff;
    flex: 0 0 23px;
}

.step-list .step.is-active { color: var(--ink); font-weight: 600; }
.step-list .step.is-active .step-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.step-list .step.is-done .step-num { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.step-list .step .step-rule { width: 26px; height: 1px; background: var(--line-strong); margin-left: 8px; }
.step-list .step:last-child .step-rule { display: none; }

/* ----------------------------------------------------------- auth screen */

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface);
}

.auth-aside {
    background: var(--sidebar-bg);
    color: #cbd5e1;
    padding: 46px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.auth-aside h2 { color: #fff; font-size: 25px; letter-spacing: -.02em; line-height: 1.3; }
.auth-aside p { font-size: 14px; max-width: 420px; margin-top: 14px; line-height: 1.6; }

.auth-aside .auth-points { margin-top: 30px; display: grid; gap: 13px; }
.auth-aside .auth-point { display: flex; gap: 11px; font-size: 13.5px; align-items: flex-start; }
.auth-aside .auth-point .tick { color: #34d399; flex: 0 0 auto; margin-top: 1px; }
.auth-aside .auth-foot { font-size: 12px; color: #64748b; }

.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-form { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 21px; letter-spacing: -.015em; }
.auth-form .auth-sub { color: var(--muted); font-size: 13.5px; margin: 5px 0 26px; }

@media (max-width: 900px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
}

/* ------------------------------------------------------------ pagination */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.pagination { margin: 0; }

.page-link {
    color: var(--ink-soft);
    border-color: var(--line);
    font-size: 13px;
    padding: 5px 11px;
}

.page-link:hover { background: var(--surface-sunken); color: var(--ink); }
.page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.page-item.disabled .page-link { color: var(--muted-soft); background: #fff; }

/* -------------------------------------------------------------- dropdown */

.dropdown-menu {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    padding: 5px;
}

.dropdown-item { border-radius: var(--radius); padding: 7px 10px; }
.dropdown-item:hover { background: var(--surface-sunken); }
.dropdown-header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dropdown-divider { border-color: var(--line); margin: 5px 0; }

/* ---------------------------------------------------------------- modals */

.modal-content { border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal-header { border-bottom: 1px solid var(--line); padding: 15px 18px; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px; font-size: 13.5px; }
.modal-footer { border-top: 1px solid var(--line); padding: 12px 18px; }

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

@media (max-width: 991px) {
    .app-sidebar { transform: translateX(-100%); }
    .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
    .app-shell.sidebar-open .sidebar-backdrop { display: block; }
    .app-main { margin-left: 0; }
    .sidebar-toggle { display: inline-flex; }
    .app-content { padding: 16px; }
    .app-topbar { padding: 0 16px; }
}

@media (max-width: 575px) {
    .page-head { flex-direction: column; align-items: stretch; }
    .page-head .page-actions { width: 100%; }
    .page-head .page-actions .btn { flex: 1; justify-content: center; }
    .filter-bar .filter-actions { margin-left: 0; width: 100%; }
    .filter-bar .filter-actions .btn { flex: 1; justify-content: center; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
    .stat-tile .stat-value { font-size: 22px; }
}

/* Tables that must stay readable on a phone collapse to stacked rows. */
@media (max-width: 767px) {
    .table-stack > thead { display: none; }
    .table-stack > tbody > tr {
        display: block;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 6px 2px;
    }
    .table-stack > tbody > tr > td {
        display: flex;
        justify-content: space-between;
        gap: 14px;
        border: 0;
        padding: 6px 12px;
        text-align: right;
    }
    .table-stack > tbody > tr > td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11.5px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: .04em;
        text-align: left;
        flex: 0 0 auto;
    }
    .table-stack > tbody > tr > td.actions { justify-content: flex-end; }
    .table-stack > tbody > tr > td.actions::before { margin-right: auto; }
}

@media print {
    .app-sidebar, .app-topbar, .page-actions, .filter-bar, .pager, .no-print { display: none !important; }
    .app-main { margin-left: 0; }
    .app-content { padding: 0; }
    .card { border: 0; box-shadow: none; }
    body { background: #fff; }
}
