/* ═══════════════════════════════════════════════════
   RICE DOCTOR — Platform CSS
   Extracted from APIT_Rice_Intelligence_Platform_Complete.html
═══════════════════════════════════════════════════ */
:root {
  --brand-50: #EFF6FF; --brand-100: #DBEAFE; --brand-200: #BFDBFE;
  --brand-300: #93C5FD; --brand-400: #60A5FA; --brand-500: #3B82F6;
  --brand-600: #2563EB; --brand-700: #1D4ED8; --brand-800: #1E3A5F;
  --brand-900: #0F172A;
  --green-50: #F0FDF4; --green-100: #DCFCE7; --green-500: #22C55E; --green-600: #16A34A; --green-700: #15803D;
  --orange-50: #FFF7ED; --orange-500: #F97316; --orange-600: #EA580C;
  --red-50: #FEF2F2; --red-500: #EF4444; --red-600: #DC2626;
  --purple-50: #FAF5FF; --purple-500: #A855F7; --purple-600: #9333EA;
  --teal-50: #F0FDFA; --teal-500: #14B8A6; --teal-600: #0D9488;
  --yellow-50: #FEFCE8; --yellow-500: #EAB308;
  --slate-50: #F8FAFC; --slate-100: #F1F5F9; --slate-200: #E2E8F0;
  --slate-300: #CBD5E1; --slate-400: #94A3B8; --slate-500: #64748B;
  --slate-600: #475569; --slate-700: #334155; --slate-800: #1E293B; --slate-900: #0F172A;
  --white: #FFFFFF;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --shadow-xl: 0 20px 25px rgba(0,0,0,.1), 0 8px 10px rgba(0,0,0,.04);
  --r: 8px; --r-lg: 12px; --r-xl: 16px; --r-2xl: 20px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --nav-w: 270px; --header-h: 56px;
  --transition: all 0.2s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); font-size: 14px; line-height: 1.6; color: var(--slate-800); background: var(--slate-100); -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 3px; }

/* IP Protection */
.module-page { user-select: none; -webkit-user-select: none; }
.module-page input, .module-page select, .module-page textarea { user-select: text; -webkit-user-select: text; }

/* ═══ LOGIN SCREEN ═══ */
.login-screen {
  display: flex; height: 100vh;
  background: linear-gradient(135deg, var(--brand-900) 0%, var(--brand-800) 50%, #1a365d 100%);
  position: relative; overflow: hidden;
}
.login-screen::before {
  content: ''; position: absolute; top: -50%; right: -20%; width: 800px; height: 800px;
  background: radial-gradient(circle, rgba(59,130,246,.15) 0%, transparent 70%); border-radius: 50%;
}
.login-screen::after {
  content: ''; position: absolute; bottom: -30%; left: -10%; width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(34,197,94,.08) 0%, transparent 70%); border-radius: 50%;
}
.login-left { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 60px 80px; position: relative; z-index: 1; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 48px; }
.login-logo {
  width: 56px; height: 56px; background: linear-gradient(135deg, var(--brand-500), var(--teal-500));
  border-radius: 16px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: white; font-weight: 800; box-shadow: 0 4px 16px rgba(59,130,246,.4); letter-spacing: 1px;
}
.login-brand-text h1 { font-size: 28px; font-weight: 800; color: white; letter-spacing: -.5px; }
.login-brand-text span { font-size: 11px; color: var(--brand-300); font-weight: 600; letter-spacing: 2px; text-transform: uppercase; display: block; margin-top: 2px; }
.login-tagline { font-size: 46px; font-weight: 800; color: white; line-height: 1.15; letter-spacing: -1.5px; margin-bottom: 18px; }
.login-tagline em { font-style: normal; background: linear-gradient(135deg, var(--brand-400), var(--teal-400)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-sub { font-size: 16px; color: var(--slate-400); line-height: 1.8; max-width: 520px; }
.login-modules { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 40px; max-width: 520px; }
.login-mod { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: var(--r-lg); color: var(--slate-300); font-size: 13px; font-weight: 500; transition: var(--transition); }
.login-mod:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.2); }
.login-mod-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.login-right { width: 480px; display: flex; align-items: center; justify-content: center; padding: 40px; position: relative; z-index: 1; }
.login-card { width: 100%; max-width: 400px; background: var(--white); border-radius: var(--r-2xl); padding: 40px; box-shadow: var(--shadow-xl); }
.login-card h2 { font-size: 24px; font-weight: 700; color: var(--slate-900); margin-bottom: 6px; }
.login-card .login-card-sub { font-size: 14px; color: var(--slate-500); margin-bottom: 30px; }
.login-field { margin-bottom: 18px; }
.login-field label { display: block; font-size: 12px; font-weight: 600; color: var(--slate-700); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.login-field input, .login-field select {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--slate-200); border-radius: var(--r);
  font-family: var(--font); font-size: 14px; color: var(--slate-800); background: var(--slate-50); transition: var(--transition); outline: none;
}
.login-field input:focus, .login-field select:focus { border-color: var(--brand-500); background: var(--white); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.login-btn {
  width: 100%; padding: 13px; background: linear-gradient(135deg, var(--brand-600), var(--brand-700));
  color: white; border: none; border-radius: var(--r); font-family: var(--font); font-size: 15px;
  font-weight: 600; cursor: pointer; transition: var(--transition); margin-top: 8px; letter-spacing: .3px;
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37,99,235,.4); }
.login-version { text-align: center; margin-top: 24px; font-size: 10px; color: var(--slate-300); letter-spacing: .5px; }

