/* IoT Platform — base stylesheet. Plain CSS, no build step. */

:root {
    --c-bg: #f4f6f8;
    --c-surface: #ffffff;
    --c-border: #dfe3e8;
    --c-text: #1f2933;
    --c-muted: #6b7280;
    --c-primary: #2563eb;
    --c-primary-dark: #1d4ed8;
    --c-success: #0f9d58;
    --c-success-bg: #e6f4ea;
    --c-danger: #d23f31;
    --c-danger-bg: #fbeae8;
    --c-warning: #b8860b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --maxw: 1100px;
    /* Spacing scale (4px base) — use these for consistent vertical rhythm. */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    font-size: 16px;
}

* { box-sizing: border-box; }

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

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

/* Topbar */
.topbar { background: var(--c-surface); border-bottom: 1px solid var(--c-border); }
.topbar__inner {
    max-width: var(--maxw); margin: 0 auto; padding: 0.75rem 1rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.topbar__brand { font-weight: 700; font-size: 1.1rem; color: var(--c-text); }
.topbar__nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar__user { color: var(--c-muted); font-size: 0.85rem; }
.topbar__logout { margin: 0; }

/* Layout */
.container { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1rem; }
.footer { max-width: var(--maxw); margin: 0 auto; padding: 1.5rem 1rem; color: var(--c-muted); }
.body--minimal { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.minimal { width: 100%; max-width: 420px; padding: 1.5rem; }

/* Hero */
.hero { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
    padding: 2.5rem; box-shadow: var(--shadow); }
.hero__lead { color: var(--c-muted); font-size: 1.1rem; max-width: 50ch; }

/* Cards / panels */
.panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
    padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: var(--space-5); }
.panel--compact { padding: var(--space-3) var(--space-4); }
.panel__title { margin: 0 0 var(--space-4); font-size: 1.1rem; }
/* A panel that directly follows a grid needs its own top spacing — the grid
   itself carries no bottom margin. (Inline margins still override this.) */
.grid + .panel { margin-top: var(--space-5); }

.grid { display: grid; gap: var(--space-4); }
.grid--cards { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius);
    padding: 1rem; box-shadow: var(--shadow); }
.card__title { font-weight: 600; margin-bottom: 0.5rem; }
.card__meta { color: var(--c-muted); font-size: 0.85rem; }

