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

:root {
  --white: #ffffff;
  --off-white: #f8f9fa;
  --gray-50: #f1f3f5;
  --gray-100: #e9ecef;
  --gray-200: #dee2e6;
  --gray-400: #adb5bd;
  --gray-600: #6c757d;
  --gray-800: #343a40;
  --gray-900: #212529;
  --green-50: #e6f7ed;
  --green-100: #b3e8cb;
  --green-500: #1a7a42;
  --green-600: #14633a;
  --green-700: #0e4d2e;
  --accent: #1a7a42;
  --accent-light: #e6f7ed;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow: 0 4px 20px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.08);
  --transition: 0.2s ease;
}

body {
  font-family: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--gray-900);
  background: var(--off-white);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  direction: rtl;
  min-height: 100vh;
}

p { color: var(--gray-600); }
a { color: inherit; text-decoration: none; }
code { font-family: 'SF Mono', 'Menlo', monospace; font-size: 0.82rem; direction: ltr; display: inline-block; }

.btn {
  display: inline-block; padding: 12px 28px; border-radius: 8px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  border: 2px solid transparent; font-family: inherit; transition: all var(--transition);
}
.btn-sm { padding: 8px 18px; font-size: 0.85rem; }
.btn-primary { background: var(--accent); color: var(--white); border-color: var(--accent); }
.btn-primary:hover { background: var(--green-600); }
.btn-outline { background: transparent; color: var(--gray-600); border-color: var(--gray-200); }
.btn-outline:hover { border-color: var(--gray-800); color: var(--gray-900); }
.btn-full { width: 100%; text-align: center; }

/* ===== LOGIN SCREEN ===== */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--white) 0%, var(--green-50) 40%, var(--off-white) 100%);
}

.login-card {
  width: 100%; max-width: 420px;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.2rem;
  margin-bottom: 28px;
}

.login-card h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; }
.login-sub { font-size: 0.95rem; margin-bottom: 28px; }

.input-group { margin-bottom: 18px; }
.input-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--gray-800); margin-bottom: 6px; }
.input-group input {
  width: 100%; padding: 12px 16px;
  border: 1.5px solid var(--gray-200); border-radius: 8px;
  font-size: 0.95rem; font-family: inherit;
  transition: border-color var(--transition);
  background: var(--off-white);
}
.input-group input:focus { outline: none; border-color: var(--accent); background: var(--white); }
.input-group input[dir="ltr"] { text-align: left; }

.login-error { color: #c4534a; font-size: 0.85rem; margin-bottom: 12px; font-weight: 500; }

/* Auth Tabs */
.auth-tabs {
  display: flex; gap: 0; margin-bottom: 24px;
  background: var(--off-white); border-radius: 8px; padding: 3px;
}
.auth-tab {
  flex: 1; padding: 10px; border: none; background: none;
  font-family: inherit; font-size: 0.9rem; font-weight: 500;
  color: var(--gray-400); cursor: pointer; border-radius: 6px;
  transition: all var(--transition);
}
.auth-tab.active { background: var(--white); color: var(--gray-900); box-shadow: var(--shadow-sm); font-weight: 600; }

.auth-form { min-height: 0; }
.auth-error { color: #c4534a; font-size: 0.85rem; margin-bottom: 12px; font-weight: 500; }
.auth-success { color: var(--accent); font-size: 0.85rem; margin-bottom: 12px; font-weight: 500; }

.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0; color: var(--gray-400); font-size: 0.82rem;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--gray-100);
}

.login-demo {
  margin-top: 0; padding-top: 0;
}
.login-demo > p { font-size: 0.8rem; color: var(--gray-400); margin-bottom: 12px; }

.demo-accounts { display: flex; flex-direction: column; gap: 8px; }
.demo-btn {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-radius: 8px;
  border: 1px solid var(--gray-100); background: var(--off-white);
  cursor: pointer; font-family: inherit; transition: all var(--transition);
}
.demo-btn:hover { border-color: var(--accent); background: var(--accent-light); }
.demo-name { font-size: 0.88rem; font-weight: 500; color: var(--gray-800); }
.demo-id { font-size: 0.8rem; color: var(--gray-400); direction: ltr; }

