:root {
    --roratek-green: #6cb433;
    --roratek-green-bright: #97e54a;
    --roratek-green-dark: #4d8726;
    --roratek-green-dim: rgba(108, 180, 51, 0.13);
    --roratek-green-border: rgba(108, 180, 51, 0.28);
    --roratek-blue: #1f9bd1;
    --roratek-blue-dark: #1477a3;

    --green: #2f9e44;
    --amber: #f08c00;
    --red: #d9480f;

    --bg: #f4f8f1;
    --card: #ffffff;
    --text: #17212b;
    --muted: #667085;
    --border: #dde9d3;
    --shadow: 0 8px 28px rgba(18, 46, 10, 0.09);
    --shadow-hover: 0 16px 40px rgba(18, 46, 10, 0.16);

    --dark: #141a11;
    --nav-height: 68px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(ellipse at 88% 0%, rgba(108, 180, 51, 0.10), transparent 44%),
        radial-gradient(ellipse at 12% 100%, rgba(108, 180, 51, 0.07), transparent 38%),
        var(--bg);
    color: var(--text);
}

a {
    color: inherit;
    text-decoration: none;
}

p {
    margin: 0;
}

.app-shell {
    max-width: 1080px;
    margin: 0 auto;
    min-height: 100vh;
}

/* ---- Topbar ---- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    backdrop-filter: blur(16px);
    background: rgba(255, 255, 255, 0.90);
    border-bottom: 1px solid rgba(221, 233, 211, 0.85);
}

.brand {
    display: flex;
    align-items: center;
}

.brand img {
    height: 32px;
    width: auto;
    display: block;
}

.logout {
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

/* ---- Content ---- */

.content {
    padding: 24px 18px calc(var(--nav-height) + 32px + env(safe-area-inset-bottom, 0px));
}

/* ---- Bottom navigation ---- */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--dark);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex: 1;
    padding: 12px 8px;
    color: rgba(255, 255, 255, 0.36);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    position: relative;
    transition: color 160ms ease;
}

.nav-item.active {
    color: var(--roratek-green);
}

.nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 32px;
    height: 3px;
    background: var(--roratek-green);
    border-radius: 0 0 4px 4px;
    transition: transform 200ms ease;
}

.nav-item.active::before {
    transform: translateX(-50%) scaleX(1);
}

.nav-icon {
    width: 22px;
    height: 22px;
    transition: transform 160ms ease;
}

.nav-item.active .nav-icon {
    transform: translateY(-1px);
}

/* ---- Page headings ---- */

.hero,
.plant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}

.eyebrow {
    margin: 0 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 11px;
    color: var(--roratek-green-dark);
    font-weight: 800;
}

h1, h2 {
    margin: 0;
    line-height: 1.1;
}

h1 {
    font-size: clamp(28px, 7vw, 50px);
    letter-spacing: -0.04em;
}

h2 {
    font-size: 20px;
    letter-spacing: -0.02em;
}

.muted {
    color: var(--muted);
}

/* ---- Cards ---- */

.login-card,
.control-card,
.section-card,
.plant-card,
.metric-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.login-card {
    max-width: 430px;
    margin: 8vh auto 0;
    padding: 28px;
}

/* ---- Forms ---- */

