:root {
    --primary: #e74c3c;
    --primary-dark: #c0392b;
    --primary-light: #fef2f2;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-w: 240px;
    --header-h: 60px;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.12);
    --transition: 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
}

/* ============Sidebar============ */
.sidebar {
    width: var(--sidebar-w);
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.logo-icon {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -1px;
}

.sidebar-header h1 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.sidebar-header .sub {
    font-size: 11px;
    color: var(--text-muted);
}

.menu {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.menu::-webkit-scrollbar { width: 4px; }
.menu::-webkit-scrollbar-track { background: transparent; }
.menu::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.menu-group {
    padding: 6px 20px 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-top: 10px;
}

.menu-group:first-child { margin-top: 0; }

.menu-item {
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all var(--transition);
    border-left: 3px solid transparent;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
}

.menu-item .ico { font-size: 16px; width: 20px; text-align: center; }

.menu-item:hover {
    background: var(--bg);
    color: var(--primary);
}

.menu-item.active {
    background: var(--primary-light);
    border-left-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

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

.topbar {
    height: var(--header-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    display: inline-block;
}
.status-dot.green { background: var(--success); }
.status-dot.yellow { background: var(--warning); }
.status-dot.red { background: var(--danger); }

.user-menu {
    position: relative;
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
    user-select: none;
}
.user-menu:hover { background: rgba(0,0,0,0.05); }
.user-menu .arrow { font-size: 10px; color: #999; }
.user-dropdown {
    display: none;
    position: absolute; top: 100%; right: 0; margin-top: 4px;
    background: #fff; border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    min-width: 140px; z-index: 9999; overflow: hidden;
}
.user-dropdown.show { display: block; }
.dropdown-item {
    padding: 10px 16px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.dropdown-item:hover { background: #f5f5f5; color: #c62828; }

.modal-bg { display: none; position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.45); z-index: 99999; }
.modal-bg.show { display: flex; align-items: center; justify-content: center; }
.modal-box { background: #fff; border-radius: 12px; padding: 24px; width: 360px; }
.modal-box h3 { margin: 0 0 16px; }
.modal-box label { font-size: 13px; color: #666; display: block; margin-bottom: 6px; }
.modal-box input[type="password"] { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 12px; font-size: 14px; box-sizing: border-box; }
.modal-box .error-msg { color: #e74c3c; font-size: 13px; margin-bottom: 12px; }
.modal-box .btns { text-align: right; }
.modal-box .btns button { padding: 8px 20px; border: none; border-radius: 6px; cursor: pointer; margin-left: 8px; font-size: 13px; }
.modal-box .btn-cancel { background: #eee; color: #333; }
.modal-box .btn-confirm { background: var(--primary, #667eea); color: #fff; }

/* ============Content============ */
.content {
    padding: 0;
    flex: 1;
    display: flex;
}

.content iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: var(--bg);
}

.page { display: none; }
.page.active { display: block; }

/* ============Buttons============ */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition);
    font-family: inherit;
}

.btn:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }

.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 5px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 4px; }

/* ============Cards============ */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { margin-top: 0; }
.card-hover { transition: all var(--transition); }
.card-hover:hover { box-shadow: var(--shadow-hover); }

/* ============Stats Grid============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow);
    transition: all var(--transition);
    cursor: pointer;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }

.stat-icon { font-size: 30px; }
.stat-info h3 { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-info p { font-size: 13px; color: var(--text-muted); }

/* ============Tables============ */
.table-wrap {
    overflow-x: auto;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    background: var(--bg);
    white-space: nowrap;
}

th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--primary); }
th .sort-arrow { font-size: 10px; margin-left: 3px; color: #ccc; }
th.sorted .sort-arrow { color: var(--primary); }

tr:hover td { background: var(--bg); }
td { color: var(--text); }

.empty-row { text-align: center; padding: 50px 20px; color: var(--text-muted); }

/* ============Badges============ */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.badge-primary { background: #dbeafe; color: #1d4ed8; }
.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #e0f2fe; color: #0369a1; }

/* ============Modal (legacy compat)============ */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; }
.modal.show { display: flex; }

/* ============Modal============ */
.modal-overlay, .modal {
    display: none;
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center; align-items: center;
}

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

.modal-box {
    background: var(--card);
    border-radius: 12px;
    width: 90%; max-width: 680px;
    max-height: 85vh;
    overflow: hidden;
    display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-content { background: var(--card); border-radius: 12px; padding: 20px; max-width: 600px; max-height: 80vh; overflow-y: auto; }

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between; align-items: center;
    flex-shrink: 0;
}

.modal-header h3 { font-size: 16px; }

.modal-close {
    background: none; border: none; font-size: 22px;
    cursor: pointer; color: var(--text-muted); line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ============Form============ */
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }

.form-group {
    display: flex; flex-direction: column;
}

.form-group label {
    font-size: 12px; font-weight: 600; color: var(--text);
    margin-bottom: 5px;
}

.form-group input,
.form-group select {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    transition: all var(--transition);
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(231,76,60,0.1);
}

.search-input {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    width: 200px;
}

.search-input:focus { outline: none; border-color: var(--primary); }

/* ============Loading============ */
.loading {
    text-align: center; color: var(--text-muted);
}

.spinner {
    display: inline-block; width: 18px; height: 18px;
    border: 2px solid var(--border); border-top-color: var(--primary);
    border-radius: 50%; animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============Tabs============ */
.tab-bar {
    display: flex; border-bottom: 1px solid var(--border); margin-bottom: 0;
}

.tab-item {
    padding: 11px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 13px;
    transition: all var(--transition);
}

.tab-item:hover { color: var(--text); }
.tab-item.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ============Tactic chips============ */
.tactic-chips {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}

.tactic-chip {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 12px 7px 10px;
    border-radius: 9px; cursor: pointer;
    border: 2px solid var(--border); background: var(--card); color: var(--text);
    min-width: 80px;
    transition: all var(--transition);
}

.tactic-chip:hover { border-color: #b0b0d0; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }

.tactic-chip.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff; border-color: transparent;
}

.tactic-chip .chip-icon {
    width: 30px; height: 30px; border-radius: 7px;
    background: rgba(0,0,0,0.05); display: flex;
    align-items: center; justify-content: center; font-size: 14px;
}

.tactic-chip.active .chip-icon { background: rgba(255,255,255,0.2); }

.tactic-chip .chip-info { display: flex; flex-direction: column; line-height: 1.2; }
.tactic-chip .chip-name { font-size: 10px; opacity: 0.7; }
.tactic-chip .chip-count { font-size: 16px; font-weight: 700; letter-spacing: -0.5px; }
.tactic-chip .chip-count.zero { font-weight: 400; opacity: 0.5; }

/* ============Pagination============ */
.pagination {
    display: flex; justify-content: center; align-items: center;
    gap: 8px; padding: 16px;
}

.pagination button {
    padding: 6px 14px; border: 1px solid var(--border);
    background: var(--card); border-radius: 5px; cursor: pointer;
    font-size: 13px; transition: all var(--transition);
}

.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============Links============ */
.stock-link { color: var(--primary); cursor: pointer; text-decoration: none; }
.stock-link:hover { text-decoration: underline; }

/* ============Utility============ */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }

.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }

.flex { display: flex; }
.flex-center { align-items: center; justify-content: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }

/* ============Progress Float============ */
.progress-float {
    display: none; position: fixed; top: 20px; right: 20px;
    background: var(--card); border-radius: 12px;
    padding: 18px 22px; box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    z-index: 9999; min-width: 260px; cursor: move; user-select: none;
}

.progress-float.show { display: block; }

.progress-float .title {
    font-size: 14px; font-weight: 600; margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px; cursor: move;
}

.progress-float .message { font-size: 13px; color: var(--text-muted); margin-bottom: 10px; }

.progress-float .bar {
    height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden;
}

.progress-float .bar-inner {
    height: 100%; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 3px; width: 0%; transition: width 0.3s;
}

.progress-float .close-btn {
    position: absolute; top: 8px; right: 10px;
    background: none; border: none; font-size: 16px; cursor: pointer; color: var(--text-muted); line-height: 1;
}

/* ============Responsive============ */
@media (max-width: 768px) {
    .sidebar { width: 56px; }
    .sidebar-header h1, .sidebar-header .sub, .menu-group, .menu-item span:not(.ico) { display: none; }
    .menu-item { padding: 12px; justify-content: center; border-left: none; }
    .menu-item.active { border-left: none; border-bottom: 2px solid var(--primary); }
    .main-content { margin-left: 56px; }
    .content { padding: 14px; }
    .stats-grid { grid-template-columns: 1fr; }
    .form-row { flex-direction: column; }
    .search-input { width: 100%; }
}

@media (max-width: 480px) {
    .stat-card { flex-direction: column; text-align: center; }
    .tactic-chips { justify-content: center; }
}

/* ============iframe body (sub-pages)============ */
body.iframe-body { display: block; height: 100vh; width: 100%; margin: 0; overflow: hidden; }
body.iframe-body .content { padding: 0; height: 100%; width: 100%; overflow-y: auto; }
body.iframe-body .content > * { width: 100%; height: calc(100vh - 40px); padding: 20px; }
body.iframe-body .topbar { display: none; }

/* ============Tactics page specific============ */
.tactics-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px;
}

.tactic-card {
    background: var(--card); border-radius: var(--radius);
    padding: 18px; box-shadow: var(--shadow); cursor: pointer;
    transition: all var(--transition); border: 2px solid transparent;
    position: relative; overflow: hidden;
}

.tactic-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-3px); border-color: var(--primary); }

.tactic-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: var(--primary); transform: scaleX(0); transform-origin: left;
    transition: transform 0.3s;
}

.tactic-card:hover::before { transform: scaleX(1); }

.tactic-card-icon { font-size: 28px; margin-bottom: 8px; }
.tactic-card-name { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.tactic-card-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; line-height: 1.5; }

.tactic-card-footer {
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 10px; border-top: 1px solid var(--border);
}

.tactic-card-arrow { color: var(--primary); font-size: 16px; }
.tactic-card:hover .tactic-card-arrow { transform: translateX(3px); }

/* ============Param group============ */
.param-group {
    background: var(--bg); border-radius: 8px; padding: 14px; margin-bottom: 14px;
}

.param-group-title {
    font-size: 13px; font-weight: 600; color: var(--primary);
    margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}

.param-item {
    margin-bottom: 12px; padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.param-item:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.param-label { font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.param-input { padding: 7px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; width: 100px; text-align: center; }
.param-input:focus { outline: none; border-color: var(--primary); }

/* ============Log container============ */
.log-container {
    background: #1e1e1e; color: #0f0; padding: 14px; border-radius: 8px;
    max-height: 300px; overflow-y: auto;
    font-family: 'Consolas', monospace; font-size: 12px; line-height: 1.5;
    display: none;
}

.log-container.show { display: block; }
.log-info { color: #4fc3f7; }
.log-success { color: #00ff00; }
.log-error { color: #ff5252; }
