/* Vigil custom dashboards: tile grid, tile bodies (rendered by _tile.html), editor chrome and present mode.
   Uses the design tokens from style.css (--bg --panel --panel2 --line --text --muted --dim --brand --ok --warn --err --radius). */

/* ---------- header */
.dhead{display:flex;justify-content:space-between;align-items:center;gap:14px;flex-wrap:wrap;margin-bottom:16px}
.dhead-l{display:flex;align-items:center;gap:14px;min-width:0}
.dhead h1{margin:0;font-size:22px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dswitch{width:auto;min-width:150px;max-width:220px;padding:7px 10px;font-size:13px}
.drefresh{font-size:12px;color:var(--dim);cursor:pointer;white-space:nowrap;display:inline-flex;align-items:center;gap:6px;user-select:none}
.drefresh:before{content:"";width:7px;height:7px;border-radius:50%;background:var(--dim);transition:background .2s}
.drefresh.busy:before{background:var(--brand);box-shadow:0 0 8px var(--brand);animation:dpulse 1s infinite}
@keyframes dpulse{50%{opacity:.35}}
.dstatus{font-size:12px;color:var(--muted);padding:3px 9px;border-radius:999px;border:1px solid var(--line);white-space:nowrap}
.dstatus.ok{color:var(--ok);border-color:rgba(46,204,138,.4)}.dstatus.warn{color:var(--warn);border-color:rgba(245,179,66,.4)}
.dstatus.err{color:var(--err);border-color:rgba(255,92,122,.4)}.dstatus.busy{color:var(--brand)}
.dsettings{margin-bottom:16px;padding:14px 16px}
.dsettings-form{display:grid;grid-template-columns:2fr 3fr 1fr auto;gap:12px;align-items:end}
.dsettings-form label{margin-bottom:4px}
@media (max-width:900px){.dsettings-form{grid-template-columns:1fr 1fr}}

/* ---------- grid + tiles */
.dgrid{display:grid;grid-template-columns:repeat(12,minmax(0,1fr));grid-auto-rows:60px;gap:10px;position:relative;min-height:140px}
.dtile{display:flex;flex-direction:column;min-width:0;min-height:0;background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);position:relative;overflow:hidden;transition:box-shadow .15s,border-color .15s}
.dtile:focus{outline:none;border-color:var(--brand);box-shadow:0 0 0 3px rgba(91,140,255,.2)}
.dtile-h{display:flex;align-items:center;gap:6px;padding:7px 12px;font-size:12.5px;font-weight:600;color:var(--muted);border-bottom:1px solid var(--line);flex:none;min-height:32px}
.dtile-h .ttl{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;flex:1}
.dtile-b{flex:1;min-height:0;overflow:auto;padding:10px 12px;position:relative}
.dtile-b.busy{opacity:.7}
.dempty{grid-column:1/-1;text-align:center;color:var(--muted);padding:60px 20px;border:1px dashed var(--line);border-radius:var(--radius)}

/* editor chrome */
.dgrid.editing .dtile{user-select:none}
.dgrid.editing .dtile-h{cursor:grab;touch-action:none}
.dgrid.editing .dtile.dragging{z-index:20;cursor:grabbing;box-shadow:0 20px 40px -16px rgba(0,0,0,.9);border-color:var(--brand);opacity:.92;transition:none}
.dgrid.editing .dtile.resizing{border-color:var(--brand);transition:none}
.dtile-h .tools{display:none;margin-left:auto;gap:2px;flex:none}
.dgrid.editing .dtile-h .tools{display:inline-flex}
.dtile-h .tb{background:transparent;border:0;color:var(--dim);font-size:13px;width:24px;height:22px;border-radius:6px;cursor:pointer;padding:0;line-height:1;font-family:inherit}
.dtile-h .tb:hover{background:var(--panel2);color:var(--text)}
.dtile-h .tb.del:hover{color:var(--err)}
.dtile-h .tb.grip{cursor:grab;letter-spacing:-3px;font-size:14px}
.dtile .rz{position:absolute;right:0;bottom:0;width:18px;height:18px;cursor:nwse-resize;touch-action:none;z-index:2}
.dtile .rz:after{content:"";position:absolute;right:4px;bottom:4px;width:8px;height:8px;border-right:2px solid var(--dim);border-bottom:2px solid var(--dim);border-radius:0 0 3px 0}
.dtile:hover .rz:after{border-color:var(--brand)}
.dghost{border:2px dashed var(--brand);border-radius:var(--radius);background:rgba(91,140,255,.08);pointer-events:none;z-index:1}

