:root {
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --bg-hover: #2d2d2d;
    --primary: #4CAF50;
    --primary-hover: #43a047;
    --accent: #2196F3;
    --text-main: #e0e0e0;
    --text-sub: #a0a0a0;
    --border: #333;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 12px;
}

/* Light Theme Variables */
body.light-theme {
    --bg-dark: #f5f5f5;
    --bg-card: #ffffff;
    --bg-hover: #e0e0e0;
    --primary: #43a047;
    --primary-hover: #2e7d32;
    --accent: #1976D2;
    --text-main: #333333;
    --text-sub: #666666;
    --border: #ddd;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background-color: var(--bg-dark); color: var(--text-main); height: 100vh; overflow: hidden; transition: background-color 0.3s, color 0.3s; }

.app-container { display: flex; height: 100%; }

.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    backdrop-filter: blur(4px);
}

.login-overlay.show { display: flex; }

.login-card {
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

.login-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 6px;
}

.login-sub {
    font-size: 12px;
    color: var(--text-sub);
    margin-bottom: 16px;
}

.login-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-dark);
    color: var(--text-main);
    outline: none;
}

.login-input:focus { border-color: var(--primary); }

.login-error {
    min-height: 18px;
    color: #F44336;
    font-size: 12px;
    margin: 8px 0 12px;
}

.login-btn { width: 100%; }

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px;
    flex-shrink: 0;
    transition: transform 0.3s ease, background-color 0.3s;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
    padding: 0 10px;
}
.logo-icon { font-size: 24px; color: var(--primary); }
.logo-area h2 { font-size: 20px; font-weight: 600; color: var(--text-main); }

.account-selector {
    position: relative;
    margin-bottom: 20px;
}
.current-account {
    background: var(--bg-hover);
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid var(--border);
    transition: 0.2s;
    color: var(--text-main);
}
.current-account:hover { border-color: var(--primary); }
.account-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 5px;
    display: none;
    z-index: 100;
    box-shadow: var(--shadow);
    max-height: 200px;
    overflow-y: auto;
}
.account-dropdown.show { display: block; }
.account-option {
    padding: 10px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
}
.account-option:hover { background: var(--bg-hover); }
.account-option.active { color: var(--primary); }

.nav-menu { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    text-decoration: none;
    color: var(--text-sub);
    border-radius: var(--radius);
    transition: 0.2s;
}
.nav-item:hover, .nav-item.active {
    background: rgba(76, 175, 80, 0.1);
    color: var(--primary);
}
.nav-item i { width: 20px; text-align: center; }

.status-mini {
    margin-top: auto;
    padding: 15px;
    background: var(--bg-dark);
    border-radius: var(--radius);
    font-size: 0.9em;
    color: var(--text-sub);
}
.connection-status { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.online { background: #4CAF50; box-shadow: 0 0 5px #4CAF50; }
.dot.offline { background: #F44336; }

.system-time {
    font-size: 12px;
    color: var(--text-sub);
    margin-top: 5px;
    text-align: center;
    opacity: 0.8;
}

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg-dark); position: relative; transition: background-color 0.3s; }

.top-bar {
    height: 60px;
    padding: 0 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card); /* Glass effect removed for simplicity */
    border-bottom: 1px solid var(--border);
    transition: background-color 0.3s, border-color 0.3s;
}

.actions { display: flex; gap: 10px; }
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-sub);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: 0.2s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-main); }

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: background-color 0.3s, border-color 0.3s;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 16px; font-weight: 600; color: var(--text-main); display: flex; align-items: center; gap: 8px; }

/* Stats */
.stats-cards {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr; /* Adjusted for merged card */
    gap: 20px;
    margin-bottom: 20px;
}
/* Resource Card (Merged Gold & Exp) */
.resource-card {
    display: flex;
    align-items: center;
    padding: 20px;
}
.resource-row {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
}
.divider-vertical {
    width: 1px;
    height: 40px;
    background: var(--border);
    margin: 0 20px;
}

.stat-card {
    display: flex;
    align-items: center;
    padding: 25px;
    gap: 20px;
    position: relative;
}
.stat-icon {
    width: 50px; height: 50px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}