/* ═══ APP SHELL ═══ */
.shell { display: flex; height: 100vh; }
.sidebar {
  width: var(--nav-w); background: var(--white); border-right: 1px solid var(--slate-200);
  display: flex; flex-direction: column; flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.sidebar-brand { padding: 18px 20px; border-bottom: 1px solid var(--slate-100); display: flex; align-items: center; gap: 12px; }
.sidebar-logo {
  width: 40px; height: 40px; background: linear-gradient(135deg, var(--brand-600), var(--brand-800));
  border-radius: 11px; display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: white; font-weight: 800; flex-shrink: 0; box-shadow: 0 2px 8px rgba(59,130,246,.3); letter-spacing: .5px;
}
.sidebar-logo-img { width: 40px; height: 40px; border-radius: 8px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand-text h2 { font-size: 16px; font-weight: 700; color: var(--slate-900); letter-spacing: -.3px; }
.sidebar-brand-text span { font-size: 10px; color: var(--brand-500); font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.nav-scroll { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-section { padding: 12px 14px 4px; }
.nav-section-title { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; color: var(--slate-400); padding: 0 8px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 14px; margin: 2px 8px;
  border-radius: var(--r); cursor: pointer; color: var(--slate-600); font-size: 13px;
  font-weight: 500; transition: var(--transition); border: 1px solid transparent; user-select: none;
}
.nav-item:hover { background: var(--slate-50); color: var(--slate-800); }
.nav-item.active { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); font-weight: 600; }
.nav-item .nav-icon {
  width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center;
  justify-content: center; font-size: 14px; flex-shrink: 0;
}
.nav-item .nav-label { flex: 1; }
.nav-item .nav-tag { font-size: 9px; font-weight: 700; padding: 2px 7px; border-radius: 10px; text-transform: uppercase; letter-spacing: .3px; }
.nav-divider { height: 1px; background: var(--slate-100); margin: 8px 16px; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid var(--slate-100); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.sidebar-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--brand-500), var(--purple-500));
  display: flex; align-items: center; justify-content: center; color: white; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--slate-700); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 10px; color: var(--slate-400); font-weight: 500; }
.sidebar-logout {
  width: 32px; height: 32px; border-radius: 8px; background: none; border: 1px solid var(--slate-200);
  color: var(--slate-400); cursor: pointer; font-size: 14px; display: flex; align-items: center;
  justify-content: center; transition: var(--transition); flex-shrink: 0;
}
.sidebar-logout:hover { color: var(--red-500); border-color: var(--red-200); background: var(--red-50); }

/* ═══ MAIN ═══ */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  height: var(--header-h); border-bottom: 1px solid var(--slate-200); background: var(--white);
  display: flex; align-items: center; padding: 0 24px; gap: 16px; flex-shrink: 0;
}
.topbar-title { font-size: 17px; font-weight: 700; color: var(--slate-900); letter-spacing: -.3px; }
.topbar-breadcrumb { font-size: 12px; color: var(--slate-400); font-weight: 500; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.topbar-chip { padding: 5px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; display: flex; align-items: center; gap: 5px; }
.topbar-chip.online { background: var(--green-50); color: var(--green-700); border: 1px solid var(--green-100); }
.topbar-chip.online::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--green-500); }

/* ═══ CONTENT ═══ */
.content-area { flex: 1; overflow: hidden; position: relative; }

/* Dashboard page */
.dashboard-page { height: 100%; overflow-y: auto; padding: 28px; background: var(--slate-50); display: none; }
.dashboard-page.active { display: block; }

/* iframe modules */
.module-frame { width: 100%; height: 100%; border: none; display: none; background: white; }
.module-frame.active { display: block; }

/* Open in new tab button */
.topbar-newtab {
  padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: var(--transition);
  background: var(--slate-50); border: 1px solid var(--slate-200); color: var(--slate-600);
  display: none; align-items: center; gap: 5px; text-decoration: none;
}
.topbar-newtab.visible { display: inline-flex; }
.topbar-newtab:hover { background: var(--brand-50); border-color: var(--brand-300); color: var(--brand-600); }