.login-back {
  display: block; text-align: center;
  margin-top: 20px; font-size: 0.85rem; color: var(--gray-400);
  transition: color var(--transition);
}
.login-back:hover { color: var(--accent); }

/* ===== DASHBOARD ===== */
.dashboard { background: var(--off-white); min-height: 100vh; }

.dash-header {
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  padding: 14px 0;
  position: sticky; top: 0; z-index: 50;
}
.dash-header-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between;
}
.dash-logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.1rem;
}
.dash-user { display: flex; align-items: center; gap: 12px; }
.dash-user-name { font-size: 0.9rem; font-weight: 600; color: var(--gray-800); }
.dash-user-email { font-size: 0.78rem; color: var(--gray-400); direction: ltr; }

.dash-main { max-width: 1200px; margin: 0 auto; padding: 32px 28px 64px; }

/* Welcome */
.dash-welcome {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 32px; flex-wrap: wrap; gap: 16px;
}
.dash-welcome h1 { font-size: 1.6rem; font-weight: 700; margin-bottom: 6px; }
.dash-subtitle { font-size: 0.9rem; color: var(--gray-400); direction: ltr; text-align: right; }
.dash-badge {
  padding: 6px 18px; border-radius: 20px;
  font-size: 0.85rem; font-weight: 700;
  border: 1.5px solid;
}

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 36px; }
.kpi-card {
  background: var(--white); border-radius: var(--radius-lg);
  padding: 24px; border: 1px solid var(--gray-100);
  display: flex; flex-direction: column; gap: 4px;
  transition: all var(--transition);
}
.kpi-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kpi-highlight { border-color: var(--green-100); background: var(--green-50); }
.kpi-icon { margin-bottom: 4px; }
.kpi-label { font-size: 0.8rem; color: var(--gray-400); font-weight: 500; }
.kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--gray-900); direction: ltr; text-align: right; }
.kpi-value-sm { font-size: 1.1rem; }
.kpi-highlight .kpi-value { color: var(--accent); }

/* Sections */
.dash-section { margin-bottom: 36px; }
.section-header { margin-bottom: 20px; }
.section-header h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.section-desc { font-size: 0.88rem; }

/* Batch Cards */
.batch-card {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-100);
  margin-bottom: 20px;
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.batch-card:hover { box-shadow: var(--shadow); }

.batch-header {
  padding: 24px 28px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--gray-100);
  flex-wrap: wrap; gap: 16px;
}
.batch-id-row { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.batch-id {
  font-weight: 700; font-size: 1rem; color: var(--accent);
  background: var(--accent-light); padding: 4px 12px; border-radius: 6px;
  direction: ltr; display: inline-block;
}
.batch-count { font-size: 0.85rem; color: var(--gray-400); font-weight: 500; }
.batch-date { font-size: 0.82rem; color: var(--gray-400); }

.batch-stats { display: flex; gap: 24px; }
.batch-stat { display: flex; flex-direction: column; align-items: center; }
.batch-stat-num { font-size: 1.2rem; font-weight: 700; color: var(--gray-900); }
.batch-stat-label { font-size: 0.75rem; color: var(--gray-400); }

/* Cow Table */
.cow-table-wrap { overflow-x: auto; }
.cow-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 800px; }
.cow-table th {
  text-align: right; padding: 12px 16px;
  font-size: 0.78rem; font-weight: 600; color: var(--gray-400);
  text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--off-white); border-bottom: 1px solid var(--gray-100);
}
.cow-table td {
  padding: 14px 16px; border-bottom: 1px solid var(--gray-50);
  vertical-align: middle;
}
.cow-table tr:last-child td { border-bottom: none; }
.cow-table tr:hover td { background: var(--green-50); }

.cow-name-cell { display: flex; align-items: center; gap: 8px; }
.cow-mini-icon { flex-shrink: 0; }

