/* =========================================================================
   Crop Systems CRM — internal back office + customer portal.
   Same brand tokens as the marketing site, denser admin/dashboard layout.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@400;500;600;700&family=Source+Sans+3:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --color-primary: #4E7A25;
  --color-primary-hover: #3F6420;
  --color-primary-soft: #EAF3DE;
  --color-ink: #24272B;
  --color-slate: #58595B;
  --color-muted-fg: #6B7280;
  --color-signal: #1D6FA5;
  --color-signal-soft: #E4F1F8;
  --color-amber: #B5790A;
  --color-amber-soft: #FBF0DB;
  --color-bg: #F5F7F3;
  --color-bg-alt: #F0F3EC;
  --color-card: #FFFFFF;
  --color-border: #E1E6DC;
  --color-destructive: #DC2626;
  --color-destructive-soft: #FBEAEA;
  --color-success: #15803D;
  --color-success-soft: #E4F4EA;
  --color-ring: #4E7A25;

  --surface-dark: #1D2521;
  --surface-dark-text: #E7EAE3;
  --surface-dark-muted: #9AA396;
  --surface-dark-border: rgba(255,255,255,.1);
  --surface-dark-hover: #29332C;

  --font-heading: 'Lexend', sans-serif;
  --font-body: 'Source Sans 3', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --space-xs: .25rem; --space-sm: .5rem; --space-md: 1rem; --space-lg: 1.5rem; --space-xl: 2rem; --space-2xl: 3rem;
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(20,30,10,.06);
  --shadow-md: 0 4px 14px rgba(20,30,10,.08);
  --shadow-lg: 0 16px 36px rgba(20,30,10,.14);

  --sidebar-w: 248px;
  --topbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-body); font-size: .95rem; line-height: 1.55; color: var(--color-ink); background: var(--color-bg); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { font-family: var(--font-heading); font-weight: 600; line-height: 1.25; margin: 0 0 .4em; color: var(--color-ink); }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
.mono { font-family: var(--font-mono); }
:focus-visible { outline: 3px solid var(--color-ring); outline-offset: 2px; }
.text-muted { color: var(--color-muted-fg); }
.text-sm { font-size: .85rem; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; background: var(--surface-dark); color: var(--surface-dark-text); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; transition: transform 200ms ease; }
.sidebar-brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--surface-dark-border); }
.sidebar-brand img { height: 30px; filter: brightness(0) invert(1); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem; }
.sidebar-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--surface-dark-muted); padding: 1rem .75rem .35rem; }
.sidebar-link { display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: var(--radius-sm); color: var(--surface-dark-text); font-weight: 500; font-size: .9rem; margin-bottom: 2px; }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.sidebar-link:hover { background: var(--surface-dark-hover); text-decoration: none; }
.sidebar-link.is-active { background: var(--color-primary); color: #fff; }
.sidebar-link.is-active svg { opacity: 1; }
.sidebar-foot { padding: .75rem; border-top: 1px solid var(--surface-dark-border); }
.sidebar-user { display: flex; align-items: center; gap: .6rem; padding: .5rem .6rem; }
.sidebar-user-avatar { width: 32px; height: 32px; border-radius: 999px; background: var(--color-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.sidebar-user-name { font-size: .85rem; font-weight: 600; line-height: 1.2; }
.sidebar-user-role { font-size: .72rem; color: var(--surface-dark-muted); }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); background: var(--color-card); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; position: sticky; top: 0; z-index: 30; }
.topbar h1 { margin: 0; font-size: 1.15rem; }
.sidebar-toggle { display: none; }
.content { padding: 1.5rem; flex: 1; }
@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); }
  .main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
}

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45em; min-height: 38px; padding: 9px 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: .88rem; cursor: pointer; border: 1.5px solid transparent; transition: background 150ms ease, border-color 150ms ease; text-decoration: none !important; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary { background: #fff; color: var(--color-ink); border-color: var(--color-border); }
.btn-secondary:hover { border-color: var(--color-primary); background: var(--color-primary-soft); }
.btn-danger { background: var(--color-destructive); color: #fff; }
.btn-danger:hover { background: #B91C1C; }
.btn-ghost { background: transparent; color: var(--color-slate); border-color: transparent; padding: 6px 10px; }
.btn-ghost:hover { background: var(--color-bg-alt); }
.btn-sm { min-height: 32px; padding: 6px 12px; font-size: .82rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / stat tiles ---------- */
.card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 1.25rem 1.5rem; }
.card-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card-header h2 { margin: 0; }
.stat-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 1.5rem; }
.stat-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1.1rem 1.3rem; box-shadow: var(--shadow-sm); }
.stat-card .icon { width: 38px; height: 38px; border-radius: var(--radius-sm); background: var(--color-primary-soft); color: var(--color-primary); display: flex; align-items: center; justify-content: center; margin-bottom: .6rem; }
.stat-card .icon svg { width: 20px; height: 20px; }
.stat-card .icon.signal { background: var(--color-signal-soft); color: var(--color-signal); }
.stat-card .icon.amber { background: var(--color-amber-soft); color: var(--color-amber); }
.stat-card .icon.danger { background: var(--color-destructive-soft); color: var(--color-destructive); }
.stat-card .value { font-family: var(--font-heading); font-weight: 700; font-size: 1.6rem; line-height: 1.1; }
.stat-card .label { color: var(--color-muted-fg); font-size: .82rem; margin-top: .15rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th { text-align: left; padding: 10px 14px; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--color-muted-fg); font-weight: 700; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.data-table tbody tr:hover { background: var(--color-bg-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }
.row-title { font-weight: 600; color: var(--color-ink); }
.row-actions { display: flex; gap: .35rem; justify-content: flex-end; }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--color-muted-fg); }
.empty-state .icon { width: 44px; height: 44px; margin: 0 auto .75rem; color: var(--color-border); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .3em; padding: 3px 10px; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.badge-green { background: var(--color-success-soft); color: var(--color-success); }
.badge-amber { background: var(--color-amber-soft); color: var(--color-amber); }
.badge-red { background: var(--color-destructive-soft); color: var(--color-destructive); }
.badge-blue { background: var(--color-signal-soft); color: var(--color-signal); }
.badge-gray { background: var(--color-bg-alt); color: var(--color-slate); }

.icon-chip { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--color-primary-soft); color: var(--color-primary); flex-shrink: 0; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 5px; }
.field .hint { font-size: .8rem; color: var(--color-muted-fg); margin-top: 4px; }
.field .error { font-size: .8rem; color: var(--color-destructive); margin-top: 4px; }
.form-row { display: grid; gap: 1rem; }
@media (min-width: 620px) { .form-row.cols-2 { grid-template-columns: 1fr 1fr; } .form-row.cols-3 { grid-template-columns: repeat(3,1fr); } }
input, textarea, select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font-size: .9rem; font-family: var(--font-body); background: #fff; color: var(--color-ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
textarea { min-height: 90px; resize: vertical; }
label.checkbox { display: flex; align-items: center; gap: .5em; font-weight: 500; }
label.checkbox input { width: auto; }

