/* ============================================
   MirFi — Design System
   Powered by Mirjy Technologies Ltd.
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --bg-primary: #09090b;
  --bg-secondary: #111114;
  --bg-card: rgba(24,24,27,0.9);
  --bg-glass: rgba(255,255,255,0.03);
  --border-color: rgba(255,255,255,0.06);
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent: #7c6cf0;
  --accent-light: #a78bfa;
  --accent-purple: #6c5ce7;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --sidebar-width: 248px;
  --topbar-height: 60px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --transition: all 0.25s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent-light); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent); }

/* --- Layout --- */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-brand {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-brand .logo {
  font-family: 'Outfit', sans-serif;
  font-size: 22px; font-weight: 700; letter-spacing: -0.5px;
}
.sidebar-brand .logo span { color: var(--accent); }
.sidebar-brand .company-name {
  font-size: 11px; color: var(--text-muted); display: block; margin-top: 2px;
}

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-section { margin-bottom: 20px; }
.nav-section-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--text-muted); padding: 0 12px; margin-bottom: 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer;
  transition: var(--transition); font-size: 13px; font-weight: 500;
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--bg-glass); color: var(--text-primary); }
.nav-item.active {
  background: rgba(124,108,240,0.08); color: var(--accent-light);
  border-left-color: var(--accent);
}
.nav-item .nav-label { flex: 1; }
.nav-item .badge {
  background: var(--danger); color: #fff;
  font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 600;
}

.sidebar-footer {
  padding: 14px 20px; border-top: 1px solid var(--border-color);
  font-size: 10px; color: var(--text-muted); text-align: center;
}

/* AI Clarification Styles */
.clarification-container {
    background: var(--bg-secondary);
    border-left: 4px solid var(--accent-purple);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}
.questions-list .form-group {
    margin-bottom: 15px;
}
.questions-list label {
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
    color: var(--text-primary);
}
.q-input {
    border-color: var(--border-color);
}
.q-input:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.1);
}

/* Main content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1; display: flex; flex-direction: column;
  min-height: 100vh; width: calc(100% - var(--sidebar-width));
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: rgba(17,17,20,0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-left h1 { font-size: 16px; font-weight: 600; font-family: 'Outfit', sans-serif; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.btn-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--bg-glass); border: 1px solid var(--border-color);
  color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: var(--transition);
}
.btn-icon:hover { background: var(--bg-card); color: var(--text-primary); }

.user-avatar {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff; cursor: pointer;
}

/* Page content */
.page-content { padding: 24px; flex: 1; min-width: 0; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  transition: var(--transition);
}
.card:hover { border-color: rgba(255,255,255,0.08); }
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 14px; font-weight: 600; font-family: 'Outfit', sans-serif; }
.card-body { padding: 20px; }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); padding: 20px;
  transition: var(--transition); position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  opacity: 0; transition: var(--transition);
}
.kpi-card:hover::before { opacity: 1; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; font-family: 'Outfit', sans-serif; margin-bottom: 2px; }
.kpi-sub { font-size: 11px; color: var(--text-muted); }
.kpi-icon {
  position: absolute; top: 18px; right: 18px;
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.kpi-icon.revenue { background: rgba(52,211,153,0.1); color: var(--success); }
.kpi-icon.expense { background: rgba(248,113,113,0.1); color: var(--danger); }
.kpi-icon.cash { background: rgba(124,108,240,0.1); color: var(--accent-light); }
.kpi-icon.tax { background: rgba(251,191,36,0.1); color: var(--warning); }

/* --- Tables --- */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th {
  text-align: left; padding: 10px 14px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; background: var(--bg-card);
}
td {
  padding: 11px 14px; border-bottom: 1px solid var(--border-color);
  font-size: 13px; color: var(--text-secondary);
}
tr:hover td { background: var(--bg-glass); }
.amount { font-family: 'JetBrains Mono', monospace; font-weight: 500; font-size: 12px; }
.amount.positive { color: var(--success); }
.amount.negative { color: var(--danger); }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 600;
}
.badge-success { background: rgba(52,211,153,0.1); color: var(--success); }
.badge-warning { background: rgba(251,191,36,0.1); color: var(--warning); }
.badge-danger { background: rgba(248,113,113,0.1); color: var(--danger); }
.badge-info { background: rgba(96,165,250,0.1); color: var(--info); }
.badge-purple { background: rgba(124,108,240,0.1); color: var(--accent-light); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; border: none;
  cursor: pointer; transition: var(--transition); font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-light); }
.btn-success { background: rgba(52,211,153,0.15); color: var(--success); border: none; }
.btn-danger { background: rgba(248,113,113,0.15); color: var(--danger); border: none; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled,
.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed !important;
  pointer-events: none;
  transform: none !important;
}
/* Loading spinner inside buttons */
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}
.btn--loading {
  opacity: 0.75;
  cursor: not-allowed !important;
  pointer-events: none;
  transform: none !important;
}
.btn--loading::before {
  content: '';
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.65s linear infinite;
  flex-shrink: 0;
}

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-control {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); background: var(--bg-primary);
  color: var(--text-primary); font-size: 13px; font-family: inherit;
  transition: var(--transition);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,108,240,0.15); }
