/* ============================================================
   admin.css — MAX租控管理 · Light / Dark Dual Theme v2.1
   Design: Figma/Linear-style editor — light default
   ============================================================ */

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

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

/* ── Light theme (default) ───────────────────────────────── */
:root {
    --bg-base:      #f0f4f9;
    --bg-surface:   #ffffff;
    --bg-elevated:  #f8fafc;
    --bg-hover:     #f1f5f9;
    --bg-active:    #dbeafe;
    --border:       rgba(0,0,0,0.08);
    --border-light: rgba(0,0,0,0.13);

    --text-primary:   #0f172a;
    --text-secondary: #475569;
    --text-muted:     #94a3b8;

    --accent:      #2563eb;
    --accent-glow: rgba(37,99,235,0.15);
    --accent-hover:#1d4ed8;

    --green:  #16a34a;
    --red:    #dc2626;
    --yellow: #ca8a04;
    --purple: #7c3aed;
    --orange: #ea580c;

    --sidebar-w: 260px;
    --right-panel-w: 340px;
    --topbar-h: 52px;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-sm: 0 1px 4px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.14);

    --canvas-dot: rgba(0,0,0,0.06);
    --toolbar-bg: rgba(255,255,255,0.88);
    --toolbar-border: rgba(0,0,0,0.10);
    --detect-bg: rgba(255,255,255,0.92);
}

/* ── Dark theme override ─────────────────────────────────── */
[data-theme="dark"] {
    --bg-base:      #0b1120;
    --bg-surface:   #131c2e;
    --bg-elevated:  #1a2540;
    --bg-hover:     #1f2d45;
    --bg-active:    #243352;
    --border:       rgba(255,255,255,0.07);
    --border-light: rgba(255,255,255,0.12);

    --text-primary:   #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted:     #4e637a;

    --accent:      #3b82f6;
    --accent-glow: rgba(59,130,246,0.20);
    --accent-hover:#2563eb;

    --green:  #22c55e;
    --red:    #ef4444;
    --yellow: #eab308;
    --purple: #a855f7;
    --orange: #f97316;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);

    --canvas-dot: rgba(255,255,255,0.04);
    --toolbar-bg: rgba(19,28,46,0.88);
    --toolbar-border: rgba(255,255,255,0.10);
    --detect-bg: rgba(19,28,46,0.92);
}

/* ── Smooth theme transitions ────────────────────────────── */
body,
.admin-topbar, .topbar-brand, .admin-sidebar,
.floating-toolbar, .detect-panel, .right-drawer,
.room-item, .stats-card, .field input, .field select,
.field textarea, .tool-btn, .tool-select,
.detect-sec-btn, .sidebar-select {
    transition:
        background 0.25s ease,
        border-color 0.25s ease,
        color 0.2s ease,
        box-shadow 0.25s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Microsoft YaHei', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── App Shell ───────────────────────────────────────────── */
.admin-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: var(--bg-base);
}

/* ── Top Bar ─────────────────────────────────────────────── */
.admin-topbar {
    height: var(--topbar-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px 0 0;
    flex-shrink: 0;
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 16px;
    border-right: 1px solid var(--border);
    width: var(--sidebar-w);
    flex-shrink: 0;
}

.brand-logo {
    font-size: 20px;
    font-weight: 800;
    color: var(--accent);
    letter-spacing: -0.5px;
    line-height: 1;
}

.brand-label {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.brand-label strong {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.brand-label span {
    font-size: 10px;
    color: var(--text-muted);
}

.topbar-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.topbar-tools {
    /* The floating toolbar is inside the canvas area now */
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 16px;
}

.topbar-project-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 5px 10px;
    height: 32px;
    cursor: pointer;
    outline: none;
}

.topbar-project-select:focus {
    border-color: var(--accent);
}

.topbar-link {
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.topbar-link:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.topbar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 12px;
    border-left: 1px solid var(--border);
}

.status-dot-live {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    animation: pulse-live 2s infinite;
}

@keyframes pulse-live {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* ── Workspace ───────────────────────────────────────────── */
.admin-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Left Sidebar ────────────────────────────────────────── */
.admin-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
}

.admin-sidebar::-webkit-scrollbar { width: 4px; }
.admin-sidebar::-webkit-scrollbar-track { background: transparent; }
.admin-sidebar::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.2); border-radius: 4px; }
.admin-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(128,128,128,0.4); }