/* Buttons */
.btn { display: inline-block; padding: 0.5rem 0.9rem; border-radius: var(--radius);
    border: 1px solid var(--c-border); background: var(--c-surface); color: var(--c-text);
    cursor: pointer; font-size: 0.95rem; text-decoration: none; }
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn--primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn--primary:hover { background: var(--c-primary-dark); }
.btn--danger { background: var(--c-danger); border-color: var(--c-danger); color: #fff; }
.btn--link { border: none; background: none; color: var(--c-primary); padding: 0; }
.btn--sm { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: 0.3rem; font-size: 0.9rem; }
.form-control { width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--c-border);
    border-radius: var(--radius); font-size: 0.95rem; background: #fff; }
.form-control:focus { outline: 2px solid var(--c-primary); border-color: var(--c-primary); }
.form-inline { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; }
.form-hint { color: var(--c-muted); font-size: 0.8rem; }
.form-error { color: var(--c-danger); font-size: 0.85rem; margin-top: 0.3rem; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--c-surface); }
.table th, .table td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--c-border); }
.table th.is-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.is-sortable:hover { color: var(--c-primary); }
.table th .sort-ind { font-size: 0.7em; opacity: 0.4; margin-left: 0.15rem; }
.table th[aria-sort] .sort-ind { opacity: 1; color: var(--c-primary); }
.table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--c-muted); }
.table tbody tr:hover { background: #f7f9fb; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge--ok { background: var(--c-success-bg); color: var(--c-success); }
.badge--warn { background: #fff4e0; color: var(--c-warning); }
.badge--danger { background: var(--c-danger-bg); color: var(--c-danger); }
.badge--muted { background: #eef1f4; color: var(--c-muted); }

/* Positive "X of Y online" summary on the project overview */
.status-online { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 var(--space-4);
    padding: 0.6rem 0.9rem; border-radius: var(--radius); background: var(--c-success-bg);
    color: var(--c-text); font-weight: 600; border: 1px solid var(--c-border); }
.status-online__dot { width: 0.65rem; height: 0.65rem; border-radius: 50%; flex: none;
    background: var(--c-success); box-shadow: 0 0 0 3px rgba(15, 157, 88, 0.18); }

/* Compare page: device -> value selection hierarchy */
.cw-devices { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-3) 0; }
.cw-device { border: 1px solid var(--c-border); border-radius: var(--radius);
    padding: var(--space-2) var(--space-3); background: var(--c-bg); }
.cw-device__head { display: flex; align-items: center; justify-content: space-between;
    gap: var(--space-2); margin-bottom: var(--space-2); }
.cw-device__name { font-weight: 600; font-size: 0.9rem; }
.cw-device__remove { font-size: 1.2rem; line-height: 1; color: var(--c-muted); }
.cw-device__remove:hover { color: var(--c-danger); }
.cw-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.cw-chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.25rem 0.65rem;
    border: 1px solid var(--c-border); border-radius: 999px; background: var(--c-surface);
    color: var(--c-text); font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.cw-chip:hover { border-color: var(--c-primary); color: var(--c-primary); }
.cw-chip.is-on { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.cw-chip.is-on::before { content: '\2713'; font-size: 0.75rem; }

/* Garden page: metric cards span the full row (auto-fit collapses empty
   tracks, unlike --cards' auto-fill), plus a prominent disclaimer callout. */
.grid--fit { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.callout { background: #fff4e0; border: 1px solid var(--c-warning); border-radius: var(--radius);
    padding: var(--space-4); margin: var(--space-4) 0 var(--space-5); font-size: 0.9rem; }
.callout > strong { display: block; margin-bottom: 0.2rem; }

/* Garden page: the irrigation estimate laid out as a calculation
   (need − effective rain = irrigation), operators centered between cards. */
.calc { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: var(--space-2) var(--space-3);
    align-items: stretch; margin: 0 0 var(--space-3); }
.calc__op { align-self: center; justify-self: center; text-align: center; line-height: 1;
    font-size: 2.5rem; font-weight: 700; color: var(--c-muted); padding: 0 0.1rem; }
@media (max-width: 700px) {
    .calc { grid-template-columns: 1fr; }
    .calc__op { padding: 0; }
}

/* Compare page: one options bar grouping time range + display toggles */
.chart-options { display: flex; flex-direction: column; gap: var(--space-2);
    margin: var(--space-3) 0; padding-top: var(--space-3); border-top: 1px solid var(--c-border); }
.chart-options__row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.chart-options__label { min-width: 4rem; font-size: 0.8rem; font-weight: 600; color: var(--c-muted);
    text-transform: uppercase; letter-spacing: 0.03em; }
.chart-options__row label { display: inline-flex; align-items: center; gap: 0.4rem;
    font-size: 0.85rem; cursor: pointer; }

/* Admin devices: project-assignment rows and the collapsible assign control */
.assign-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.assign-row .form-control { width: auto; }
.assign-name { flex: 1 1 14rem; min-width: 11rem; }
.assign-select { max-width: 16rem; }
.assign-add { margin-top: 0.25rem; }
.assign-add > summary { cursor: pointer; color: var(--c-primary); font-weight: 600; font-size: 0.85rem;
    list-style: none; display: inline-flex; align-items: center; gap: 0.35rem; user-select: none; }
.assign-add > summary::-webkit-details-marker { display: none; }
.assign-add > summary::before { content: '+'; font-weight: 700; font-size: 1rem; line-height: 1; }
.assign-add[open] > summary::before { content: '\2212'; }

/* Flash */
.flash { max-width: var(--maxw); margin: 1rem auto 0; padding: 0.75rem 1rem; border-radius: var(--radius); }
.flash--success { background: var(--c-success-bg); color: var(--c-success); }
.flash--error { background: var(--c-danger-bg); color: var(--c-danger); }

/* Errors */
.error-page { text-align: center; padding: 2rem 0; }
.error-page__code { font-size: 4rem; margin: 0; color: var(--c-primary); }
.error-page__message { color: var(--c-muted); font-size: 1.15rem; }
.error-page__detail { text-align: left; background: #1f2933; color: #e5e7eb; padding: 1rem;
    border-radius: var(--radius); overflow: auto; font-size: 0.8rem; }

/* Utilities */
.muted { color: var(--c-muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.stack > * + * { margin-top: 1rem; }
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-title { margin: 0 0 1rem; }

/* Optional explicit wrapper for wide tables (also works on desktop). */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 720px) {
    /* Responsive tables: on narrow screens let a wide table scroll horizontally
       inside its panel instead of overflowing the page. The table stays a real
       table (columns stay aligned); only line-wrapping is suppressed so it keeps
       its natural width and the panel provides the scroll affordance. */
    .panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table th, .table td { white-space: nowrap; }
}

@media (max-width: 640px) {
    .topbar__inner { flex-direction: column; align-items: flex-start; }
    .hero { padding: 1.5rem; }
}