.stat-icon.gold { background: rgba(255, 193, 7, 0.1); color: #FFC107; }
.stat-icon.exp { background: rgba(33, 150, 243, 0.1); color: #2196F3; }
.stat-icon.time { background: rgba(156, 39, 176, 0.1); color: #9C27B0; }
.stat-icon.rate { background: rgba(0, 150, 136, 0.1); color: #009688; }

.stat-info { flex: 1; min-width: 0; }
.stat-info h3 { font-size: 14px; color: var(--text-sub); margin-bottom: 5px; white-space: nowrap; }
.stat-info .value { font-size: 24px; font-weight: bold; color: var(--text-main); transition: color 0.3s; white-space: nowrap; }
.stat-info .sub { font-size: 12px; color: var(--primary); margin-top: 2px; white-space: nowrap; display: flex; gap: 5px; }

/* Exp Gain Animation */
@keyframes value-jump {
    0% { transform: scale(1); color: var(--text-main); }
    50% { transform: scale(1.3); color: var(--accent); }
    100% { transform: scale(1); color: var(--text-main); }
}
@keyframes value-jump-gold {
    0% { transform: scale(1); color: var(--text-main); }
    50% { transform: scale(1.3); color: #FFC107; }
    100% { transform: scale(1); color: var(--text-main); }
}

.value-changed {
    display: inline-block;
    animation: value-jump 0.5s ease-out;
}
.value-changed-gold {
    display: inline-block;
    animation: value-jump-gold 0.5s ease-out;
}

/* Progress Bar */
.progress-bar {
    width: 100%; height: 6px; background: var(--bg-hover); border-radius: 3px; margin: 5px 0; overflow: hidden;
}
.progress-bar .fill { height: 100%; background: var(--accent); transition: width 0.5s; }

/* Grid System */
.row { display: flex; gap: 20px; }
.col-8 { flex: 8; }
.col-4 { flex: 4; }

/* Logs */
.logs-container { max-height: 400px; overflow-y: auto; font-family: 'Consolas', monospace; font-size: 13px; }
.log-row { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.05); display: flex; gap: 10px; }
body.light-theme .log-row { border-bottom: 1px solid rgba(0,0,0,0.05); }
.log-time { color: var(--text-sub); min-width: 70px; }
.log-tag { color: var(--accent); min-width: 60px; }
.log-msg { color: var(--text-main); flex: 1; word-break: break-all; }
.log-row.warn .log-msg { color: #FFC107; }
body.light-theme .log-row.warn .log-msg { color: #F57F17; }

/* Switches */
.switches-list { display: flex; flex-direction: column; gap: 15px; }
.switch-item { display: flex; justify-content: space-between; align-items: center; cursor: pointer; color: var(--text-main); }
.switch-item input { display: none; }
.slider {
    width: 40px; height: 20px; background: var(--bg-hover); border-radius: 20px; position: relative; transition: 0.3s;
}
.slider:before {
    content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: 0.3s;
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

/* Farm Grid */
.farm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 15px;
}
.farm-grid.mini { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 5px; }
.land-cell {
    background: var(--bg-hover);
    border-radius: 8px;
    padding: 10px;
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 2px solid transparent;
    position: relative;
    transition: 0.2s;
    overflow: hidden;
    color: var(--text-main);
}
.land-cell:hover { transform: translateY(-2px); filter: brightness(1.1); }
.land-cell.harvestable { border-color: #FFC107; background: rgba(255, 193, 7, 0.1); }
.land-cell.dead { border-color: #555; opacity: 0.6; }
.land-cell .id { position: absolute; top: 5px; left: 5px; font-size: 10px; color: var(--text-sub); }
.land-cell .needs {
    position: absolute; bottom: 5px; right: 5px;
    background: #F44336; color: #fff; font-size: 10px; padding: 2px 4px; border-radius: 4px;
}
.plant-name { font-size: 14px; margin-bottom: 2px; }
.phase-name { font-size: 12px; color: var(--text-sub); }
.farm-grid.mini .land-cell { padding: 2px; }
.farm-grid.mini .plant-name { font-size: 10px; }
.farm-grid.mini .id { display: none; }

/* Friends List */
.friends-list { display: flex; flex-direction: column; gap: 10px; }
.friend-item {
    background: var(--bg-hover); border-radius: 8px; border: 1px solid var(--border); overflow: hidden;
    color: var(--text-main);
}
.friend-header {
    padding: 15px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.friend-header:hover { background: var(--bg-card); }
.friend-header .preview { font-size: 12px; color: var(--text-sub); }
.friend-header .preview.has-work { color: var(--primary); font-weight: bold; }

/* Task List */
.task-list { display: flex; flex-direction: column; gap: 10px; padding-top: 15px; }
.task-item {
    background: var(--bg-hover); padding: 15px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center;
    color: var(--text-main);
}
.task-info h4 { font-size: 14px; margin-bottom: 5px; }
.task-info p { font-size: 12px; color: var(--text-sub); }
.task-progress { font-size: 12px; color: var(--accent); margin-left: 10px; }
.tabs { display: flex; gap: 20px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.tab { padding: 10px 5px; cursor: pointer; color: var(--text-sub); border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text-main); }

/* Actions Group */
.actions-group { display: flex; gap: 5px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Modal */
.modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000;
    display: none; align-items: center; justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
    background: var(--bg-card); width: 400px; padding: 25px; border-radius: var(--radius);
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    max-width: 90%;
    color: var(--text-main);
}
.modal-header { display: flex; justify-content: space-between; margin-bottom: 20px; }
.close-modal { cursor: pointer; font-size: 20px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 8px; color: var(--text-sub); font-size: 14px; }
.form-control {
    width: 100%; background: var(--bg-dark); border: 1px solid var(--border); color: var(--text-main);
    padding: 10px; border-radius: 6px; outline: none;
}
.form-control:focus { border-color: var(--primary); }
.btn {
    padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; font-weight: 600; transition: 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Tooltip Hint */
.hint-text {
    position: absolute; bottom: 5px; right: 10px; font-size: 10px; color: var(--text-sub); opacity: 0.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 15px; }
.acc-item {
    background: var(--bg-hover); padding: 15px; border-radius: 8px; border: 1px solid var(--border);
    cursor: pointer; transition: 0.2s;
    color: var(--text-main);
}
.acc-item:hover { border-color: var(--primary); }
.acc-item .name { font-weight: bold; margin-bottom: 5px; }
.acc-item .code { font-size: 12px; color: var(--text-sub); word-break: break-all; }

/* Operation Stats in Dashboard */
.op-stat {
    display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border);
    color: var(--text-main);
}
.op-stat:last-child { border-bottom: none; }
.op-stat .count { font-weight: bold; color: var(--accent); }


/* Mobile Responsive */
@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    
    .sidebar {
        width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border);
        padding: 10px 20px;
    }
    .sidebar .logo-area, .sidebar .status-mini { display: none; }
    
    .account-selector { margin-bottom: 10px; }
    
    .nav-menu { flex-direction: row; overflow-x: auto; padding-bottom: 5px; gap: 10px; }
    .nav-item { padding: 8px 12px; white-space: nowrap; font-size: 14px; }
    .nav-item i { margin-right: 5px; }

    .main-content { height: calc(100vh - 120px); } /* Adjust based on sidebar height */
    .top-bar { padding: 0 15px; height: 50px; }
    .content-wrapper { padding: 15px; }

    .stats-cards { grid-template-columns: 1fr; gap: 10px; }
    .stat-card { padding: 15px; }
    .resource-card { flex-direction: column; align-items: stretch; }
    .divider-vertical { display: none; }
    .resource-row { margin-bottom: 10px; }
    
    .row { flex-direction: column; gap: 15px; }
    .col-8, .col-4 { flex: 1; }
    
    .farm-grid { grid-template-columns: repeat(4, 1fr); gap: 10px; }
    .land-cell { padding: 5px; }
    .plant-name { font-size: 12px; }
    .phase-name { font-size: 10px; }
}
