/* ============================================
   FALI Design System — Forest & Sage
   ============================================ */

/* --- Design Tokens --- */
:root {
  --ds-bg-page: #f7f6f4;
  --ds-bg-card: #ffffff;
  --ds-bg-hover: #f2f1ef;
  --ds-bg-input: #ffffff;
  --ds-primary: #3d8b6e;
  --ds-primary-hover: #337a5f;
  --ds-primary-light: #edf4f0;
  --ds-text: #1a1a1a;
  --ds-text-muted: #888888;
  --ds-text-secondary: #6b6b6b;
  --ds-border: #e5e3e0;
  --ds-success: #3d8b6e;
  --ds-success-light: #edf4f0;
  --ds-danger: #c45c4a;
  --ds-danger-light: #fdf0ee;
  --ds-warning: #b8860b;
  --ds-warning-light: #fdf6e3;
  --ds-info: #4a7fa5;
  --ds-info-light: #eef5fa;
  --ds-radius-sm: 8px;
  --ds-radius-md: 12px;
  --ds-radius-lg: 16px;
  --ds-shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --ds-shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --ds-shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  --ds-font: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* --- Base --- */
.ds-page {
  background: var(--ds-bg-page);
  color: var(--ds-text);
  font-family: var(--ds-font);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.ds-page *, .ds-page *::before, .ds-page *::after { box-sizing: border-box; }

/* Typography */
.ds-h1 { font-size: 24px; font-weight: 800; color: var(--ds-text); line-height: 1.3; margin: 0; }
.ds-h2 { font-size: 20px; font-weight: 800; color: var(--ds-text); line-height: 1.3; margin: 0; }
.ds-h3 { font-size: 16px; font-weight: 700; color: var(--ds-text); line-height: 1.4; margin: 0; }
.ds-label {
  font-size: 11px; font-weight: 700; color: var(--ds-text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.ds-muted { color: var(--ds-text-muted); }
.ds-container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.ds-page a { color: inherit; text-decoration: none; }

/* --- Navigation --- */
.ds-nav {
  background: var(--ds-bg-card);
  border-radius: var(--ds-radius-lg);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--ds-shadow-sm);
  margin-bottom: 24px;
}
.ds-nav-logo {
  width: 32px; height: 32px;
  background: var(--ds-primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.ds-nav-logo svg { width: 18px; height: 18px; color: white; }
.ds-nav-brand { font-weight: 800; font-size: 17px; color: var(--ds-text); }
.ds-nav-links { margin-left: auto; display: flex; gap: 2px; }
.ds-nav-link {
  font-size: 13px; font-weight: 600; color: var(--ds-text-muted);
  padding: 6px 14px; border-radius: var(--ds-radius-sm);
  transition: all 0.15s; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.ds-nav-link svg { width: 15px; height: 15px; }
.ds-nav-link:hover { background: var(--ds-bg-hover); color: var(--ds-text); }
.ds-nav-link.active { background: var(--ds-primary-light); color: var(--ds-primary); }
.ds-nav-user { margin-left: 12px; display: flex; align-items: center; gap: 10px; }
.ds-avatar {
  width: 32px; height: 32px;
  background: var(--ds-primary-light); color: var(--ds-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
}

/* --- Buttons --- */
.ds-btn {
  font-family: var(--ds-font); font-size: 13px; font-weight: 700;
  padding: 9px 20px; border-radius: var(--ds-radius-sm);
  border: none; cursor: pointer; transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; line-height: 1.4;
}
.ds-btn svg { width: 16px; height: 16px; }
.ds-btn-primary { background: var(--ds-primary); color: white; }
.ds-btn-primary:hover { background: var(--ds-primary-hover); box-shadow: var(--ds-shadow-md); transform: translateY(-1px); }
.ds-btn-outline { background: transparent; color: var(--ds-text); border: 1.5px solid var(--ds-border); }
.ds-btn-outline:hover { border-color: var(--ds-primary); color: var(--ds-primary); background: var(--ds-primary-light); }
.ds-btn-danger { background: var(--ds-danger); color: white; }
.ds-btn-danger:hover { opacity: 0.9; }
.ds-btn-ghost { background: transparent; color: var(--ds-text-muted); }
.ds-btn-ghost:hover { background: var(--ds-bg-hover); color: var(--ds-text); }
.ds-btn-sm { font-size: 12px; padding: 6px 14px; }
.ds-btn-full { width: 100%; justify-content: center; }

/* --- Stat Cards --- */
.ds-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.ds-stat-card {
  background: var(--ds-bg-card); border-radius: var(--ds-radius-md);
  padding: 20px; box-shadow: var(--ds-shadow-sm); transition: box-shadow 0.15s;
}
.ds-stat-card:hover { box-shadow: var(--ds-shadow-md); }
.ds-stat-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.ds-stat-icon svg { width: 18px; height: 18px; }
.ds-stat-icon-green { background: var(--ds-success-light); color: var(--ds-success); }
.ds-stat-icon-blue { background: var(--ds-info-light); color: var(--ds-info); }
.ds-stat-icon-amber { background: var(--ds-warning-light); color: var(--ds-warning); }
.ds-stat-value { font-size: 28px; font-weight: 800; color: var(--ds-text); margin: 4px 0; }
.ds-stat-change { font-size: 12px; font-weight: 600; }
.ds-stat-change-up { color: var(--ds-success); }
.ds-stat-change-down { color: var(--ds-danger); }

/* --- Card (generic) --- */
.ds-card {
  background: var(--ds-bg-card); border-radius: var(--ds-radius-md);
  padding: 24px; box-shadow: var(--ds-shadow-sm);
}

/* --- Badges --- */
.ds-badge {
  font-family: var(--ds-font); font-size: 11px; font-weight: 700;
  padding: 4px 10px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 4px;
}
.ds-badge svg { width: 12px; height: 12px; }
.ds-badge-success { background: var(--ds-success-light); color: var(--ds-success); }
.ds-badge-danger { background: var(--ds-danger-light); color: var(--ds-danger); }
.ds-badge-warning { background: var(--ds-warning-light); color: var(--ds-warning); }
.ds-badge-info { background: var(--ds-info-light); color: var(--ds-info); }
.ds-badge-neutral { background: #eeeeee; color: #666666; }

/* --- Alerts --- */
.ds-alert {
  padding: 14px 18px; border-radius: var(--ds-radius-md);
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.ds-alert svg { width: 18px; height: 18px; flex-shrink: 0; }
.ds-alert-success { background: var(--ds-success-light); color: var(--ds-success); }
.ds-alert-danger { background: var(--ds-danger-light); color: var(--ds-danger); }
.ds-alert-warning { background: var(--ds-warning-light); color: var(--ds-warning); }
.ds-alert-info { background: var(--ds-info-light); color: var(--ds-info); }

/* --- Tables --- */
.ds-table-container {
  background: var(--ds-bg-card); border-radius: var(--ds-radius-md);
  box-shadow: var(--ds-shadow-sm); overflow-y: hidden;
  overflow-x: auto; /* Allow horizontal scroll on mobile */
  -webkit-overflow-scrolling: touch;
}
.ds-table { width: 100%; border-collapse: collapse; }
.ds-table th {
  font-size: 11px; font-weight: 700; color: var(--ds-text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 14px 18px; text-align: left;
  background: #fafaf8; border-bottom: 2px solid var(--ds-border);
}
.ds-table td {
  padding: 14px 18px; font-size: 13px;
  border-bottom: 1px solid #f0efed; color: var(--ds-text);
}
.ds-table tr:hover td { background: #fafaf8; }
.ds-table tr:last-child td { border-bottom: none; }
.ds-table .ds-bold { font-weight: 700; }

/* --- Forms --- */
.ds-form-group { margin-bottom: 16px; }
.ds-form-label {
  display: block; font-size: 13px; font-weight: 700;
  color: var(--ds-text); margin-bottom: 6px;
}
.ds-form-hint { font-size: 12px; color: var(--ds-text-muted); margin-bottom: 6px; }
.ds-form-input {
  width: 100%; font-family: var(--ds-font); font-size: 14px;
  padding: 10px 14px; border: 1.5px solid var(--ds-border);
  border-radius: var(--ds-radius-sm); background: var(--ds-bg-input);
  color: var(--ds-text); transition: all 0.15s;
}
.ds-form-input:focus {
  outline: none; border-color: var(--ds-primary);
  box-shadow: 0 0 0 3px rgba(61,139,110,0.1);
}
.ds-form-input::placeholder { color: #bbb; }
.ds-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --- Progress Bar --- */
.ds-progress-container {
  width: 100%; height: 4px;
  background: var(--ds-border); border-radius: 2px;
  overflow: hidden;
}
.ds-progress-bar {
  height: 100%; background: var(--ds-primary);
  transition: width 0.3s ease; border-radius: 2px;
}
.ds-progress-bar.ds-progress-complete { background: var(--ds-success); }

/* --- Mobile Bottom Tab Bar --- */
.ds-tab-bar {
  display: none; /* Hidden on desktop */
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--ds-bg-card);
  border-top: 1px solid var(--ds-border);
  padding: 6px 0 env(safe-area-inset-bottom, 8px);
  z-index: 100;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}
.ds-tab-bar nav {
  display: flex;
  justify-content: space-around;
  max-width: 500px;
  margin: 0 auto;
}
.ds-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  font-size: 10px;
  font-weight: 700;
  color: var(--ds-text-muted);
  text-decoration: none;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.ds-tab svg { width: 20px; height: 20px; }
.ds-tab.active { color: var(--ds-primary); }
.ds-tab:hover { color: var(--ds-primary); }

/* Two-column to single-column */
.ds-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 768px) {
  .ds-grid-2col { grid-template-columns: 1fr; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .ds-nav-links { display: none; }
  .ds-nav-user { margin-left: auto; }
  .ds-stats-grid { grid-template-columns: 1fr 1fr; }
  .ds-form-row { grid-template-columns: 1fr; }
  .ds-tab-bar { display: block; }
  body { padding-bottom: 70px; } /* Space for fixed tab bar */
}

/* Mobile touch targets */
@media (max-width: 768px) {
  .ds-btn { min-height: 44px; padding: 10px 20px; }
  .ds-btn-sm { min-height: 36px; }
  .ds-form-input { min-height: 44px; font-size: 16px; } /* 16px prevents iOS zoom on focus */
  .ds-nav { padding: 10px 16px; border-radius: var(--ds-radius-md); }
  .ds-card { padding: 16px; }
  .ds-table td, .ds-table th { padding: 10px 12px; font-size: 12px; }
  .ds-table { min-width: 500px; } /* Forces horizontal scroll rather than crushing columns */
  .filter-bar {
    flex-direction: column;
    gap: 8px;
  }
  .filter-bar select,
  .filter-bar input[type="text"],
  .filter-bar input[type="date"] {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .ds-stats-grid { grid-template-columns: 1fr; }
  .ds-container { padding: 0 16px; }
}