.sidebar-top {
    padding: 14px 14px 0;
    flex-shrink: 0;
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.sidebar-floorplan-row {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 8px;
}

.sidebar-select {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    padding: 6px 10px;
    height: 34px;
    outline: none;
    cursor: pointer;
    min-width: 0;
}

.sidebar-select:focus {
    border-color: var(--accent);
}

.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 36px;
    background: transparent;
    border: 1px dashed rgba(59,130,246,0.4);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 10px;
}

.upload-btn:hover {
    background: var(--accent-glow);
    border-color: var(--accent);
}

.scale-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 6px 0;
    border-top: 1px solid var(--border);
    margin-top: 2px;
}

.scale-edit-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 11px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
}

.scale-edit-btn:hover {
    background: var(--accent-glow);
}

/* Stats card */
.stats-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin: 8px 14px;
    display: none;
    flex-shrink: 0;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-secondary);
    padding: 2px 0;
}

.stats-row strong {
    color: var(--text-primary);
    font-weight: 600;
}

.stats-highlight {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.stats-big {
    font-size: 20px;
    font-weight: 700;
    color: var(--green);
    line-height: 1;
}

.stats-big-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Room list */
.room-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px 6px;
    flex-shrink: 0;
    border-top: 1px solid var(--border);
}

.room-list-header-actions {
    display: flex;
    gap: 2px;
    align-items: center;
}

.sidebar-icon-btn {
    background: none;
    border: none;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}

.sidebar-icon-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.sidebar-icon-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.sidebar-icon-btn.danger:hover:not(:disabled) {
    background: rgba(239,68,68,0.15);
    color: var(--red);
}

/* Label toggles */
.label-toggles {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 0 14px 8px;
    flex-shrink: 0;
}

.label-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.label-toggle input[type=checkbox] {
    accent-color: var(--accent);
    width: 13px;
    height: 13px;
}

.label-toggle:hover {
    color: var(--text-secondary);
}

.label-font-size-select {
    height: 26px;
    min-width: 72px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 11px;
}

/* Room list area */
.room-list {
    flex: none;
    padding: 4px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.room-item {
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    background: var(--bg-elevated);
    transition: all 0.15s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.room-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.room-item.active {
    background: var(--bg-active);
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-glow), inset 0 0 0 1px var(--accent-glow);
}

.room-info strong {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
}

.room-info span {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
    display: block;
}

/* Status badges */
.status-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 100px;
    white-space: nowrap;
    flex-shrink: 0;
}

.status-badge.available { background: var(--bg-surface);  color: var(--text-secondary); border: 1px solid var(--border); }
.status-badge.public { background: rgba(100,116,139,0.15); color: #64748b; }
.status-badge.rented    { background: rgba(245,158,11,0.15); color: #f59e0b; }
.status-badge.locked    { background: rgba(239,68,68,0.15);  color: var(--red); }

.empty-text {
    color: var(--text-muted);
    font-size: 12px;
    text-align: center;
    padding: 24px 0;
    line-height: 1.8;
}

/* ── Canvas Area ─────────────────────────────────────────── */
.admin-canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    background: var(--bg-base);
    background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
    background-size: 24px 24px;
}

.canvas-container-wrapper {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#floorplanCanvas {
    width: 100%;
    height: 100%;
}

/* ── Floating Toolbar (top-center) ───────────────────────── */
.floating-toolbar {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--toolbar-border);
    border-radius: var(--radius-lg);
    padding: 5px 8px;
    display: flex;
    align-items: center;
    gap: 2px;
    box-shadow: var(--shadow-md);
    z-index: 60;
    white-space: nowrap;
    max-width: calc(100% - 28px);
    overflow-x: auto;
}

.tool-divider {
    width: 1px;
    height: 20px;
    background: var(--border-light);
    margin: 0 4px;
    flex-shrink: 0;
}

.tool-btn {
    background: transparent;
    border: 1px solid transparent;
    height: 34px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    white-space: nowrap;
    font-family: inherit;
}

.tool-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.tool-btn.active {
    background: var(--bg-active);
    color: var(--accent);
    border-color: rgba(59,130,246,0.3);
}