/* ---------- Alerts / flash ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: 1.25rem; display: flex; align-items: center; gap: .6em; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; }
.alert-success { background: var(--color-success-soft); color: var(--color-success); }
.alert-error { background: var(--color-destructive-soft); color: var(--color-destructive); }
.alert-info { background: var(--color-signal-soft); color: var(--color-signal); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--color-border); margin-bottom: 1.25rem; overflow-x: auto; }
.tab-link { padding: 10px 2px; font-weight: 600; font-size: .88rem; color: var(--color-muted-fg); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab-link:hover { text-decoration: none; color: var(--color-ink); }
.tab-link.is-active { color: var(--color-primary); border-color: var(--color-primary); }

/* ---------- Misc ---------- */
.breadcrumbs { font-size: .82rem; color: var(--color-muted-fg); margin-bottom: .75rem; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.pill-nav { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.pill-nav a { padding: 6px 14px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--color-bg-alt); color: var(--color-slate); }
.pill-nav a:hover { text-decoration: none; background: var(--color-primary-soft); }
.pill-nav a.is-active { background: var(--color-primary); color: #fff; }
.grid-2 { display: grid; gap: 1.5rem; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 2fr 1fr; align-items: start; } }
.divider { border: none; border-top: 1px solid var(--color-border); margin: 1.25rem 0; }
.kv-list { display: flex; flex-direction: column; gap: .55rem; font-size: .88rem; }
.kv-list .row { display: flex; justify-content: space-between; gap: 1rem; }
.kv-list .k { color: var(--color-muted-fg); }
.kv-list .v { font-weight: 600; text-align: right; }

/* ---------- Auth / centered pages ---------- */
.centered-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: var(--color-bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card { padding: 2rem; }
.auth-logo { display: block; margin: 0 auto 1.5rem; height: 40px; }

/* ---------- Portal (customer-facing) ---------- */
.portal-header { background: var(--color-card); border-bottom: 1px solid var(--color-border); }
.portal-header .container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; height: 64px; display: flex; align-items: center; justify-content: space-between; }
.portal-header img { height: 30px; }
.portal-nav { display: flex; gap: 1.5rem; }
.portal-nav a { font-weight: 600; color: var(--color-slate); font-size: .9rem; }
.portal-nav a.is-active, .portal-nav a:hover { color: var(--color-primary); text-decoration: none; }
.portal-container { max-width: 1100px; margin: 0 auto; padding: 1.75rem 1.5rem 3rem; }

/* ---------- Pagination (Bootstrap-5 markup from Laravel's paginator) ---------- */
.pagination { display: flex; list-style: none; padding: 0; margin: 0; gap: .25rem; flex-wrap: wrap; }
.pagination .page-item .page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 34px; padding: 0 .6rem; border-radius: var(--radius-sm); border: 1px solid var(--color-border); background: #fff; color: var(--color-ink); font-size: .85rem; }
.pagination .page-item .page-link:hover { border-color: var(--color-primary); background: var(--color-primary-soft); text-decoration: none; }
.pagination .page-item.active .page-link { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.pagination .page-item.disabled .page-link { color: var(--color-border); cursor: not-allowed; }

/* ---------- Charts ---------- */
.chart-card { padding: 1.25rem 1.5rem; }
.chart-card canvas { max-width: 100%; }
.metric-tile { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.metric-tile .icon { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--color-primary-soft); color: var(--color-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.metric-tile .icon svg { width: 18px; height: 18px; }
.metric-tile .icon.warning { background: var(--color-amber-soft); color: var(--color-amber); }
.metric-tile .icon.critical { background: var(--color-destructive-soft); color: var(--color-destructive); }
.metric-tile .value { font-family: var(--font-heading); font-weight: 700; font-size: 1.15rem; }
.metric-tile .label { font-size: .78rem; color: var(--color-muted-fg); }
.metric-grid { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 1.25rem; }