.form-stack,
.inline-form,
.schedule-form {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

input,
select {
    width: 100%;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 12px;
    padding: 12px 14px;
    font: inherit;
    outline: none;
    transition: border-color 140ms ease;
}

input:focus,
select:focus {
    border-color: var(--roratek-green);
}

button {
    border: 0;
    border-radius: 14px;
    padding: 13px 18px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: opacity 140ms ease, transform 100ms ease;
}

button:active {
    transform: scale(0.97);
}

.primary-btn {
    background: var(--roratek-green);
    color: #fff;
}

.secondary-btn {
    background: var(--roratek-green-dim);
    color: var(--roratek-green-dark);
}

.danger-btn {
    width: 100%;
    margin-top: 10px;
    background: rgba(217, 72, 15, 0.10);
    color: var(--red);
}

/* ---- Plant card grid ---- */

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

.plant-card {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 0;
    padding: 0;
    overflow: hidden;
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.plant-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
}

/* ---- Card image ---- */

.card-image {
    position: relative;
    height: 190px;
    background: linear-gradient(135deg, var(--roratek-green-dim), var(--border));
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 300ms ease;
}

.plant-card:hover .card-image img {
    transform: scale(1.03);
}

.card-offline img {
    filter: grayscale(55%) brightness(0.9);
}

/* Status pill overlaid top-right on image */
.card-image .status-pill {
    position: absolute;
    top: 12px;
    right: 12px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Connection badge overlaid bottom-left on image */
.conn-badge {
    position: absolute;
    bottom: 12px;
    left: 12px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    padding: 5px 10px;
    border-radius: 999px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.conn-badge.online {
    background: rgba(108, 180, 51, 0.80);
    color: #fff;
}

.conn-badge.offline {
    background: rgba(0, 0, 0, 0.55);
    color: rgba(255, 255, 255, 0.80);
}

/* ---- Card body ---- */

.card-body {
    display: grid;
    gap: 16px;
    padding: 18px 20px 20px;
}

.card-body h2 {
    font-size: 18px;
    margin-bottom: 3px;
}

.card-top,
.device-row,
.list-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.card-top p {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 14px;
}

/* ---- Status pills ---- */

.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-healthy   { background: rgba(108, 180, 51, 0.14); color: var(--roratek-green-dark); }
.status-dry       { background: rgba(240, 140,  0, 0.14); color: var(--amber); }
.status-wet       { background: rgba( 31, 155, 209, 0.13); color: var(--roratek-blue-dark); }
.status-no-data   { background: #edf2f7; color: var(--muted); }
.status-complete  { background: rgba(108, 180, 51, 0.14); color: var(--roratek-green-dark); }
.status-requested { background: rgba(240, 140,  0, 0.14); color: var(--amber); }
.status-failed    { background: rgba(217,  72, 15, 0.12); color: var(--red); }
.status-sent      { background: rgba( 31, 155, 209, 0.13); color: var(--roratek-blue-dark); }

/* ---- Metrics ---- */

.metrics,
.metric-panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.metric-panel {
    grid-template-columns: repeat(4, 1fr);
    padding: 20px;
    margin: 14px 0;
}

.metric-label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 6px;
}

.metrics strong,
.metric-panel strong {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

/* ---- Device row ---- */

.device-row {
    padding-top: 14px;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    align-items: center;
}

.online  { color: var(--roratek-green); font-weight: 800; }
.offline { color: var(--red); font-weight: 800; }

/* ---- Back link ---- */

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 18px;
    color: var(--roratek-green-dark);
    font-weight: 700;
    font-size: 14px;
}

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

.control-card,
.section-card {
    padding: 22px;
    margin-bottom: 14px;
}

.section-card h2 {
    margin-bottom: 16px;
}

.inline-form {
    grid-template-columns: 1fr auto;
    align-items: end;
}

.schedule-form {
    grid-template-columns: 1.3fr 0.7fr 0.8fr auto;
    margin: 14px 0;
}

/* ---- List ---- */

.list {
    display: grid;
    gap: 10px;
}

.list-row {
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    align-items: center;
}

.list-row p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.list-row > span {
    flex-shrink: 0;
}

/* ---- Table ---- */

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

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 460px;
}

th, td {
    padding: 12px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 800;
}

/* ---- Flash messages ---- */

.messages {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.message {
    padding: 12px 16px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 14px;
}

.message.success {
    background: rgba(108, 180, 51, 0.13);
    color: var(--roratek-green-dark);
}

.message.error {
    background: rgba(217, 72, 15, 0.12);
    color: var(--red);
}

/* ---- Login ---- */

.login-logo {
    display: block;
    max-width: 180px;
    margin: 0 auto 28px;
}

/* ---- Plant hero ---- */

.plant-hero {
    position: relative;
    height: 260px;
    border-radius: 22px;
    overflow: hidden;
    margin-bottom: 14px;
    background: var(--border);
}

.plant-hero img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.plant-hero-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.38) 0%,
        transparent 38%,
        transparent 52%,
        rgba(0, 0, 0, 0.62) 100%
    );
}