.tool-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.tool-btn.ai-btn { color: var(--purple); }
.tool-btn.ai-btn:hover:not(:disabled) {
    background: rgba(168,85,247,0.12);
    color: var(--purple);
    border-color: rgba(168,85,247,0.25);
}

.tool-btn.save-btn { color: var(--green); }
.tool-btn.save-btn:not(:disabled):hover {
    background: rgba(34,197,94,0.12);
    color: var(--green);
    border-color: rgba(34,197,94,0.25);
}

.tool-select {
    height: 34px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 0 8px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
}

.tool-select:focus {
    border-color: var(--accent);
    color: var(--text-primary);
}

.zoom-control {
    height: 34px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
}

.zoom-select {
    width: 76px;
    height: 26px;
    padding: 0 6px;
}

.zoom-slider {
    width: 110px;
    accent-color: var(--accent);
}

.zoom-label {
    min-width: 42px;
    color: var(--text-secondary);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.toolbar-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    border-left: 1px solid var(--border);
    margin-left: 2px;
}

.status-text {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 48px;
}

/* ── Left Auto-detect Panel ──────────────────────────────── */
.detect-panel {
    background: transparent;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: 16px;
    margin-bottom: 12px;
}

.detect-panel-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    user-select: none;
}

.detect-panel.collapsed .detect-panel-title {
    margin-bottom: 0;
}

.detect-panel.collapsed #detectPanelBody {
    display: none;
}

.detect-panel-title strong {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
}

.detect-panel-title span {
    font-size: 10px;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 2px 6px;
    border-radius: 4px;
}

.detect-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    height: 34px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    margin-bottom: 10px;
    font-family: inherit;
}

.detect-action-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.detect-action-btn:active {
    transform: translateY(0);
}

.detect-checks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}

.detect-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.detect-check input[type=checkbox] {
    accent-color: var(--accent);
    width: 12px;
    height: 12px;
}

.detect-input-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.detect-input {
    width: 60px;
    height: 26px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: 5px;
    padding: 0 6px;
    text-align: right;
    font-size: 11px;
    color: var(--text-primary);
    outline: none;
    font-family: inherit;
}

.detect-input:focus {
    border-color: var(--accent);
}

.detect-sec-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin: 6px 0;
}

.detect-sec-btn {
    height: 28px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.15s;
    font-family: inherit;
}

.detect-sec-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.detect-clear-btn {
    width: 100%;
    height: 28px;
    background: transparent;
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: var(--radius-sm);
    color: rgba(239,68,68,0.7);
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.15s;
    font-family: inherit;
    margin-top: 6px;
}

.detect-clear-btn:hover {
    background: rgba(239,68,68,0.08);
    border-color: var(--red);
    color: var(--red);
}

.detect-hint {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.6;
}

/* Detection results list */
#detectedUnitsList {
    margin-top: 8px;
    display: none;
}

.detected-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.detected-save-all-btn {
    background: rgba(34,197,94,0.15);
    border: 1px solid rgba(34,197,94,0.3);
    border-radius: 5px;
    color: var(--green);
    font-size: 10px;
    padding: 3px 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.15s;
}

.detected-save-all-btn:hover {
    background: rgba(34,197,94,0.25);
}

.detected-list-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 180px;
    overflow-y: auto;
}

.detected-list-items::-webkit-scrollbar { width: 3px; }
.detected-list-items::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 3px; }

.detected-list-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    /* border-left set inline per palette */
}

.detected-unit-name {
    flex: 1;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 11px;
    outline: none;
    border-radius: 3px;
    padding: 1px 2px;
    min-width: 0;
    cursor: text;
    background: transparent;
}

.detected-unit-name:focus {
    background: var(--bg-hover);
    box-shadow: 0 0 0 1px rgba(59,130,246,0.4);
}

.detected-unit-area {
    color: var(--text-muted);
    font-size: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.detected-del-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    flex-shrink: 0;
    transition: all 0.15s;
}

.detected-del-btn:hover {
    background: rgba(239,68,68,0.15);
    color: var(--red);
}

/* ── Right Drawer ────────────────────────────────────────── */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: all 0.25s;
}

.drawer-overlay.open {
    opacity: 1;
    visibility: visible;
}

.right-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--right-panel-w);
    height: 100vh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-light);
    z-index: 160;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}

