/* ============================================================
   FarmAssets — iControl design language
   Dark navy sidebar · teal accent · clean light tables.
   Self-contained (no external fonts). Overrides Bootstrap.
   ============================================================ */

:root {
    --bg:           #f5f8fa;
    --surface:      #ffffff;
    --border:       #e6ecf1;
    --border-2:     #d6dee6;

    --accent:       #13bdc4;   /* teal */
    --accent-dk:    #0fa3a9;
    --accent-ink:   #0b7e83;
    --accent-soft:  #e2f6f7;

    --navy:         #0f1c2e;   /* dark sidebar */
    --navy-2:       #18283d;   /* sidebar hover */
    --navy-line:    #283a52;
    --side-text:    #9fb0c3;
    --side-dim:     #6f8198;

    --ink:          #1f2a37;
    --text:         #3a4654;
    --muted:        #7b8794;

    --amber:        #b8791b;  --amber-soft: #fbf0db;
    --red:          #d64545;  --red-soft:   #fbe8e8;

    --radius:       10px;
    --radius-sm:    8px;
    --shadow:       0 1px 3px rgba(16,30,50,.06), 0 1px 2px rgba(16,30,50,.04);
    --shadow-hover: 0 6px 18px rgba(16,30,50,.10);
}

html { font-size: 15px; position: relative; min-height: 100%; }
@media (min-width: 768px) { html { font-size: 16px; } }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { color: var(--ink); font-weight: 650; letter-spacing: -0.01em; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { color: var(--accent-dk); }

/* ---- Top bar ---------------------------------------------- */
.topbar {
    display: flex; align-items: center; gap: .75rem;
    height: 56px; padding: 0 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1050;
}
.topbar .brand { display: flex; align-items: center; gap: .5rem; font-weight: 750; color: var(--ink); font-size: 1.05rem; letter-spacing: -0.02em; }
.topbar .brand:hover { color: var(--ink); }
.brand-mark { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent); font-size: 1rem; }
.brand-badge { font-size: .62rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--border-2); border-radius: 6px; padding: .25rem .5rem; }
.topsearch { flex: 1 1 auto; max-width: 520px; margin: 0 auto; }
.topsearch input { width: 100%; border: 1px solid var(--border-2); border-radius: 8px; padding: .45rem .8rem; background: #fafcfd; font-size: .9rem; }
.topsearch input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 .18rem var(--accent-soft); background: #fff; }
.user-chip { display: flex; align-items: center; gap: .55rem; margin-left: auto; }
.user-chip .avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; font-size: .8rem; }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.1; }
.user-chip .who strong { font-size: .85rem; color: var(--ink); }
.user-chip .who small { font-size: .72rem; color: var(--muted); }

.canvas-toggle { border: 0; background: transparent; color: var(--ink); font-size: 1.2rem; line-height: 1; padding: .15rem .5rem; cursor: pointer; border-radius: var(--radius-sm); }
.canvas-toggle:hover { background: var(--bg); }

/* ---- App shell: dark sidebar + main pane ------------------ */
.app-shell { display: flex; align-items: stretch; }
.main-pane { flex: 1 1 auto; min-width: 0; padding: 1.5rem 1.5rem 3rem; }

.side-nav {
    flex: 0 0 252px; width: 252px;
    background: var(--navy); color: var(--side-text);
    min-height: calc(100vh - 56px);
    padding: .5rem .6rem 1.25rem;
    overflow-y: auto;
    transition: flex-basis .22s ease, width .22s ease, padding .22s ease;
}
.canvas-off .side-nav { flex-basis: 0; width: 0; padding-left: 0; padding-right: 0; overflow: hidden; }

