:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-body: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-sub: #94a3b8;
    --border: #334155;
    --sidebar-bg: #0b1120;
    --sidebar-text: #94a3b8;
    --sidebar-active: #1e293b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* Force font inheritance */
input, button, select, textarea, table, td, th {
    font-family: inherit;
}

body {
    margin: 0;
    background: var(--bg-body);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Webkit Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* Login */
.login-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-body);
    z-index: 2000;
    display: flex; justify-content: center; align-items: center;
}
.login-card {
    background: var(--bg-card); padding: 40px; border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2); width: 320px;
    text-align: center; border: 1px solid var(--border);
}
.login-input {
    width: 100%; padding: 12px; margin-bottom: 12px;
    border: 1px solid var(--border); border-radius: 6px;
    box-sizing: border-box; outline: none; transition: border 0.2s;
    background: #0f172a; color: #fff;
}
.login-input:focus { border-color: var(--primary); }
.btn {
    background: var(--primary); color: #fff; border: none;
    padding: 10px 16px; border-radius: 6px; font-weight: 600;
    cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
.btn:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); }
.btn-secondary { background: #334155; color: #cbd5e1; }
.btn-secondary:hover { background: #475569; }
.btn-info { background: #0ea5e9; color: #fff; }
.btn-info:hover { background: #0284c7; }
.btn-sm { padding: 6px 12px; font-size: 0.85em; }

/* App Layout */
.sidebar {
    width: 250px; background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column;
    flex-shrink: 0;
}
.brand {
    padding: 20px; font-size: 1.25em; color: #fff; font-weight: bold;
    border-bottom: 1px solid #1f2937; display: flex; align-items: center; gap: 10px;
}
.brand-icon { width: 24px; height: 24px; background: var(--primary); border-radius: 4px; display:flex;align-items:center;justify-content:center;color:#fff;font-size:14px;}
.nav { flex: 1; padding: 20px 0; }
.nav-item {
    padding: 12px 20px; cursor: pointer; display: flex; align-items: center; gap: 10px;
    transition: background 0.2s; color: #d1d5db;
}
.nav-item:hover, .nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 18px; text-align: center; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.header {
    background: var(--bg-card); border-bottom: 1px solid var(--border);
    padding: 0 30px; height: 64px; display: flex; align-items: center; justify-content: space-between;
}
.content { flex: 1; overflow-y: auto; padding: 30px; }

/* Stats Cards */
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { 
    background: linear-gradient(145deg, var(--bg-card) 0%, #252f44 100%);
    padding: 20px; border-radius: 8px; border: 1px solid var(--border); 
    box-shadow: 0 1px 2px rgba(0,0,0,0.2); 
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    border-color: #475569;
}
.stat-label { color: var(--text-sub); font-size: 0.85em; margin-bottom: 5px; }
.stat-val { font-size: 1.5em; font-weight: bold; color: var(--text-main); }

/* Table */
.card { background: var(--bg-card); border-radius: 8px; border: 1px solid var(--border); overflow: hidden; margin-bottom: 20px; }
.table-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 15px 20px; background: #1e293b; color: var(--text-sub); font-size: 0.75em; text-transform: uppercase; font-weight: 600; border-bottom: 1px solid var(--border); }
td { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 0.9em; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.badge { padding: 4px 8px; border-radius: 12px; font-size: 0.75em; font-weight: 600; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #334155; color: #cbd5e1; }

/* Progress Bar */
.prog-wrap { width: 100%; background: #334155; border-radius: 4px; height: 6px; margin-top: 6px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,0.2); }
.prog-bar { height: 100%; background: var(--primary); border-radius: 4px; width: 0%; transition: width 0.5s; }
.prog-label { font-size: 0.75em; color: var(--text-sub); display: flex; justify-content: space-between; margin-top: 2px; font-family: monospace; font-weight: 600; }

/* Modals */
.modal-wrap {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(4px);
}
.modal-box {
    background: var(--bg-card); width: 500px; max-width: 90%;
    border-radius: 8px; padding: 25px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5);
    border: 1px solid var(--border);
    color: var(--text-main);
    max-height: 85vh;
    overflow-y: auto;
    position: relative; 
}
.form-group { margin-bottom: 15px; }
.form-label { display: block; margin-bottom: 5px; font-size: 0.9em; color: var(--text-sub); }
.form-input, .form-select, .form-area {
    width: 100%; padding: 10px; border: 1px solid var(--border);
    border-radius: 4px; font-family: inherit; box-sizing: border-box;
    background: var(--bg-body); color: var(--text-main);
    outline: none;
}
.form-input:focus, .form-select:focus, .form-area:focus { border-color: var(--primary); }

.hidden { display: none !important; }
.remark-edit { border-bottom: 1px dashed var(--text-sub); cursor: pointer; }
.remark-edit:hover { color: var(--primary); border-color: var(--primary); }

/* Animations */
@keyframes spin { 100% { transform: rotate(360deg); } }
.spin { animation: spin 1s ease-in-out; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.92) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes modalOut { from { opacity: 1; transform: scale(1) translateY(0); } to { opacity: 0; transform: scale(0.92) translateY(10px); } }
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes backdropOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(40px); } }
@keyframes rowHighlight { 0% { background: transparent; } 30% { background: rgba(251,191,36,0.12); } 100% { background: transparent; } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Page fade-in */
#app-view { animation: fadeIn 0.4s ease-out; }

/* Modal animations */
.modal-wrap { animation: backdropIn 0.2s ease-out; }
.modal-wrap.modal-closing { animation: backdropOut 0.2s ease-out forwards; pointer-events: none; }
.modal-box { animation: modalIn 0.25s ease-out; }
.modal-closing .modal-box { animation: modalOut 0.2s ease-out forwards; }

/* Tab content fade */
.content { animation: fadeIn 0.3s ease-out; }

/* Table row entrance */
tr.row-enter { animation: slideUp 0.3s ease-out; }
tr.row-updated { animation: rowHighlight 0.8s ease-out; }

/* Toast */
#toast { animation: toastIn 0.3s ease-out; }
#toast.toast-out { animation: toastOut 0.3s ease-out forwards; }

/* Stat card number transition */
.stat-val { transition: color 0.3s; }

/* Login card entrance */
.login-enter { animation: slideUp 0.5s ease-out; }

/* Button loading state */
.btn-loading { position: relative; pointer-events: none; opacity: 0.7; }
.btn-loading::after {
    content: ''; position: absolute; width: 14px; height: 14px;
    border: 2px solid transparent; border-top-color: #fff; border-radius: 50%;
    animation: spin 0.6s linear infinite; right: 10px; top: calc(50% - 7px);
}

/* Pulse for status indicators */
.pulse { animation: pulse 2s ease-in-out infinite; }

/* Nav item transition */
.nav-item { transition: background 0.2s, color 0.2s, padding-left 0.2s; }
.nav-item.active { padding-left: 24px; border-left: 3px solid var(--primary); }

/* Utilities */
.bg-dark { background-color: var(--bg-body) !important; }
.text-white { color: #fff !important; }
.text-red { color: var(--danger) !important; }
.text-center { text-align: center !important; }
.p-4 { padding: 1.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.w-100 { width: 100% !important; }

/* Form Control Alias */
.form-control {
    width: 100%; padding: 12px;
    border: 1px solid var(--border); border-radius: 6px;
    box-sizing: border-box; outline: none; transition: border 0.2s;
    background: #0f172a; color: #fff;
    display: block;
}
.form-control:focus { border-color: var(--primary); }

/* Mobile Adaptation */
@media (max-width: 768px) {
    body { flex-direction: column; overflow: auto; }
    .sidebar { width: 100%; height: auto; flex-direction: row; align-items: center; padding: 0; overflow-x: auto; border-bottom: 1px solid var(--border); }
    .brand { padding: 15px; border-bottom: none; border-right: 1px solid #1f2937; margin-right: 0; }
    .nav { display: flex; flex-direction: row; padding: 0; }
    .nav-item { padding: 15px; white-space: nowrap; border-bottom: none; }
    
    .main { height: auto; overflow: visible; flex: 1; }
    .content { padding: 15px; overflow: visible; }
    .header { padding: 0 15px; }

    /* Horizontal Scroll for Tables */
    .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { min-width: 600px; }

    /* Fullscreen Modals on Mobile */
    .modal-box { 
        width: 100%; max-width: 100%; height: 100%; max-height: 100vh;
        border-radius: 0; border: none; padding: 15px;
    }
    
    /* Stats Stacked */
    .grid-stats { grid-template-columns: 1fr; gap: 15px; }
    
    /* Adjust Progress Bar Layout */
    .prog-label { font-size: 0.8em; }
}