.right-drawer.open {
    transform: translateX(0);
}

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

.drawer-header h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.drawer-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s;
}

.drawer-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.drawer-body::-webkit-scrollbar { width: 4px; }
.drawer-body::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 4px; }

.drawer-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.drawer-divider {
    height: 1px;
    background: var(--border);
    margin: 20px 0;
}

/* Form fields inside drawer */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.field-row {
    display: flex;
    gap: 10px;
}

.field-row .field { flex: 1; }

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field label,
.field-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    padding: 7px 10px;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.field textarea {
    resize: vertical;
    min-height: 60px;
}

.field input[type=number] {
    -moz-appearance: textfield;
}

.field input[type=number]::-webkit-outer-spin-button,
.field input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.suggested-area-hint {
    font-size: 10px;
    color: var(--text-muted);
    display: none;
}

/* Drawer action buttons */
.drawer-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.btn-primary {
    height: 38px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    height: 34px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-danger {
    height: 34px;
    background: transparent;
    border: 1px solid rgba(239,68,68,0.3);
    border-radius: var(--radius-sm);
    color: rgba(239,68,68,0.7);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-danger:hover {
    background: rgba(239,68,68,0.1);
    border-color: var(--red);
    color: var(--red);
}

/* Ledger section */
.ledger-list-container {
    max-height: 160px;
    overflow-y: auto;
    margin-bottom: 14px;
}

.ledger-item {
    padding: 8px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ledger-item strong {
    color: var(--text-primary);
    font-size: 12px;
}

.ledger-sub-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 12px 0 8px;
}

/* ── Scrollbar global ────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Utility classes ─────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }

/* ── Asset ledger workspace ─────────────────────────────── */
.topbar-link.active {
    background: var(--bg-active);
    color: var(--primary-color);
}
.ledger-workspace {
    height: calc(100vh - var(--topbar-height));
    overflow: auto;
    background: var(--bg-main);
}
.ledger-shell {
    max-width: 1680px;
    margin: 0 auto;
    padding: 20px;
}
.ledger-header,
.ledger-header-actions,
.ledger-panel-title,
.ledger-import-actions,
.ledger-filters,
.ledger-bind-search {
    display: flex;
    align-items: center;
    gap: 10px;
}
.ledger-header {
    justify-content: space-between;
    margin-bottom: 16px;
}
.ledger-header h1 {
    margin: 0;
    font-size: 22px;
}
.ledger-kpis {
    display: grid;
    grid-template-columns: repeat(8, minmax(110px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
.ledger-kpi,
.ledger-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}
.ledger-kpi {
    padding: 12px;
}
.ledger-kpi span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 6px;
}
.ledger-kpi strong {
    font-size: 20px;
}
.ledger-analytics {
    display: grid;
    grid-template-columns: minmax(300px, 1.3fr) repeat(6, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
.ledger-analytics-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    min-width: 0;
}
.ledger-analytics-title {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 10px;
}
.ledger-analytics-title span {
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
}
.ledger-trend-bars {
    display: flex;
    align-items: end;
    gap: 8px;
    min-height: 118px;
    overflow: auto;
}
.ledger-trend-bar {
    display: grid;
    align-items: end;
    justify-items: center;
    gap: 5px;
    min-width: 28px;
}
.ledger-trend-bar span {
    width: 16px;
    border-radius: 5px 5px 2px 2px;
    background: linear-gradient(180deg, var(--primary-color), var(--green));
}
.ledger-trend-bar small {
    color: var(--text-muted);
    font-size: 10px;
}
.ledger-rank-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
}
.ledger-rank-row span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ledger-rank-row strong {
    white-space: nowrap;
}
.ledger-quality-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.ledger-quality-list span {
    padding: 5px 8px;
    border-radius: 999px;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    font-size: 12px;
}
.ledger-grid {
    display: grid;
    grid-template-columns: minmax(720px, 1.7fr) minmax(380px, 0.85fr);
    gap: 14px;
}
.ledger-panel {
    min-width: 0;
    padding: 14px;
}
.ledger-panel-title {
    justify-content: space-between;
    margin-bottom: 12px;
}
.ledger-panel-title span {
    color: var(--text-muted);
    font-size: 12px;
}
.ledger-paste {
    width: 100%;
    min-height: 180px;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ledger-import-actions {
    margin-top: 10px;
    flex-wrap: wrap;
}
.ledger-import-preview {
    margin-top: 10px;
    max-height: 180px;
    overflow: auto;
}
.ledger-filters {
    margin-bottom: 10px;
}
.ledger-filters input {
    flex: 1;
}
.ledger-table-wrap {
    overflow: auto;
    max-height: 62vh;
}
.ledger-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.ledger-table th,
.ledger-table td {
    padding: 9px 8px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    white-space: nowrap;
}
.ledger-table th {
    color: var(--text-muted);
    background: var(--bg-hover);
    position: sticky;
    top: 0;
    z-index: 1;
}
.ledger-table tr.active td {
    background: var(--bg-active);
}
.ledger-table.mini td {
    font-size: 11px;
}
.ledger-cell-sub {
    display: block;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 11px;
    margin-top: 2px;
}
.ledger-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ledger-form.compact {
    margin-top: 10px;
}
.ledger-deal-list {
    max-height: 190px;
    overflow: auto;
}
.ledger-deal-item {
    padding: 9px 0;
    border-bottom: 1px solid var(--border-color);
    display: grid;
    gap: 3px;
    font-size: 12px;
}
.ledger-bind-box {
    border: 1px dashed var(--border-light);
    border-radius: 8px;
    padding: 10px;
    background: var(--bg-hover);
}
.bound-ledger-unit {
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 8px;
}
.bound-ledger-unit.is-bound {
    color: var(--green);
    font-weight: 600;
}
.ledger-bind-hint {
    color: var(--text-muted);
    font-size: 11px;
    margin: 6px 0 4px;
}
.ledger-bind-search input {
    flex: 1;
}
.ledger-bind-results {
    display: grid;
    gap: 6px;
    margin-top: 8px;
    max-height: 180px;
    overflow: auto;
}
.ledger-bind-option {
    width: 100%;
    border: 1px solid var(--border-color);
    background: var(--bg-panel);
    border-radius: 6px;
    padding: 8px;
    text-align: left;
    cursor: pointer;
}
.ledger-bind-option:hover {
    border-color: var(--primary-color);
    background: var(--bg-active);
}
.ledger-bind-option span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
}
.ledger-import-modal {
    max-width: 980px;
}
.ledger-import-modal .ledger-paste {
    min-height: 240px;
}

@media (max-width: 1200px) {
    .ledger-kpis { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
    .ledger-analytics { grid-template-columns: 1fr 1fr; }
    .ledger-grid { grid-template-columns: 1fr; }
}

/* ── Konva stage container ───────────────────────────────── */
.konva-stage {
    width: 100% !important;
    height: 100% !important;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.modal-content {
    background: var(--bg-panel);
    border-radius: 8px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transform: translateY(-20px);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
}
.modal-overlay.open .modal-content {
    transform: translateY(0);
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.modal-header .close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
}
.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-hover);
    border-radius: 0 0 8px 8px;
}

/* ── Mobile Responsive Adaptation (H5) ────────────────────── */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    margin-right: 12px;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }
    .admin-topbar {
        padding: 0 10px;
    }
    .topbar-brand {
        width: auto;
        border-right: none;
        padding: 0;
    }
    .brand-logo {
        font-size: 16px;
    }
    .topbar-right {
        flex: 1;
        overflow-x: auto;
        padding-bottom: 0;
        margin-left: 10px;
        -webkit-overflow-scrolling: touch;
    }
    .topbar-right::-webkit-scrollbar {
        display: none; /* Hide scrollbar for a cleaner look on mobile */
    }
    
    /* Hide some less important topbar buttons */
    #themeToggleBtn, .toolbar-status {
        display: none !important;
    }

    /* Drawer style sidebar */
    .admin-sidebar {
        position: fixed;
        left: -100%;
        top: var(--topbar-h);
        bottom: 0;
        z-index: 1000;
        width: 280px;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-lg);
        background: var(--bg-surface);
    }
    .admin-sidebar.open {
        left: 0;
    }
    
    /* Dim overlay for sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    .sidebar-overlay.active {
        display: block;
    }

    /* Right drawer full width */
    .right-drawer {
        width: 100%;
        max-width: 100%;
        border-left: none;
    }

    /* Hide complex floating tools */
    .floating-toolbar, .detect-panel {
        display: none !important;
    }

    /* Adjust modal for mobile */
    .modal-content {
        width: 90%;
        padding: 1rem;
        margin-top: 10vh;
    }
}