/* Legacy module page (for dynamic loading fallback) */
.module-page { padding: 28px; display: none; background: var(--slate-50); overflow-y: auto; height: 100%; }
.module-page:first-of-type { display: block; }

/* Loading overlay */
.loading-overlay {
  position: absolute; inset: 0; background: rgba(248,250,252,.85); display: none;
  align-items: center; justify-content: center; z-index: 100;
}
.loading-overlay.active { display: flex; }
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--slate-200); border-top-color: var(--brand-500);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1024px) {
  .sidebar { width: 64px; min-width: 64px; }
  .sidebar-brand-text, .nav-section-title, .nav-label, .nav-tag, .sidebar-user-info { display: none; }
  .sidebar-brand { justify-content: center; padding: 14px 8px; }
  .nav-item { justify-content: center; margin: 2px 4px; padding: 10px; }
  .sidebar-footer { justify-content: center; padding: 14px 8px; }
  .sidebar-logout { display: none; }
  .login-left { display: none; }
  .login-right { width: 100%; }
}

/* ═══ TAB NAVIGATION ═══ */
.rd-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--slate-200); margin-bottom: 24px; padding-bottom: 0; overflow-x: auto; }
.rd-tab {
  padding: 10px 18px; font-size: 13px; font-weight: 600; color: var(--slate-500); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px; transition: var(--transition);
  white-space: nowrap; user-select: none;
}
.rd-tab:hover { color: var(--slate-700); background: var(--slate-50); border-radius: 6px 6px 0 0; }
.rd-tab.active { color: var(--brand-600); border-bottom-color: var(--brand-600); }
.rd-tab-content { display: none; }
.rd-tab-content.active { display: block; }

/* ═══ UTILITY CLASSES ═══ */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 28px; }
.kpi {
  background: var(--white); border-radius: var(--r-lg); border: 1px solid var(--slate-200);
  padding: 20px; box-shadow: var(--shadow-sm); border-top: 3px solid var(--brand-500); transition: var(--transition);
}
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--slate-500); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.kpi-value { font-size: 30px; font-weight: 800; color: var(--slate-900); letter-spacing: -.5px; }
.kpi-unit { font-size: 13px; font-weight: 400; color: var(--slate-500); margin-left: 2px; }
.module-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.module-card {
  background: var(--white); border-radius: var(--r-lg); border: 1px solid var(--slate-200);
  padding: 24px; box-shadow: var(--shadow-sm); transition: var(--transition); cursor: pointer;
}
.module-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); border-color: var(--brand-300); }
.module-card-icon {
  width: 48px; height: 48px; border-radius: var(--r-lg); display: flex; align-items: center;
  justify-content: center; font-size: 22px; margin-bottom: 14px;
}
.module-card h3 { font-size: 16px; font-weight: 700; color: var(--slate-800); margin-bottom: 6px; }
.module-card p { font-size: 13px; color: var(--slate-500); line-height: 1.6; }
.mc-tag { display: inline-block; margin-top: 12px; font-size: 10px; font-weight: 600; padding: 3px 10px; border-radius: 10px; text-transform: uppercase; letter-spacing: .3px; }

/* ═══ FORM ELEMENTS (shared across modules) ═══ */
.rd-field { margin-bottom: 16px; }
.rd-field label { display: block; font-size: 12px; font-weight: 600; color: var(--slate-600); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px; }
.rd-field select, .rd-field input[type="number"], .rd-field input[type="range"] {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--slate-200); border-radius: var(--r);
  font-family: var(--font); font-size: 14px; color: var(--slate-800); background: var(--white); outline: none; transition: var(--transition);
}
.rd-field select:focus, .rd-field input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.rd-btn {
  padding: 10px 20px; background: var(--brand-600); color: white; border: none; border-radius: var(--r);
  font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: var(--transition);
}
.rd-btn:hover { background: var(--brand-700); transform: translateY(-1px); }
.rd-result {
  background: var(--white); border: 1px solid var(--slate-200); border-radius: var(--r-lg);
  padding: 20px; margin-top: 16px;
}

/* ═══ TRIAL COUNTDOWN CHIP (shell topbar) ═══ */
.trial-chip {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #fde68a;
}
.trial-chip.show { display: inline-flex; }
.trial-chip-countdown {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-weight: 700;
  color: #78350f;
  background: #fffbe6;
  padding: 2px 8px;
  border-radius: 4px;
  letter-spacing: .5px;
}
.trial-chip-expired {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid #fecaca;
}
.trial-chip-expired.show { display: inline-flex; }
