/* ─── RuralBot Shared Design System ───────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&family=DM+Serif+Display:ital@0;1&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar:      oklch(24% 0.07 145);
  --sidebar-hov:  oklch(30% 0.08 145);
  --green:        oklch(52% 0.17 145);
  --green-light:  oklch(95% 0.055 145);
  --amber:        oklch(70% 0.17 75);
  --amber-light:  oklch(96% 0.055 75);
  --wheat:        oklch(92% 0.04 80);
  --red:          oklch(60% 0.19 25);
  --red-light:    oklch(96% 0.055 25);
  --bg:           oklch(97% 0.014 80);
  --surface:      oklch(99.5% 0.006 78);
  --surface-alt:  oklch(96.5% 0.018 78);
  --border:       oklch(89% 0.018 78);
  --text:         oklch(22% 0.04 145);
  --text-muted:   oklch(52% 0.03 140);
  --serif:        'DM Serif Display', Georgia, serif;
  --sans:         'DM Sans', system-ui, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::after {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none; z-index: 9999;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
}

/* ── Layout shell ────────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px; background: var(--sidebar);
  display: flex; flex-direction: column; flex-shrink: 0;
  box-shadow: 4px 0 24px oklch(0% 0 0 / 0.14);
  z-index: 10; position: relative; overflow: hidden;
  transition: width 0.3s cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed { width: 64px; }
.sidebar::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0; height: 80px;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent 0%,
    oklch(22% 0.07 145 / 0.6) 60%, oklch(20% 0.07 145 / 0.9) 100%);
  z-index: 0;
}

.sidebar-logo {
  padding: 22px 18px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid oklch(100% 0 0 / 0.08); flex-shrink: 0;
  text-decoration: none;
}
.sidebar-logo img {
  width: 40px; height: 40px; object-fit: contain; flex-shrink: 0;
  filter: drop-shadow(0 2px 6px oklch(0% 0 0 / 0.35));
  transition: width 0.3s, height 0.3s;
}
.sidebar-logo .logo-text { overflow: hidden; }
.sidebar-logo .logo-name {
  color: #fff; font-weight: 700; font-size: 16px;
  letter-spacing: -0.01em; white-space: nowrap;
}
.sidebar-logo .logo-sub {
  color: oklch(72% 0.07 145); font-size: 11px;
  white-space: nowrap; margin-top: 1px;
}
.sidebar.collapsed .sidebar-logo { justify-content: center; padding: 22px 0; }
.sidebar.collapsed .logo-text { display: none; }
.sidebar.collapsed .sidebar-logo img { width: 34px; height: 34px; }

nav.sidebar-nav {
  flex: 1; padding: 10px;
  display: flex; flex-direction: column; gap: 2px;
  position: relative; z-index: 1;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: 12px;
  text-decoration: none; border: none; background: transparent;
  cursor: pointer; font-family: var(--sans);
  color: oklch(72% 0.045 145); font-size: 14px; font-weight: 400;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap; overflow: hidden;
}
.sidebar.collapsed .nav-item { justify-content: center; padding: 11px 0; }
.sidebar.collapsed .nav-item span.nav-label { display: none; }
.nav-item:hover { background: oklch(100% 0 0 / 0.07); color: white; }
.nav-item.active {
  background: oklch(100% 0 0 / 0.12); color: white; font-weight: 500;
}
.nav-item .nav-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--amber); margin-left: auto; flex-shrink: 0;
}
.sidebar.collapsed .nav-item .nav-dot { display: none; }
.nav-icon { flex-shrink: 0; display: flex; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid oklch(100% 0 0 / 0.08);
  font-size: 11px; color: oklch(52% 0.04 145); line-height: 1.6;
  flex-shrink: 0; position: relative; z-index: 1;
}
.sidebar-footer strong { color: oklch(68% 0.05 145); display: block; }
.sidebar.collapsed .sidebar-footer { display: none; }

/* ── Top bar ────────────────────────────────────────────────────────────── */
.topbar {
  height: 60px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-title { font-weight: 600; font-size: 15px; color: var(--text); }
.topbar-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.topbar-toggle {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: background 0.15s;
}
.topbar-toggle:hover { background: var(--wheat); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 99px;
  background: var(--green-light); color: var(--green);
  font-size: 12px; font-weight: 500;
}
.status-pill .dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
}