#floorplanCanvas {
    touch-action: none; /* Prevent native browser zooming/panning on canvas */
}


@media (max-width: 768px) {
    .admin-topbar {
        display: flex;
        flex-wrap: wrap;
        height: auto;
        padding: 8px 10px;
    }
    .topbar-brand {
        width: 100%;
        justify-content: space-between;
        margin-bottom: 8px;
    }
    .topbar-right {
        width: 100%;
        margin-left: 0;
        justify-content: flex-start;
    }
}


@media (max-width: 768px) {
    .mobile-hide-text { display: none !important; }
    .topbar-link { padding: 4px 8px !important; } /* Make buttons smaller on mobile */
}


/* Floating Floor Selector */
.floating-floor-selector {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    padding: 10px 20px;
    border-radius: 50px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 500;
    border: 1px solid var(--border);
    font-weight: bold;
    color: var(--text-primary);
    transition: all 0.3s;
}
.floating-floor-selector:hover {
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.floor-select-large {
    background: var(--bg-body);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 15px;
    font-weight: bold;
    color: var(--primary-color);
    outline: none;
    cursor: pointer;
    min-width: 140px;
}
@media (max-width: 768px) {
    .floating-floor-selector {
        bottom: 20px;
        width: 85%;
        justify-content: center;
        padding: 8px 16px;
    }
}


/* Update Floating Floor Selector Style */
.floating-floor-selector {
    bottom: auto !important;
    top: 24px !important;
    background: var(--accent) !important;
    color: #ffffff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(99,102,241,0.4) !important;
}
.floating-floor-selector i {
    color: #ffffff !important;
}
.floor-select-large {
    background: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
}
.floor-select-large option {
    color: #333 !important; /* Options dropdown usually needs dark text on white background in native UI */
}
@media (max-width: 768px) {
    .floating-floor-selector {
        top: 16px !important;
        bottom: auto !important;
    }
}


.floating-floor-selector {
    top: calc(var(--topbar-h) + 24px) !important;
}
@media (max-width: 768px) {
    .floating-floor-selector {
        top: 110px !important;
    }
}


.floating-floor-selector {
    top: 14px !important;
    border-radius: var(--radius-lg) !important; /* Match other UI */
    background: var(--accent) !important;
    box-shadow: var(--shadow-md) !important;
    padding: 6px 12px !important;
    border: none !important;
}
.floor-select-large {
    border-radius: var(--radius-md) !important;
    background: rgba(255, 255, 255, 0.15) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    padding: 4px 12px !important;
}
/* If both exist, move floating-toolbar down so they don't overlap */
.admin-canvas-area .floating-toolbar {
    top: 64px !important; 
}


.floating-floor-selector {
    background: var(--toolbar-bg) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border: 1px solid var(--toolbar-border) !important;
    color: var(--text-primary) !important;
    box-shadow: var(--shadow-md) !important;
}
.floating-floor-selector i {
    color: var(--text-secondary) !important;
}
.floor-select-large {
    background: var(--bg-surface) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
}
.floor-select-large:hover {
    border-color: var(--primary-color) !important;
}


@media (max-width: 768px) {
    .floating-toolbar {
        display: flex !important;
        width: 90% !important;
        overflow-x: auto !important;
        justify-content: flex-start !important;
        -webkit-overflow-scrolling: touch;
        top: 10px !important;
    }
    .floating-toolbar::-webkit-scrollbar { display: none; }
    
    /* Hide drawing tools on mobile */
    #modeRectBtn, #modeDrawBtn, #modeFillBtn, #toggleDebugMaskBtn {
        display: none !important;
    }
    .floating-toolbar .tool-divider:nth-of-type(2) {
        display: none !important;
    }
}


@media (max-width: 768px) {
    .desktop-only-tool {
        display: none !important;
    }
}


/* Loading Overlay */
.canvas-loading {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary-color);
}
@media (prefers-color-scheme: dark) {
    .canvas-loading {
        background: rgba(30, 41, 59, 0.6);
        color: #ffffff;
    }
}
.canvas-loading i {
    font-size: 36px;
    margin-bottom: 16px;
}

