/* Mkenya FMS — Main Design Tokens & Base
   Version: 1.0.0 | Kenyan Agricultural Green Theme
================================================================ */

:root {
  --fms-primary:       #2d7d32;
  --fms-primary-dark:  #1b5e20;
  --fms-primary-light: #4caf50;
  --fms-accent:        #ff8f00;
  --fms-accent-light:  #ffca28;
  --fms-danger:        #c62828;
  --fms-danger-light:  #ef5350;
  --fms-warning:       #e65100;
  --fms-warning-light: #ff9800;
  --fms-info:          #0277bd;
  --fms-info-light:    #29b6f6;
  --fms-success:       #2e7d32;
  --fms-bg:            #f8faf8;
  --fms-bg-card:       #ffffff;
  --fms-bg-sidebar:    #1b5e20;
  --fms-text:          #1a1a1a;
  --fms-text-muted:    #5f5f5f;
  --fms-text-light:    #9e9e9e;
  --fms-border:        #e0e7e0;
  --fms-border-dark:   #b2c4b2;
  --fms-radius:        10px;
  --fms-radius-sm:     6px;
  --fms-radius-lg:     16px;
  --fms-shadow:        0 2px 12px rgba(45,125,50,0.10);
  --fms-shadow-hover:  0 6px 24px rgba(45,125,50,0.18);
  --fms-transition:    0.2s ease;
  --fms-sidebar-w:     260px;
  --fms-topbar-h:      60px;
  --fms-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Arial, sans-serif;
}

/* Reset & Base */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