/* ---------- tile bodies (markup from _tile.html) */
.tile-stat{height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center}
.tile-stat .v{font-size:clamp(28px,3.4vw,46px);font-weight:800;letter-spacing:-.03em;line-height:1.05;font-variant-numeric:tabular-nums}
.tile-stat .v.err{color:var(--err)}
.tile-stat .u{font-size:.42em;color:var(--muted);margin-left:5px;font-weight:600;letter-spacing:0}
.tile-stat .h{color:var(--dim);font-size:12px;margin-top:6px}
.tile-status{padding:9px 14px;border-radius:9px;font-weight:700;margin-bottom:10px;text-align:center;font-size:13.5px;border:1px solid}
.tile-status.operational{background:rgba(46,204,138,.12);color:var(--ok);border-color:rgba(46,204,138,.35)}
.tile-status.degraded{background:rgba(245,179,66,.12);color:var(--warn);border-color:rgba(245,179,66,.35)}
.tile-status.down{background:rgba(255,92,122,.12);color:var(--err);border-color:rgba(255,92,122,.35);animation:dpulse 1.6s infinite}
.tile-list{font-size:13px}
.tile-list .row{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:4px 0;border-bottom:1px solid rgba(34,48,74,.55);font-size:13px}
.tile-list>.row:last-child{border-bottom:0}
.tile-list .row>span:first-child{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tile-list .row>span:last-child{flex:none;font-size:12px}
.tile-list a,.tile-table a{color:var(--text)}
.tile-table{width:100%;border-collapse:collapse;font-size:13px}
.tile-table td{padding:5px 6px;border-bottom:1px solid rgba(34,48,74,.55);white-space:nowrap;vertical-align:middle}
.tile-table td:first-child{padding-left:0;white-space:normal;max-width:0;overflow:hidden;text-overflow:ellipsis}
.tile-table td:last-child{padding-right:0}
.tile-table tr:last-child td{border-bottom:0}
.tile-table .mini{width:100px}
.tile-chart{display:flex;flex-direction:column;height:100%}
.tile-chart .lbl{font-size:12px;color:var(--muted);margin-bottom:6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;flex:none}
.tile-chart .lbl b{color:var(--text)}
.tile-chart .area{flex:1;min-height:40px;position:relative}
.tile-gauges{display:grid;grid-template-columns:repeat(3,1fr);gap:6px 8px;text-align:center;align-content:center;height:100%;font-size:12px}
.tile-gauges .g svg{width:64px;height:64px;display:block;margin:0 auto}
.tile-gauges .n{font-weight:700;font-size:15px;margin-top:2px;font-variant-numeric:tabular-nums}
.tile-gauges .l{color:var(--dim);font-size:11.5px}
.tile-text{white-space:pre-wrap;word-break:break-word;font-size:13.5px;line-height:1.5}
.tile-empty{display:flex;align-items:center;justify-content:center;height:100%;min-height:40px;color:var(--dim);text-align:center;font-size:13px;padding:6px}
.tile-empty.err{color:var(--err)}
.dtile-b iframe{display:block}

/* ---------- add-tile panel */
.dadd{position:fixed;inset:0;background:rgba(5,8,14,.66);z-index:55;display:none;align-items:center;justify-content:center;padding:20px}
.dadd.open{display:flex}
.dadd .box{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);width:min(820px,100%);max-height:86vh;overflow:auto;padding:18px 20px;box-shadow:var(--shadow)}
.dadd .box h2{display:flex;justify-content:space-between;align-items:center}
.dadd .types{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:10px}
.dadd .type{text-align:left;background:var(--panel2);border:1px solid var(--line);border-radius:9px;padding:11px 13px;cursor:pointer;color:var(--text);font:inherit}
.dadd .type:hover{border-color:var(--brand);background:#1a2438}
.dadd .type b{display:block;font-size:13.5px}
.dadd .type span{color:var(--muted);font-size:12.5px;display:block;margin-top:2px}
.dadd .type i{color:var(--dim);font-size:11px;font-style:normal}

/* ---------- configure drawer */
.ddrawer{position:fixed;top:0;right:0;bottom:0;width:min(440px,100%);background:var(--bg2);border-left:1px solid var(--line);z-index:60;display:flex;flex-direction:column;transform:translateX(102%);transition:transform .18s ease;box-shadow:-20px 0 50px -30px rgba(0,0,0,.9)}
.ddrawer.open{transform:none}
.ddrawer .dd-h{display:flex;justify-content:space-between;align-items:center;padding:14px 18px;border-bottom:1px solid var(--line);flex:none}
.ddrawer .dd-h h3{margin:0}
.ddrawer .dd-b{flex:1;overflow:auto;padding:14px 18px}
.ddrawer .dd-f{padding:12px 18px;border-top:1px solid var(--line);display:flex;gap:8px;justify-content:flex-end;flex:none}
.ddrawer .frow{margin-bottom:12px}
.ddrawer .frow label{font-size:12.5px}
.ddrawer .frow2{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.ddrawer .dpv-l{font-size:11px;text-transform:uppercase;letter-spacing:.06em;color:var(--dim);margin:16px 0 6px}
.ddrawer .dpv{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);padding:10px 12px;overflow:auto;height:220px;position:relative}
.ddrawer .dpv.busy{opacity:.6}

/* ---------- present mode */
body.present{background:#05080e;padding:18px 24px 24px;min-height:100vh;box-sizing:border-box}
body.present.idle{cursor:none}
.present .ptop{display:flex;justify-content:space-between;align-items:flex-start;gap:20px;margin-bottom:16px}
.present .ptop h1{font-size:30px;margin:0}
.present .ptop .muted{font-size:15px}
.present .pright{text-align:right;flex:none}
.present .pclock{font-size:40px;font-weight:800;letter-spacing:-.02em;font-variant-numeric:tabular-nums;line-height:1}
.present .phint{position:fixed;right:18px;bottom:12px;font-size:11px;color:var(--dim);opacity:.7}
.present.idle .phint{opacity:0}
.present .dgrid{grid-auto-rows:64px;gap:12px}
.present .dtile-h{font-size:14px;padding:9px 14px}
.present .dtile-b{padding:12px 14px;font-size:15px}
.present .tile-stat .v{font-size:clamp(44px,4.8vw,84px)}
.present .tile-stat .h{font-size:14px}
.present .tile-list .row,.present .tile-table,.present .tile-text{font-size:15px}
.present .tile-status{font-size:16px;padding:12px 16px}
.present .tile-gauges .g svg{width:88px;height:88px}
.present .tile-gauges .n{font-size:19px}
.present .tile-chart .lbl{font-size:13.5px}

/* ---------- small screens: one column, tiles stacked in reading order */
@media (max-width:700px){
  .dgrid{display:flex;flex-direction:column;gap:10px}
  .dtile{height:calc(var(--h,3) * 70px - 10px);max-height:70vh;flex:none}
  .dghost,.dtile .rz{display:none}
  .dhead h1{font-size:19px}
  .dsettings-form{grid-template-columns:1fr}
  body.present{padding:12px}
  .present .ptop h1{font-size:22px}.present .pclock{font-size:28px}
}
/* tables inside tiles: keep the name column readable, truncate instead of wrapping letter by letter */
.tile-table{table-layout:auto}.tile-table td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:0}
.tile-table td:first-child{max-width:none;width:1%;min-width:120px}.tile-table td .pill{margin-left:4px}
.tile-table .mini{width:100px;min-width:60px}.tile-list .row > span:first-child{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.tile-list .row{gap:8px}.tile-list .row > span:last-child{flex-shrink:0}
