:root {
    --primary: #4f46e5;
    --primary-light: #e0e7ff;
    --primary-dark: #3730a3;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --text-light: #64748b;
    --border: #cbd5e1;
    --danger: #ef4444;
    --success: #16a34a;
    --occupied-bg: #dbeafe;       /* Blue-50 */
    --occupied-border: #93c5fd;   /* Blue-300 */
    --occupied-shadow: #60a5fa;   /* Blue-400 */
    --empty-bg: #f1f5f9;
    --empty-border: #e2e8f0;
    --empty-shadow: #cbd5e1;
    /* High Contrast Selection Colors (Magenta) */
    --select-bg: #fdf4ff;         /* Fuchsia-50 */
    --select-border: #d946ef;     /* Fuchsia-500 */
    --select-shadow: #c026d3;     /* Fuchsia-600 */
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* --- LOGIN --- */
.login-container { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%); }
.login-card { background: var(--surface); padding: 40px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); max-width: 320px; border: 1px solid var(--border); }

/* --- LANDING --- */
#landing { display: none; }
.landing-container { height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%); text-align: center; }
.landing-card { background: var(--surface); padding: 40px; border-radius: 24px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); max-width: 500px; border: 1px solid var(--border); }
.nav-button { background: var(--primary); color: white; padding: 12px 24px; font-weight: 600; border-radius: 8px; border: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: 0.2s; }
.nav-button:hover { background: var(--primary-dark); transform: translateY(-2px); }

/* --- APP LAYOUT --- */
.app-layout { display: flex; height: 100vh; opacity: 0; pointer-events: none; transition: opacity 0.3s; position: absolute; inset: 0; }
.app-layout.active { opacity: 1; pointer-events: auto; }