.mkenya-fms-admin-wrap,
.fms-frontend-panel {
  font-family: var(--fms-font);
  color: var(--fms-text);
  background: var(--fms-bg);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Typography ─────────────────────────────────────────── */
.fms-h1 { font-size: 1.75rem; font-weight: 700; color: var(--fms-primary-dark); }
.fms-h2 { font-size: 1.375rem; font-weight: 600; }
.fms-h3 { font-size: 1.125rem; font-weight: 600; }
.fms-label { font-size: 0.8125rem; font-weight: 600; color: var(--fms-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Loading Screen ─────────────────────────────────────── */
.fms-loading-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1b5e20 0%, #2d7d32 60%, #388e3c 100%);
  z-index: 9999;
  transition: opacity 0.4s ease;
}
.fms-loader-logo { text-align: center; color: #fff; }
.fms-logo-leaf   { font-size: 3.5rem; display: block; margin-bottom: 12px; animation: fms-pulse 1.5s ease-in-out infinite; }
.fms-loader-logo h2 { font-size: 1.8rem; font-weight: 800; letter-spacing: 0.02em; margin-bottom: 4px; }
.fms-loader-logo p  { font-size: 0.9rem; opacity: 0.8; margin-bottom: 20px; }
.fms-loader-bar  { width: 200px; height: 4px; background: rgba(255,255,255,0.3); border-radius: 2px; margin: 16px auto 0; overflow: hidden; }
.fms-loader-fill { height: 100%; width: 0; background: #fff; border-radius: 2px; animation: fms-load-bar 1.8s ease-in-out infinite; }

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

/* ── Sidebar ────────────────────────────────────────────── */
.fms-sidebar {
  width: var(--fms-sidebar-w);
  background: var(--fms-bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--fms-transition), width var(--fms-transition);
  z-index: 100;
  overflow: hidden;
}
.fms-sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.fms-sidebar-logo .fms-leaf { font-size: 1.5rem; }
.fms-sidebar-logo .fms-brand { color: #fff; font-size: 1.1rem; font-weight: 800; }
.fms-sidebar-logo .fms-brand small { display: block; font-size: 0.7rem; opacity: 0.6; font-weight: 400; }
.fms-sidebar-farm { padding: 12px 18px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.fms-sidebar-farm p { color: rgba(255,255,255,0.55); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; }
.fms-sidebar-farm strong { color: #fff; font-size: 0.9rem; }
.fms-sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.fms-sidebar-nav::-webkit-scrollbar { width: 4px; }
.fms-sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.fms-sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
.fms-nav-section { padding: 16px 18px 6px; font-size: 0.68rem; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 0.08em; }
.fms-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  color: rgba(255,255,255,0.78);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--fms-transition), color var(--fms-transition);
  border-left: 3px solid transparent;
  user-select: none;
}
.fms-nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.fms-nav-item.active { background: rgba(255,255,255,0.14); color: #fff; border-left-color: var(--fms-accent-light); font-weight: 600; }
.fms-nav-item .fms-nav-icon { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }
.fms-nav-badge { margin-left: auto; background: var(--fms-accent); color: #fff; font-size: 0.65rem; padding: 1px 6px; border-radius: 10px; font-weight: 700; }
.fms-sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.1); }
.fms-sidebar-user { display: flex; align-items: center; gap: 9px; }
.fms-user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--fms-primary-light); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; color: #fff; flex-shrink: 0; }
.fms-user-name   { color: #fff; font-size: 0.82rem; font-weight: 600; }
.fms-user-role   { color: rgba(255,255,255,0.5); font-size: 0.7rem; }
.fms-logout-btn  { margin-left: auto; background: none; border: none; color: rgba(255,255,255,0.5); cursor: pointer; font-size: 1rem; padding: 4px; transition: color var(--fms-transition); }
.fms-logout-btn:hover { color: var(--fms-accent-light); }

/* ── Main Content Area ──────────────────────────────────── */
.fms-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--fms-bg);
}

/* ── Topbar ─────────────────────────────────────────────── */
.fms-topbar {
  height: var(--fms-topbar-h);
  background: var(--fms-bg-card);
  border-bottom: 1px solid var(--fms-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.fms-topbar-left { display: flex; align-items: center; gap: 12px; flex: 1; }
.fms-page-title  { font-size: 1.1rem; font-weight: 700; color: var(--fms-text); }
.fms-topbar-right { display: flex; align-items: center; gap: 10px; }
.fms-topbar-btn {
  background: none; border: none; cursor: pointer;
  padding: 6px 8px; border-radius: var(--fms-radius-sm);
  color: var(--fms-text-muted); font-size: 1rem;
  position: relative; transition: background var(--fms-transition), color var(--fms-transition);
}
.fms-topbar-btn:hover { background: var(--fms-bg); color: var(--fms-primary); }
.fms-notification-dot {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fms-accent); border: 2px solid var(--fms-bg-card);
}

/* ── Content Scroll Area ────────────────────────────────── */
.fms-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.fms-content::-webkit-scrollbar { width: 6px; }
.fms-content::-webkit-scrollbar-thumb { background: var(--fms-border-dark); border-radius: 3px; }

/* ── Cards ──────────────────────────────────────────────── */
.fms-card {
  background: var(--fms-bg-card);
  border: 1px solid var(--fms-border);
  border-radius: var(--fms-radius);
  box-shadow: var(--fms-shadow);
  padding: 20px;
}
.fms-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.fms-card-title  { font-size: 1rem; font-weight: 700; color: var(--fms-text); }
.fms-card-subtitle { font-size: 0.8rem; color: var(--fms-text-muted); margin-top: 2px; }

/* ── KPI / Stat Cards ───────────────────────────────────── */
.fms-stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.fms-stat-card {
  background: var(--fms-bg-card); border: 1px solid var(--fms-border);
  border-radius: var(--fms-radius); padding: 18px 20px;
  box-shadow: var(--fms-shadow);
  display: flex; align-items: flex-start; gap: 14px;
  transition: box-shadow var(--fms-transition), transform var(--fms-transition);
  cursor: default;
}
.fms-stat-card:hover { box-shadow: var(--fms-shadow-hover); transform: translateY(-2px); }
.fms-stat-icon-wrap {
  width: 44px; height: 44px; border-radius: var(--fms-radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.fms-stat-icon-wrap.green  { background: #e8f5e9; }
.fms-stat-icon-wrap.amber  { background: #fff3e0; }
.fms-stat-icon-wrap.blue   { background: #e3f2fd; }
.fms-stat-icon-wrap.red    { background: #ffebee; }
.fms-stat-icon-wrap.teal   { background: #e0f2f1; }
.fms-stat-value  { font-size: 1.6rem; font-weight: 800; color: var(--fms-text); line-height: 1; }
.fms-stat-label  { font-size: 0.78rem; color: var(--fms-text-muted); margin-top: 4px; }
.fms-stat-trend  { font-size: 0.75rem; margin-top: 4px; font-weight: 600; }
.fms-stat-trend.up   { color: var(--fms-success); }
.fms-stat-trend.down { color: var(--fms-danger-light); }

/* ── Data Grids ─────────────────────────────────────────── */
.fms-grid { display: grid; gap: 20px; }
.fms-grid-2 { grid-template-columns: 1fr 1fr; }
.fms-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.fms-grid-auto { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* ── Tables ─────────────────────────────────────────────── */
.fms-table-wrap { overflow-x: auto; border-radius: var(--fms-radius); }
.fms-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.fms-table thead th {
  background: #f0f7f0; padding: 10px 14px;
  text-align: left; font-size: 0.75rem; font-weight: 700;
  color: var(--fms-primary-dark); text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 2px solid var(--fms-border);
  white-space: nowrap;
}
.fms-table tbody td { padding: 10px 14px; border-bottom: 1px solid var(--fms-border); vertical-align: middle; }
.fms-table tbody tr:last-child td { border-bottom: none; }
.fms-table tbody tr:hover { background: #f8fdf8; }
.fms-table-loading { padding: 40px; text-align: center; color: var(--fms-text-muted); font-size: 0.9rem; }
.fms-table-empty { padding: 48px 24px; text-align: center; color: var(--fms-text-muted); }
.fms-table-empty .fms-empty-icon { font-size: 2.5rem; margin-bottom: 12px; }

/* ── Badges / Tags ──────────────────────────────────────── */
.fms-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700; white-space: nowrap;
}
.fms-badge-green  { background: #e8f5e9; color: #2e7d32; }
.fms-badge-amber  { background: #fff3e0; color: #e65100; }
.fms-badge-red    { background: #ffebee; color: #c62828; }
.fms-badge-blue   { background: #e3f2fd; color: #0277bd; }
.fms-badge-grey   { background: #f5f5f5; color: #616161; }
.fms-badge-teal   { background: #e0f2f1; color: #00695c; }

/* ── Buttons ────────────────────────────────────────────── */
.fms-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--fms-radius-sm);
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  border: none; transition: background var(--fms-transition), box-shadow var(--fms-transition), transform var(--fms-transition);
  text-decoration: none; white-space: nowrap;
}
.fms-btn:active { transform: scale(0.97); }
.fms-btn-primary { background: var(--fms-primary); color: #fff; }
.fms-btn-primary:hover { background: var(--fms-primary-dark); box-shadow: 0 2px 8px rgba(45,125,50,0.3); }
.fms-btn-secondary { background: var(--fms-bg); color: var(--fms-text); border: 1px solid var(--fms-border); }
.fms-btn-secondary:hover { background: #f0f7f0; border-color: var(--fms-primary-light); }
.fms-btn-danger  { background: var(--fms-danger); color: #fff; }
.fms-btn-danger:hover  { background: #b71c1c; }
.fms-btn-accent  { background: var(--fms-accent); color: #fff; }
.fms-btn-accent:hover  { background: #e65100; }
.fms-btn-sm   { padding: 5px 12px; font-size: 0.8rem; }
.fms-btn-lg   { padding: 12px 28px; font-size: 1rem; }
.fms-btn-full { width: 100%; justify-content: center; }
.fms-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.fms-btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Forms ──────────────────────────────────────────────── */
.fms-form   { display: flex; flex-direction: column; gap: 16px; }
.fms-field  { display: flex; flex-direction: column; gap: 5px; }
.fms-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fms-form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
label.fms-field-label { font-size: 0.82rem; font-weight: 600; color: var(--fms-text-muted); }
.fms-input, .fms-select, .fms-textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--fms-border);
  border-radius: var(--fms-radius-sm); font-size: 0.9rem;
  font-family: var(--fms-font); color: var(--fms-text); background: #fff;
  transition: border-color var(--fms-transition), box-shadow var(--fms-transition);
  outline: none;
}
.fms-input:focus, .fms-select:focus, .fms-textarea:focus {
  border-color: var(--fms-primary);
  box-shadow: 0 0 0 3px rgba(45,125,50,0.12);
}
.fms-input:disabled { background: #f5f5f5; color: var(--fms-text-muted); cursor: not-allowed; }
.fms-textarea { min-height: 80px; resize: vertical; }
.fms-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%235f5f5f' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.fms-hint { font-size: 0.75rem; color: var(--fms-text-muted); }
.fms-required::after { content: ' *'; color: var(--fms-danger); }
.fms-input-group { display: flex; position: relative; }
.fms-input-group .fms-input { flex: 1; }
.fms-input-group .fms-input-addon {
  padding: 9px 12px; background: #f0f7f0; border: 1.5px solid var(--fms-border);
  border-left: none; border-radius: 0 var(--fms-radius-sm) var(--fms-radius-sm) 0;
  font-size: 0.85rem; color: var(--fms-text-muted); white-space: nowrap;
  display: flex; align-items: center;
}
.fms-input-group .fms-input { border-radius: var(--fms-radius-sm) 0 0 var(--fms-radius-sm); }

/* ── Alerts / Notices ───────────────────────────────────── */
.fms-notice {
  padding: 12px 16px; border-radius: var(--fms-radius-sm);
  font-size: 0.875rem; display: flex; align-items: flex-start; gap: 8px;
  border-left: 4px solid;
}
.fms-notice-success { background: #e8f5e9; border-color: var(--fms-success); color: #1b5e20; }
.fms-notice-error   { background: #ffebee; border-color: var(--fms-danger);  color: #7f0000; }
.fms-notice-warning { background: #fff3e0; border-color: var(--fms-warning); color: #bf360c; }
.fms-notice-info    { background: #e3f2fd; border-color: var(--fms-info);    color: #01579b; }
.fms-form-message { padding: 10px 14px; border-radius: var(--fms-radius-sm); font-size: 0.875rem; margin-bottom: 4px; }
.fms-form-message.fms-success { background: #e8f5e9; color: #1b5e20; }
.fms-form-message.fms-error   { background: #ffebee; color: #7f0000; }

/* ── Spinner ────────────────────────────────────────────── */
.fms-spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff; border-radius: 50%;
  animation: fms-spin 0.6s linear infinite; display: inline-block; vertical-align: middle;
}
.fms-spinner-dark { border-color: rgba(0,0,0,0.15); border-top-color: var(--fms-primary); }
.fms-spinner-lg   { width: 32px; height: 32px; border-width: 3px; }
.fms-spinner-wrap { display: flex; align-items: center; justify-content: center; padding: 48px; }

/* ── Modals ─────────────────────────────────────────────── */
.fms-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  animation: fms-fade-in 0.15s ease;
}
.fms-modal {
  background: var(--fms-bg-card); border-radius: var(--fms-radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-width: 600px; width: 100%; max-height: 90vh;
  display: flex; flex-direction: column;
  animation: fms-slide-up 0.2s ease;
}
.fms-modal-header {
  padding: 18px 22px 14px; border-bottom: 1px solid var(--fms-border);
  display: flex; align-items: center; justify-content: space-between;
}
.fms-modal-title { font-size: 1.05rem; font-weight: 700; }
.fms-modal-close { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--fms-text-muted); padding: 4px; border-radius: 4px; }
.fms-modal-close:hover { background: var(--fms-bg); color: var(--fms-text); }
.fms-modal-body   { padding: 20px 22px; overflow-y: auto; flex: 1; }
.fms-modal-footer { padding: 14px 22px; border-top: 1px solid var(--fms-border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Tabs ───────────────────────────────────────────────── */
.fms-tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--fms-border); margin-bottom: 20px; overflow-x: auto; }
.fms-tab {
  padding: 9px 18px; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: none; background: none;
  color: var(--fms-text-muted); transition: color var(--fms-transition);
  border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap;
}
.fms-tab:hover  { color: var(--fms-primary); }
.fms-tab.active { color: var(--fms-primary); border-bottom-color: var(--fms-primary); }

/* ── Search & Filter Bar ────────────────────────────────── */
.fms-toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}
.fms-search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 320px; }
.fms-search-wrap .fms-input { padding-left: 34px; }
.fms-search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--fms-text-muted); font-size: 0.9rem; pointer-events: none; }

/* ── Pagination ─────────────────────────────────────────── */
.fms-pagination { display: flex; align-items: center; gap: 6px; margin-top: 16px; justify-content: flex-end; }
.fms-page-btn { padding: 6px 12px; border-radius: var(--fms-radius-sm); border: 1px solid var(--fms-border); background: var(--fms-bg-card); cursor: pointer; font-size: 0.82rem; }
.fms-page-btn.active { background: var(--fms-primary); color: #fff; border-color: var(--fms-primary); }
.fms-page-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Auth Pages ─────────────────────────────────────────── */
.fms-auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8f5e9 0%, #f8fdf8 60%, #e0f2f1 100%);
  padding: 24px;
}
.fms-auth-card {
  background: #fff; border-radius: var(--fms-radius-lg); box-shadow: var(--fms-shadow-hover);
  padding: 36px 32px; width: 100%; max-width: 420px;
}
.fms-auth-header { text-align: center; margin-bottom: 28px; }
.fms-auth-logo   { font-size: 3rem; display: block; margin-bottom: 10px; }
.fms-auth-header h1 { font-size: 1.5rem; font-weight: 800; color: var(--fms-primary-dark); }
.fms-auth-header p  { color: var(--fms-text-muted); font-size: 0.88rem; margin-top: 4px; }
.fms-auth-footer { text-align: center; margin-top: 18px; font-size: 0.85rem; color: var(--fms-text-muted); }
.fms-link { color: var(--fms-primary); text-decoration: none; font-weight: 600; }
.fms-link:hover { text-decoration: underline; }

/* ── Chart Containers ───────────────────────────────────── */
.fms-chart-wrap { position: relative; min-height: 220px; }
.fms-chart-title { font-size: 0.85rem; font-weight: 700; color: var(--fms-text-muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Milk Table Row Colors ──────────────────────────────── */
.fms-milk-row-input input[type="number"] { width: 72px; padding: 5px 8px; border: 1.5px solid var(--fms-border); border-radius: var(--fms-radius-sm); font-size: 0.85rem; text-align: center; }
.fms-milk-row-input input:focus { border-color: var(--fms-primary); outline: none; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .fms-sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
  .fms-sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.2); }
  .fms-grid-2, .fms-grid-3 { grid-template-columns: 1fr; }
  .fms-form-row, .fms-form-row-3 { grid-template-columns: 1fr; }
  .fms-stats-grid { grid-template-columns: 1fr 1fr; }
  .fms-content { padding: 16px; }
}
@media (max-width: 480px) {
  .fms-stats-grid { grid-template-columns: 1fr; }
  .fms-auth-card { padding: 24px 18px; }
}