.hero-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #fff;
    align-self: flex-start;
    flex-shrink: 0;
}

.plant-hero-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.plant-hero-info h1 {
    color: #fff;
    font-size: clamp(22px, 6vw, 36px);
    margin: 0;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.35);
}

.plant-hero-info p {
    color: rgba(255, 255, 255, 0.78);
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

/* ---- Plant meta strip ---- */

.plant-meta-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}

.meta-item {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.meta-item:not(:last-child) {
    border-right: 1px solid var(--border);
}

.meta-label {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.meta-value {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
}

/* ---- Section theming ---- */

.s-soil  { --s-color: #7a5230; --s-bg: rgba(122, 82,  48, 0.10); }
.s-water { --s-color: #1477a3; --s-bg: rgba( 20,119, 163, 0.10); }
.s-env   { --s-color: #b86000; --s-bg: rgba(184, 96,   0, 0.10); }
.s-sched { --s-color: #4d8726; --s-bg: rgba( 77,135,  38, 0.10); }
.s-hist  { --s-color: #3d52a0; --s-bg: rgba( 61, 82, 160, 0.10); }

.themed-section {
    border-top: 3px solid var(--s-color);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}

.section-header h2 {
    color: var(--s-color);
    margin: 0;
}

.section-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: var(--s-bg);
    color: var(--s-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ---- Soil / moisture gauge ---- */

.moisture-gauge {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.gauge-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.big-num {
    font-size: 44px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    color: var(--text);
}

.big-unit {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0;
}

.moisture-bar {
    height: 10px;
    border-radius: 99px;
    background: var(--border);
    overflow: hidden;
}

.moisture-fill {
    height: 100%;
    border-radius: 99px;
    transition: width 500ms ease;
}

.moisture-fill.status-healthy { background: var(--roratek-green); }
.moisture-fill.status-dry     { background: var(--amber); }
.moisture-fill.status-wet     { background: var(--roratek-blue); }
.moisture-fill.status-no-data { background: var(--muted); }

.moisture-limits {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--muted);
    font-weight: 700;
}

/* ---- Watering stats ---- */

.water-stats {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.tank-bar-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.tank-bar {
    flex: 1;
    height: 8px;
    border-radius: 99px;
    background: var(--border);
    overflow: hidden;
}

.tank-fill {
    height: 100%;
    border-radius: 99px;
    background: var(--roratek-blue);
    transition: width 500ms ease;
}

.tank-pct {
    font-size: 13px;
    font-weight: 800;
    color: var(--roratek-blue-dark);
    white-space: nowrap;
}

.water-stat-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.water-stat-pair strong {
    display: block;
    margin-top: 4px;
    font-size: 15px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-label {
    font-size: 13px;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.water-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

/* ---- Environment stats ---- */

.env-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.env-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stat-big {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
    display: block;
}

.stat-unit {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0;
}

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

.sched-badge {
    font-size: 11px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}

.sched-on  { background: var(--roratek-green-dim); color: var(--roratek-green-dark); }
.sched-off { background: #edf2f7; color: var(--muted); }

/* ---- No data message ---- */

.no-data-msg {
    color: var(--muted);
    font-size: 14px;
    padding: 8px 0 2px;
}

/* ---- Empty state ---- */

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
}

/* ---- Responsive ---- */

@media (max-width: 720px) {
    .hero,
    .plant-header {
        align-items: flex-start;
        gap: 14px;
        flex-wrap: wrap;
    }

    .metric-panel {
        grid-template-columns: repeat(2, 1fr);
    }

    .inline-form,
    .schedule-form {
        grid-template-columns: 1fr;
    }

    .metrics {
        grid-template-columns: repeat(3, 1fr);
    }

    .metrics strong,
    .metric-panel strong {
        font-size: 19px;
    }
}