/* ── Page content ────────────────────────────────────────────────────────── */
.page-main {
  flex: 1; overflow: auto;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.page-body {
  padding: 28px 32px;
  display: flex; flex-direction: column; gap: 24px;
  flex: 1;
  max-width: 1100px;
  width: 100%;
}
.page-body.narrow { max-width: 760px; }
.page-body.medium { max-width: 820px; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 2px 12px oklch(0% 0 0 / 0.055), 0 1px 3px oklch(0% 0 0 / 0.04);
}
.card-alt { background: var(--surface-alt); }
.card h2 {
  font-family: var(--serif);
  font-size: 18px; color: var(--text);
  letter-spacing: -0.01em; margin-bottom: 18px;
}
.card h3 {
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 12px;
}

.section-heading {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.section-heading h2 {
  font-family: var(--serif); font-size: 20px;
  color: var(--text); letter-spacing: -0.01em;
}
.section-heading p {
  font-size: 12px; color: var(--text-muted); margin-top: 2px;
}

.page-title {
  font-family: var(--serif); font-size: 22px;
  color: var(--text); letter-spacing: -0.01em; margin-bottom: 3px;
}
.page-subtitle {
  font-size: 13px; color: var(--text-muted);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 12px;
  font-family: var(--sans); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  text-decoration: none; border: none;
  letter-spacing: 0.01em; white-space: nowrap;
}
.btn-primary { background: var(--sidebar); color: #fff; }
.btn-primary:hover {
  background: oklch(28% 0.08 145);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px oklch(0% 0 0 / 0.18);
}
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--wheat); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover {
  background: oklch(48% 0.17 145);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px oklch(52% 0.17 145 / 0.35);
}
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover {
  background: oklch(54% 0.19 25);
  transform: translateY(-1px);
}
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 8px; }

/* ── Form elements ───────────────────────────────────────────────────────── */
.form-label {
  display: block; font-weight: 600; font-size: 12px;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 7px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 14px; font-family: var(--sans);
  background: var(--surface-alt); color: var(--text);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px oklch(52% 0.17 145 / 0.14);
}
.form-textarea { resize: vertical; line-height: 1.6; min-height: 90px; }
.form-checkbox-row {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--text);
}

/* ── Chips / Pills ───────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 500;
}
.chip-green  { background: var(--green-light);  color: var(--green); }
.chip-amber  { background: var(--amber-light);  color: oklch(58% 0.17 70); }
.chip-red    { background: var(--red-light);    color: var(--red); }
.chip-blue   { background: oklch(94% 0.04 230); color: oklch(48% 0.15 235); }
.chip-muted  { background: var(--wheat);        color: var(--text-muted); }

/* Status pill mapping for watering session states */
.state-queued, .state-commanding_open, .state-commanding_close { background: oklch(94% 0.04 230); color: oklch(48% 0.15 235); }
.state-confirmed_open, .state-complete, .state-confirmed_close { background: var(--green-light); color: var(--green); }
.state-failed, .state-timeout { background: var(--red-light); color: var(--red); }
.state-cancelled { background: var(--wheat); color: var(--text-muted); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px;
}
.data-table th {
  text-align: left; padding: 10px 14px;
  background: var(--surface-alt); color: var(--text-muted);
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  border-bottom: 1.5px solid var(--border);
}
.data-table th:first-child { border-radius: 8px 0 0 0; }
.data-table th:last-child  { border-radius: 0 8px 0 0; }
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--wheat); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tab-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  padding: 8px 16px; border-radius: 20px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1.5px solid var(--border);
  background: transparent; color: var(--text-muted);
  transition: all 0.18s; font-family: var(--sans);
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover:not(.tab-active) { background: var(--wheat); color: var(--text); }
.tab.tab-active {
  background: var(--sidebar); color: white; border-color: var(--sidebar);
}

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 8px;
  justify-content: flex-end; margin-top: 16px;
}
.page-btn {
  min-width: 32px; height: 32px; padding: 0 10px; border-radius: 8px;
  border: 1.5px solid var(--border); background: transparent;
  font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--text-muted); font-family: var(--sans);
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
  transition: all 0.15s;
}
.page-btn:hover:not(.page-active) { background: var(--wheat); }
.page-btn.page-active { background: var(--sidebar); color: white; border-color: var(--sidebar); }
.page-info { font-size: 12px; color: var(--text-muted); margin-left: 4px; }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: 12px 16px; border-radius: 12px; font-size: 13px;
  font-weight: 500; margin-bottom: 8px;
}
.flash-success { background: var(--green-light); color: var(--green); border: 1px solid oklch(85% 0.06 145); }
.flash-error   { background: var(--red-light); color: var(--red); border: 1px solid oklch(86% 0.06 25); }
.flash-info    { background: oklch(94% 0.04 230); color: oklch(48% 0.15 235); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  color: var(--text-muted); font-style: italic;
  padding: 24px; text-align: center;
  background: var(--surface-alt); border-radius: 12px;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: oklch(82% 0.02 80); border-radius: 4px;
  border: 2px solid transparent; background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: oklch(72% 0.03 80); background-clip: content-box; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar .logo-text, .sidebar .nav-label, .sidebar-footer { display: none; }
  .sidebar .sidebar-logo { justify-content: center; padding: 22px 0; }
  .sidebar .nav-item { justify-content: center; padding: 11px 0; }
  .topbar { padding: 0 18px; }
  .page-body { padding: 20px 16px; }
}