.side-label { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; color: var(--side-dim); padding: 1rem .85rem .4rem; font-weight: 700; }
.side-link { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .85rem; border-radius: var(--radius-sm); color: var(--side-text); font-weight: 600; border-left: 3px solid transparent; white-space: nowrap; }
.side-link:hover { background: var(--navy-2); color: #fff; }
.side-link.active { background: var(--navy-2); color: #fff; border-left-color: var(--accent); }
.side-divider { height: 1px; background: var(--navy-line); margin: .7rem .6rem; }
.side-add { display: block; margin: .8rem .4rem 0; text-align: center; }

.canvas-backdrop { display: none; }

/* asset tree inside the dark sidebar */
.canvas-head { display: flex; align-items: center; justify-content: space-between; padding: 0 .5rem .35rem; }
.canvas-title { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--side-dim); }
.canvas-add { color: var(--accent); font-weight: 700; font-size: 1.15rem; line-height: 1; padding: 0 .4rem; border-radius: 6px; }
.canvas-add:hover { background: var(--navy-2); color: var(--accent); }
.canvas-item { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding: .4rem .55rem; margin-bottom: .1rem; border-radius: var(--radius-sm); color: var(--side-text); white-space: nowrap; }
.canvas-item:hover { background: var(--navy-2); color: #fff; }
.canvas-item.active { background: var(--accent); color: #05282a; }
.canvas-item .ci-name { overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.canvas-item .ci-twig { color: var(--navy-line); margin-right: .15rem; }
.canvas-item.active .ci-twig { color: rgba(0,0,0,.35); }
.ci-count { background: rgba(255,255,255,.08); color: var(--side-text); font-size: .7rem; font-weight: 700; border-radius: 999px; padding: .05rem .45rem; flex: 0 0 auto; }
.canvas-item.active .ci-count { background: rgba(0,0,0,.18); color: #05282a; }
.canvas-all { font-weight: 600; margin-bottom: .35rem; }

/* mobile: sidebar becomes an overlay drawer */
@media (max-width: 768px) {
    .side-nav { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 1045; flex-basis: 252px; width: 252px; min-height: 0; box-shadow: var(--shadow-hover); transform: translateX(0); transition: transform .22s ease; }
    .canvas-off .side-nav { transform: translateX(-100%); width: 252px; flex-basis: 252px; padding: .5rem .6rem 1.25rem; }
    .canvas-backdrop { position: fixed; inset: 56px 0 0 0; background: rgba(8,16,28,.5); z-index: 1040; }
    html:not(.canvas-off) .canvas-backdrop { display: block; }
    .main-pane { padding: 1.1rem 1rem 2.5rem; }
    .topsearch { display: none; }
}

/* ---- Buttons ---------------------------------------------- */
.btn { border-radius: var(--radius-sm); font-weight: 600; }
.btn-success, .btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-success:hover, .btn-success:focus, .btn-accent:hover { background: var(--accent-dk); border-color: var(--accent-dk); color: #fff; }
.btn-outline-success { color: var(--accent-ink); border-color: var(--border-2); background: var(--surface); }
.btn-outline-success:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-outline-secondary { color: var(--text); border-color: var(--border-2); background: var(--surface); }
.btn-outline-secondary:hover { background: var(--bg); color: var(--ink); border-color: var(--border-2); }
.btn-light { background: var(--accent); color: #fff; border: 0; }
.btn-light:hover { background: var(--accent-dk); color: #fff; }
.btn-link { color: var(--muted); text-decoration: none; }
.btn:focus, .btn:active:focus, .form-control:focus, .form-select:focus { box-shadow: 0 0 0 .18rem var(--accent-soft); }

/* ---- Cards / task rows ------------------------------------ */
.card, .task-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); transition: box-shadow .15s ease; }
.task-card:hover { box-shadow: var(--shadow-hover); }
.task-card .task-title { font-weight: 650; color: var(--ink); }
.task-card .task-meta { color: var(--muted); font-size: .82rem; }
.task-card.is-doing { border-left: 3px solid var(--amber); }
.task-card.is-overdue { border-left: 3px solid var(--red); }

/* ---- Badges ----------------------------------------------- */
.badge { font-weight: 600; border-radius: 999px; padding: .3em .7em; }
.badge.bg-secondary { background: #eef2f6 !important; color: var(--muted) !important; }
.badge.bg-primary   { background: var(--accent-soft) !important; color: var(--accent-ink) !important; }
.badge.bg-info      { background: var(--accent-soft) !important; color: var(--accent-ink) !important; }
.badge.bg-warning   { background: var(--amber-soft) !important; color: var(--amber) !important; }
.badge.bg-success   { background: var(--accent-soft) !important; color: var(--accent-ink) !important; }
.badge.bg-dark      { background: #e7eaee !important; color: #55616e !important; }

/* ---- Bucket headings (Board) ------------------------------ */
.bucket-title { display: flex; align-items: center; gap: .5rem; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .75rem; }
.bucket-title .dot { width: .55rem; height: .55rem; border-radius: 999px; background: var(--border-2); }
.bucket-title.overdue .dot { background: var(--red); }
.bucket-title.today .dot   { background: var(--accent); }
.bucket-title.week .dot    { background: var(--amber); }
.bucket-title .count { background: #eef2f6; color: var(--muted); border-radius: 999px; padding: 0 .5rem; font-size: .72rem; }

/* ---- Asset tree on the Assets page ------------------------ */
.list-group-item { border-color: var(--border); }
.list-group-item-action:hover { background: var(--accent-soft); }
.tree-row { display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: .4rem; color: var(--text); transition: box-shadow .15s ease, border-color .15s ease; }
.tree-row:hover { box-shadow: var(--shadow); border-color: var(--border-2); }
.tree-link { display: flex; align-items: center; flex: 1 1 auto; min-width: 0; text-decoration: none; color: var(--text); }
.tree-link:hover { color: var(--ink); }
.tree-counts { display: flex; align-items: center; gap: .35rem; flex: 0 0 auto; }
.tree-row .twig { color: var(--border-2); font-family: monospace; white-space: pre; }
.tree-name { font-weight: 600; color: var(--ink); }
.drag-handle { cursor: grab; color: var(--border-2); font-size: 1rem; line-height: 1; padding: 0 .1rem; flex: 0 0 auto; user-select: none; }
.drag-handle:hover { color: var(--muted); }
.drag-handle:active { cursor: grabbing; }
.drag-handle-inline { color: var(--border-2); }
.tree-row.dragging { opacity: .45; }
.tree-row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.tree-row.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.type-chip { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #eef2f6; border-radius: 999px; padding: .12rem .55rem; margin-left: .35rem; }

/* ---- Breadcrumb ------------------------------------------- */
.farm-crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .25rem; }
.farm-crumbs a { color: var(--muted); }
.farm-crumbs a:hover { color: var(--accent-ink); }

/* ---- Forms ------------------------------------------------ */
.form-control, .form-select { border-color: var(--border-2); border-radius: var(--radius-sm); }
.form-label { font-weight: 600; color: var(--text); font-size: .9rem; }

/* ---- Sub-tabs (Tasks / History) --------------------------- */
.farm-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; }
.farm-tabs a { padding: .5rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.farm-tabs a:hover { color: var(--ink); }
.farm-tabs a.active { color: var(--accent-ink); border-bottom-color: var(--accent); }

/* ---- Filter bar ------------------------------------------- */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1.25rem; align-items: center; }
.filter-bar .search { flex: 1 1 220px; min-width: 180px; }

/* ---- Tables ----------------------------------------------- */
.farm-table { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); border-collapse: separate; border-spacing: 0; }
.farm-table th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: .7rem .9rem; background: #fafcfd; border-bottom: 1px solid var(--border); }
.farm-table td { padding: .7rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.farm-table tr:last-child td { border-bottom: 0; }
.farm-table tbody tr:hover { background: var(--accent-soft); }
.farm-table .t-title { font-weight: 600; color: var(--ink); }
.table-wrap { overflow-x: auto; }

.pill { font-size: .72rem; font-weight: 600; border-radius: 999px; padding: .15rem .6rem; white-space: nowrap; }
.pill.todo  { background: #eef2f6; color: var(--muted); }
.pill.doing { background: var(--amber-soft); color: var(--amber); }
.pill.done  { background: var(--accent-soft); color: var(--accent-ink); }
.pill.over  { background: var(--red-soft); color: var(--red); }

/* ---- Tile explorer ---------------------------------------- */
/* Equal-height grid (not masonry) so a tile with extra badges/stats stays aligned. */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: 1rem; align-items: stretch; }
.tile {
    display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden;
    transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
.tile:hover { box-shadow: var(--shadow-hover); border-color: var(--accent); transform: translateY(-2px); }

/* Primary (drill / open) area — grows to fill so footers line up across the row. */
.tile-main { display: flex; flex-direction: column; flex: 1 1 auto; padding: 1rem; color: var(--text); }
.tile-main:hover { color: var(--text); }
.tile-top { display: flex; gap: .75rem; align-items: flex-start; }
.tile-head { min-width: 0; }
.tile-icon { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 1.45rem; }
.ic-structure { background: var(--accent-soft); }
.ic-land      { background: #e6f4ea; }
.ic-boundary  { background: var(--amber-soft); }
.ic-equipment { background: #eef2f6; }
.tile-name { font-weight: 700; color: var(--ink); font-size: 1.02rem; line-height: 1.2; }
.tile-sub { margin-top: .3rem; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.tile-stats { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; min-height: 1.5rem; }
.stat { font-size: .74rem; font-weight: 600; border-radius: 999px; padding: .2rem .6rem; }
.stat-open  { background: var(--accent-soft); color: var(--accent-ink); }
.stat-over  { background: var(--red-soft); color: var(--red); }
.stat-clear { background: #eef2f6; color: var(--muted); }
.tile-hint { margin-top: auto; padding-top: .85rem; color: var(--muted); font-size: .82rem; font-weight: 600; }

/* Secondary action: filter the board to this branch. Pinned to the bottom of every tile. */
.tile-board { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .6rem 1rem; border-top: 1px solid var(--border); background: #fbfdfe; color: var(--accent-ink); font-weight: 600; font-size: .82rem; }
.tile-board:hover { background: var(--accent-soft); color: var(--accent-dk); }

.tile-current { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem; margin-bottom: 1.25rem; }
.tile-current .tile-icon { width: 52px; height: 52px; font-size: 1.6rem; }

/* ---- Day plan (drag & drop) ------------------------------- */
.plan-board { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 768px) { .plan-board { grid-template-columns: 1fr; } }
.plan-lane { background: #fbfcfd; border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; margin-bottom: 1rem; }
.plan-lane.backlog { background: var(--surface); }
.plan-lane-head { display: flex; align-items: center; gap: .5rem; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: .7rem; }
.plan-lane-head .dot { width: .55rem; height: .55rem; border-radius: 999px; background: var(--border-2); }
.plan-lane-head .dot.today { background: var(--accent); }
.plan-lane-head .dot.next { background: var(--amber); }
.plan-lane-head .lane-count { background: #eef2f6; color: var(--muted); border-radius: 999px; padding: 0 .5rem; font-size: .72rem; }
.lane-drop { min-height: 56px; display: flex; flex-direction: column; gap: .5rem; border-radius: var(--radius-sm); }
.lane-drop.drop-hover { outline: 2px dashed var(--accent); outline-offset: 3px; background: var(--accent-soft); }
.lane-empty { color: var(--muted); font-size: .82rem; margin: .35rem .25rem; }

.plan-card {
    display: flex; justify-content: space-between; align-items: flex-start; gap: .6rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow); padding: .55rem .7rem; cursor: grab;
}
.plan-card:active { cursor: grabbing; }
.plan-card.dragging { opacity: .45; }
.pc-main { min-width: 0; }
.pc-title { font-weight: 650; color: var(--ink); }
.pc-meta { color: var(--muted); font-size: .8rem; margin-top: .1rem; }
.pc-actions { display: flex; align-items: center; gap: .3rem; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.lane-seg { display: inline-flex; border: 1px solid var(--border-2); border-radius: 999px; overflow: hidden; }
.lane-seg form { margin: 0; }
.seg { border: 0; background: var(--surface); color: var(--muted); font-size: .7rem; font-weight: 600; padding: .22rem .55rem; cursor: pointer; }
.seg:hover { background: var(--bg); color: var(--ink); }
.seg.active { background: var(--accent); color: #fff; }

/* ---- Auth pages ------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-hover); padding: 1.75rem; }
.auth-brand { display: flex; align-items: center; gap: .5rem; font-weight: 750; color: var(--ink); font-size: 1.1rem; margin-bottom: 1.25rem; }
.auth-title { font-size: 1.4rem; margin-bottom: .15rem; }
.auth-sub { color: var(--muted); font-size: .9rem; margin-bottom: 1.25rem; }
.auth-alt { margin-top: 1.1rem; margin-bottom: 0; font-size: .88rem; color: var(--muted); text-align: center; }

/* ---- Owner chips / assignment ----------------------------- */
.owner-chip { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 600; color: var(--text); }
.oc-av { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: .66rem; font-weight: 700; flex: 0 0 auto; }
.av-0 { background: #13bdc4; } .av-1 { background: #3b82c4; } .av-2 { background: #8b5cd6; }
.av-3 { background: #c47d1b; } .av-4 { background: #2fa363; } .av-5 { background: #d35a7e; }
.owner-chip.unassigned { color: var(--amber); }
.oc-av.oc-none { background: transparent; color: var(--amber); border: 1.5px dashed var(--amber); }

.assignee { display: inline-flex; align-items: center; gap: .3rem; flex-wrap: wrap; }
.chip-btn { border: 0; background: transparent; padding: .05rem .2rem; border-radius: 999px; cursor: pointer; }
.chip-btn:hover { background: var(--bg); }
.assign-picker { display: inline-flex; align-items: center; gap: .25rem; }
.btn-grab { border: 0; background: var(--accent); color: #fff; font-size: .72rem; font-weight: 700; border-radius: 999px; padding: .12rem .6rem; cursor: pointer; margin-left: .25rem; }
.btn-grab:hover { background: var(--accent-dk); }
.assign-form { display: inline-flex; align-items: center; gap: .2rem; margin-left: .25rem; }
.assign-select { font-size: .72rem; border: 1px solid var(--border-2); border-radius: 999px; padding: .1rem .4rem; color: var(--muted); background: var(--surface); }
.btn-assign-go { border: 0; background: #eef2f6; color: var(--muted); font-size: .72rem; border-radius: 999px; padding: .1rem .45rem; cursor: pointer; }
.btn-assign-go:hover { background: var(--border-2); color: var(--ink); }

/* ---- Notes / commentary ----------------------------------- */
.note-add { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem; box-shadow: var(--shadow); }
.note-add textarea { border: 0; resize: vertical; padding: .25rem; }
.note-add textarea:focus { outline: none; box-shadow: none; }
.note-add-actions { display: flex; align-items: center; justify-content: space-between; margin-top: .5rem; }
.note-attach { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--muted); cursor: pointer; }
.note-attach input[type=file] { font-size: .78rem; max-width: 200px; }

.note-list { display: flex; flex-direction: column; gap: .6rem; }
.note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .85rem; box-shadow: var(--shadow); }
.note-head { display: flex; align-items: center; gap: .5rem; }
.note-time { color: var(--muted); font-size: .76rem; }
.note-del { margin-left: auto; }
.note-del-btn { border: 0; background: transparent; color: var(--border-2); font-size: 1.05rem; line-height: 1; cursor: pointer; padding: 0 .25rem; }
.note-del-btn:hover { color: var(--red); }
.note-body { margin-top: .4rem; color: var(--text); white-space: pre-wrap; }
.note-img-link { display: inline-block; margin-top: .5rem; }
.note-img { max-width: 260px; max-height: 220px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ---- Page header ------------------------------------------ */
.page-head h2 { margin-bottom: 0; }
.page-head .sub { color: var(--muted); font-weight: 500; }