.chip-code {
  background: var(--gray-50); padding: 2px 8px; border-radius: 4px;
  font-size: 0.78rem; color: var(--gray-600);
}

.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 0.78rem; font-weight: 600;
}
.status-active { background: var(--green-50); color: var(--accent); }
.status-pregnant { background: #fef3e2; color: #b8860b; }
.status-dry { background: var(--gray-50); color: var(--gray-600); }

.health-badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 0.78rem; font-weight: 500;
}
.health-excellent { color: var(--accent); }
.health-good { color: var(--gray-600); }

/* Revenue Card */
.revenue-card {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-100); padding: 28px;
}

.rev-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.rev-header h3 { font-size: 1.1rem; font-weight: 700; }
.rev-tier { font-size: 0.85rem; margin-top: 4px; }
.rev-return-badge {
  background: var(--green-50); color: var(--accent);
  padding: 8px 18px; border-radius: 20px;
  font-size: 0.9rem; font-weight: 700;
}

.rev-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.rev-item {
  padding: 16px; border-radius: var(--radius);
  background: var(--off-white); text-align: center;
}
.rev-label { display: block; font-size: 0.78rem; color: var(--gray-400); font-weight: 500; margin-bottom: 6px; }
.rev-value { display: block; font-size: 1.1rem; font-weight: 700; color: var(--gray-900); direction: ltr; }
.rev-green { color: var(--accent); }
.rev-gray { color: var(--gray-400); }
.rev-green-bold { color: var(--accent); font-size: 1.3rem; }

.rev-bar-section { margin-top: 8px; }
.rev-bar-labels { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--gray-400); margin-bottom: 6px; }
.rev-bar-track { height: 12px; background: var(--gray-100); border-radius: 6px; overflow: hidden; }
.rev-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--green-100)); border-radius: 6px; transition: width 0.8s ease; }
.rev-bar-pct { font-size: 0.82rem; color: var(--gray-400); margin-top: 6px; text-align: left; direction: ltr; }

/* Chart */
.chart-container {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-100); padding: 28px;
  overflow-x: auto;
}
.chart-bars {
  display: flex; align-items: flex-end; gap: 12px;
  height: 240px; min-width: 500px;
  padding-top: 40px;
}
.chart-bar-group {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end;
  position: relative; height: 100%;
}
.chart-bar {
  width: 100%; max-width: 48px;
  background: linear-gradient(180deg, var(--accent), var(--green-100));
  border-radius: 6px 6px 0 0;
  transition: height 0.6s ease;
  min-height: 4px;
}
.chart-bar-group:hover .chart-bar { opacity: 0.8; }
.chart-tooltip {
  position: absolute; top: -8px;
  font-size: 0.72rem; color: var(--gray-400); font-weight: 500;
  white-space: nowrap; direction: ltr;
  opacity: 0; transition: opacity 0.2s;
}
.chart-bar-group:hover .chart-tooltip { opacity: 1; }
.chart-label {
  font-size: 0.7rem; color: var(--gray-400);
  margin-top: 8px; white-space: nowrap;
}

/* New User Welcome */
.new-user-card {
  background: var(--white); border-radius: var(--radius-lg);
  border: 1px solid var(--gray-100); padding: 48px 36px;
  text-align: center; margin-bottom: 36px;
}
.new-user-icon { margin-bottom: 20px; }
.new-user-card h2 { font-size: 1.4rem; margin-bottom: 12px; }
.new-user-card p { font-size: 0.95rem; margin-bottom: 12px; max-width: 500px; margin-left: auto; margin-right: auto; line-height: 1.8; }
.new-user-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 24px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .rev-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .login-card { padding: 28px 24px; }
  .dash-main { padding: 20px 16px 48px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .rev-grid { grid-template-columns: 1fr; }
  .batch-header { flex-direction: column; }
  .dash-welcome { flex-direction: column; }
  .dash-welcome h1 { font-size: 1.3rem; }
}