select.form-control { appearance: none; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: none; align-items: center; justify-content: center; z-index: 1000;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: 16px; width: 90%; max-width: 520px;
  max-height: 85vh; overflow-y: auto;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { transform: scale(0.96) translateY(8px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
.modal-header {
  padding: 18px 24px; border-bottom: 1px solid var(--border-color);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 700; font-family: 'Outfit', sans-serif; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; }
.modal-body { padding: 24px; }
.modal-footer { padding: 14px 24px; border-top: 1px solid var(--border-color); display: flex; gap: 10px; justify-content: flex-end; }

/* --- Charts --- */
.chart-container { position: relative; height: 280px; }

/* --- Loading --- */
.spinner { width: 28px; height: 28px; border: 2px solid var(--border-color); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { display: flex; align-items: center; justify-content: center; padding: 48px; color: var(--text-muted); }

/* --- Toast --- */
.toast-container { position: fixed; top: 72px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 18px; border-radius: var(--radius-sm); background: var(--bg-secondary); border: 1px solid var(--border-color); box-shadow: var(--shadow); min-width: 260px; animation: toastIn 0.3s ease; font-size: 13px; }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

/* --- Login Page --- */
.login-page {
  min-height: 100vh; display: flex;
  background: var(--bg-primary);
}
.login-left {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 48px;
}
.login-right {
  flex: 1; position: relative; overflow: hidden;
}
.login-right img { width: 100%; height: 100%; object-fit: cover; }
.login-right::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, var(--bg-primary) 0%, transparent 40%); }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { font-family: 'Outfit', sans-serif; font-size: 28px; font-weight: 700; margin-bottom: 8px; letter-spacing: -0.5px; }
.login-card .brand span { color: var(--accent); }
.login-card h1 { font-family: 'Outfit', sans-serif; font-size: 20px; margin-bottom: 6px; font-weight: 600; }
.login-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 32px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }
.login-powered { font-size: 11px; color: var(--text-muted); margin-top: 32px; }

/* --- Utilities --- */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-12 { gap: 12px; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; width: 100%; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .login-right { display: none; }
  #menu-toggle { display: flex !important; }
}
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .page-content { padding: 16px; }
}
/* --- AI Assistant --- */
.ai-container { max-width: 800px; margin: 0 auto; }
.ai-input-wrapper {
    position: relative; margin-bottom: 30px;
    background: linear-gradient(135deg, rgba(124,108,240,0.1), rgba(167,139,250,0.05));
    border: 1px solid rgba(124,108,240,0.2);
    border-radius: 20px; padding: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.ai-textarea {
    width: 100%; min-height: 120px; background: transparent;
    border: none; color: var(--text-primary); font-size: 16px;
    resize: none; outline: none; font-family: inherit; line-height: 1.5;
}
.ai-textarea::placeholder { color: var(--text-muted); opacity: 0.6; }
.ai-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

.ai-processing {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 60px; text-align: center;
}
.ai-processing h2 { font-family: 'Outfit', sans-serif; font-size: 20px; margin-top: 20px; background: linear-gradient(90deg, #fff, var(--text-muted)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.proposal-card {
    animation: slideUp 0.4s cubic-bezier(.16,1,.3,1);
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.explanation-box {
    background: rgba(124,108,240,0.05); border-left: 3px solid var(--accent);
    padding: 16px; border-radius: 0 12px 12px 0; margin-bottom: 24px;
    font-size: 13px; color: var(--text-secondary); line-height: 1.6;
}
.magic-badge {
    display: inline-flex; align-items: center; gap: 4px;
    background: linear-gradient(45deg, var(--accent), var(--accent-light));
    color: #fff; padding: 4px 10px; border-radius: 20px; font-size: 10px;
    font-weight: 700; text-transform: uppercase; margin-bottom: 12px;
}

.table-editable td { padding: 4px 10px; }
.table-editable input {
    background: transparent; border: 1px solid transparent;
    color: var(--text-primary); width: 100%; padding: 6px;
    border-radius: 4px; transition: var(--transition);
}
.table-editable input:hover { border-color: var(--border-color); background: rgba(255,255,255,0.02); }
.table-editable input:focus { border-color: var(--accent); background: var(--bg-primary); }

.glow-btn {
    background: linear-gradient(45deg, var(--accent), var(--accent-light));
    box-shadow: 0 0 20px rgba(124,108,240,0.4);
}
.glow-btn:hover { box-shadow: 0 0 30px rgba(124,108,240,0.6); transform: scale(1.02); }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 1s linear infinite; }