/* SIDEBARS */
.sidebar-towers { width: 240px; background: #1e293b; color: white; display: flex; flex-direction: column; border-right: 1px solid #334155; flex-shrink: 0; }
.brand { padding: 20px; font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 10px; background: #0f172a; }
.tower-grid { padding: 12px; overflow-y: auto; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tower-card { background: #334155; border-radius: 8px; padding: 10px; cursor: pointer; transition: 0.2s; display: flex; flex-direction: column; align-items: center; text-align: center; border: 2px solid transparent; }
.tower-card:hover { background: #475569; }
.tower-card.active { background: var(--primary); border-color: var(--primary-light); }
.tower-num { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.tower-stats { font-size: 9px; color: #94a3b8; line-height: 1.4; }

.sidebar-boxes { width: 200px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sb-header { padding: 16px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 14px; color: var(--text-light); text-transform: uppercase; background: #f8fafc; }
.box-list { flex: 1; overflow-y: auto; }
.box-item { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: 0.1s; display: flex; justify-content: space-between; align-items: center; }
.box-item:hover { background: #f8fafc; color: var(--primary); }
.box-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; border-left: 4px solid var(--primary); }
.box-stat-pill { font-size: 10px; background: rgba(0,0,0,0.05); padding: 2px 6px; border-radius: 10px; color: var(--text-light); }

/* MAIN CONTENT */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: #f1f5f9; }
.header { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0; }
.view-info h2 { margin: 0; font-size: 18px; color: var(--text); }
.view-meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.live-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-light); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 4px rgba(0,0,0,0.03); }
.status-dot.online { background: #16a34a; box-shadow: 0 0 0 4px rgba(22,163,74,0.15); }
.status-dot.offline { background: #ef4444; box-shadow: 0 0 0 4px rgba(239,68,68,0.15); }
.header-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.workspace { flex: 1; padding: 24px; overflow: auto; display: flex; justify-content: center; align-items: flex-start; }

.box-container { background: white; padding: 10px; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); border: 1px solid var(--border); }
.box-subtitle-area { margin-bottom: 10px; padding: 0 4px; }
.box-subtitle-input { width: 100%; border: none; border-bottom: 1px dashed var(--border); padding: 4px; font-size: 13px; color: var(--text-light); background: transparent; }
.box-subtitle-input:focus { outline: none; border-bottom-color: var(--primary); color: var(--primary); }

.big-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; width: fit-content; user-select: none; }

/* CELLS */
.b-cell {
    width: 70px; height: 70px; border-radius: 6px; position: relative; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    transition: transform 0.1s, box-shadow 0.1s; font-size: 10px; text-align: center; padding: 4px; line-height: 1.2;
}
/* 1. Empty */
.b-cell { background: var(--empty-bg); border: 1px solid var(--empty-border); box-shadow: 0 3px 0 var(--empty-shadow); color: #cbd5e1; }
.b-cell:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--empty-shadow); }
/* 2. Occupied */
.b-cell.occupied { background: var(--occupied-bg); border: 1px solid var(--occupied-border); box-shadow: 0 3px 0 var(--occupied-shadow); color: #1e3a8a; font-weight: 600; }
.b-cell.occupied:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--occupied-shadow); }
/* 3. Locked (Other User) */
.b-cell.locked-other { background: #fee2e2; border-color: #fca5a5; box-shadow: 0 3px 0 #f87171; cursor: not-allowed; }
/* 4. Selected (Batch Mode) */
.b-cell.selected { background: var(--select-bg) !important; border-color: var(--select-border) !important; box-shadow: 0 0 0 3px var(--select-border) !important; color: #86198f !important; z-index: 10; }
/* 5. Drag Preview */
.b-cell.drag-preview { background: #fae8ff; border-color: var(--select-border); }

.cell-text { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; max-width: 100%; word-break: break-word; font-size: 9px; }
.cell-initials { position: absolute; bottom: 2px; right: 2px; font-size: 8px; font-weight: 700; background: rgba(255,255,255,0.5); padding: 1px 3px; border-radius: 4px; color: var(--primary-dark); }
.cell-num { position: absolute; top: 2px; left: 3px; font-size: 8px; opacity: 0.5; }

/* MODALS & BARS */
.tool-btn { padding: 8px 12px; border: 1px solid var(--border); background: white; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tool-btn:hover { background: #f1f5f9; color: var(--primary); }
.tool-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.tool-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.tool-btn:disabled:hover { background: white; color: inherit; }

.batch-bar {
    position: fixed; bottom: 30px; left: 50%; transform: translate(-50%, 150%);
    background: #1e293b; color: white; padding: 12px 24px; border-radius: 50px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3); display: flex; align-items: center; gap: 20px;
    transition: 0.3s cubic-bezier(0.16, 1, 0.3, 1); z-index: 100;
}
.batch-bar.visible { transform: translate(-50%, 0); }
.batch-btn { background: rgba(255,255,255,0.1); border: none; color: white; padding: 6px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; }
.batch-btn:hover { background: rgba(255,255,255,0.2); }
.batch-btn.danger { background: var(--danger); }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); z-index: 200; display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: white; width: 450px; border-radius: 16px; padding: 0; overflow: hidden; box-shadow: 0 20px 25px rgba(0,0,0,0.1); display: flex; flex-direction: column; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: #f8fafc; }
.modal-body { padding: 24px; max-height: 70vh; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); background: #f8fafc; display: flex; gap: 10px; justify-content: flex-end; }

/* Filter Rows for Search/Export */
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.export-multi { position: relative; margin-bottom: 12px; }
.export-multi-btn { width: 100%; display: flex; justify-content: space-between; align-items: center; min-height: 38px; }
.export-multi-menu {
    display: none; position: absolute; left: 0; right: 0; top: 42px; z-index: 10020;
    max-height: 240px; overflow-y: auto; padding: 8px; background: white;
    border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 12px 30px rgba(15,23,42,0.18);
}
.export-multi-menu.open { display: block; }
.export-menu-controls { display: flex; gap: 8px; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid #e2e8f0; position: sticky; top: -8px; background: white; z-index: 1; }
.export-check-row { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 5px 6px; border-radius: 4px; cursor: pointer; text-transform: none; font-size: 12px; color: var(--text); font-weight: 500; margin: 0; }
.export-check-row:hover { background: #f8fafc; }
.export-check-row input { width: 16px; height: 16px; margin: 0; padding: 0; flex: 0 0 16px; }
.export-check-row span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Search Results Styling */
.search-result {
    padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer;
    background: white; transition: background 0.2s; display: flex; align-items: flex-start; gap: 10px;
}
.search-result:hover { background: #f8fafc; }
.search-result:last-child { border-bottom: none; }
.search-check { margin-top: 4px; cursor: pointer; width: 16px; height: 16px; accent-color: var(--primary); }

input, select, textarea { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 12px; font-size: 14px; }
label { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--text-light); display: block; margin-bottom: 4px; }
.btn { padding: 10px 16px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: white; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
