/* ==========================================================================
   Panel System CSS
   ========================================================================== */

:root {
    --panel-header-height: 28px;
    --panel-tab-height: 32px;
    --splitter-size: 6px;
    --panel-min-size: 100px;
    --panel-bg: var(--bg-panel, #16213e);
    --panel-header-bg: var(--bg-darker, #0f0f1a);
    --panel-border: var(--border-color, #2a2a4a);
    --panel-active-border: var(--accent-light, #3282b8);
    --tab-active-bg: var(--accent, #0f4c75);
    --tab-hover-bg: rgba(50, 130, 184, 0.3);
}

/* ==========================================================================
   Dock Container
   ========================================================================== */

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

.dock-container.desktop {
    display: flex;
    flex-direction: row;
}

.dock-container.mobile {
    display: flex;
    flex-direction: column;
}

.dock-center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 200px;
    overflow: hidden;
}

/* ==========================================================================
   Dock Zone
   ========================================================================== */

.dock-zone {
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    overflow: hidden;
    position: relative;
}

.dock-zone-left,
.dock-zone-right {
    border-color: var(--panel-border);
}

.dock-zone-left {
    border-right: 1px solid var(--panel-border);
}

.dock-zone-right {
    border-left: 1px solid var(--panel-border);
}

.dock-zone-bottom {
    border-top: 1px solid var(--panel-border);
}

.dock-zone-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Drag-over highlight */
.dock-zone.drag-over {
    outline: 2px dashed var(--panel-active-border);
    outline-offset: -2px;
    background: rgba(50, 130, 184, 0.1);
}

.drop-indicator {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(50, 130, 184, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 100;
}

.drop-indicator span {
    background: var(--panel-active-border);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

/* ==========================================================================
   Dock Panel
   ========================================================================== */

.dock-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.dock-panel.active {
    display: flex;
}

.dock-panel.dragging {
    opacity: 0.5;
}

.panel-header {
    height: var(--panel-header-height);
    min-height: var(--panel-header-height);
    background: var(--panel-header-bg);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 8px;
    cursor: move;
    user-select: none;
}

.panel-title {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.panel-controls {
    display: flex;
    gap: 4px;
}

.panel-btn {
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.panel-btn:hover {
    background: var(--tab-hover-bg);
    color: var(--text-color);
}

.panel-btn-close:hover {
    background: #cc3333;
    color: white;
}

.panel-content {
    flex: 1;
    overflow: auto;
    position: relative;
}

/* ==========================================================================
   Panel Tabs
   ========================================================================== */

.panel-tabs {
    height: var(--panel-tab-height);
    min-height: var(--panel-tab-height);
    background: var(--panel-header-bg);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: hidden;
}

.panel-tabs::-webkit-scrollbar {
    height: 3px;
}

.panel-tabs::-webkit-scrollbar-track {
    background: var(--panel-header-bg);
}

.panel-tabs::-webkit-scrollbar-thumb {
    background: var(--panel-border);
}

.panel-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    border-right: 1px solid var(--panel-border);
    cursor: pointer;
    white-space: nowrap;
    font-size: 12px;
    color: var(--text-dim);
    transition: background 0.15s, color 0.15s;
}

.panel-tab:hover {
    background: var(--tab-hover-bg);
    color: var(--text-color);
}

.panel-tab.active {
    background: var(--tab-active-bg);
    color: var(--text-color);
    border-bottom: 2px solid var(--panel-active-border);
}

.tab-icon {
    font-size: 14px;
}

.tab-title {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-close {
    width: 16px;
    height: 16px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.15s;
}

.panel-tab:hover .tab-close {
    opacity: 1;
}

.tab-close:hover {
    background: #cc3333;
    color: white;
}

/* ==========================================================================
   Dock Splitter
   ========================================================================== */

.dock-splitter {
    background: var(--panel-border);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.dock-splitter.vertical {
    width: var(--splitter-size);
    cursor: col-resize;
}

.dock-splitter.horizontal {
    height: var(--splitter-size);
    cursor: row-resize;
}

.dock-splitter:hover,
.dock-splitter.dragging {
    background: var(--panel-active-border);
}

.splitter-handle {
    position: absolute;
    background: transparent;
}

.dock-splitter.vertical .splitter-handle {
    top: 0;
    bottom: 0;
    left: -3px;
    right: -3px;
}

.dock-splitter.horizontal .splitter-handle {
    left: 0;
    right: 0;
    top: -3px;
    bottom: -3px;
}

/* ==========================================================================
   Floating Panel
   ========================================================================== */

.floating-panel {
    position: fixed;
    z-index: 1000;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.floating-panel.dragging {
    opacity: 0.9;
    cursor: move;
}

.floating-header {
    height: var(--panel-header-height);
    min-height: var(--panel-header-height);
    background: var(--panel-header-bg);
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    align-items: center;
    padding: 0 8px;
    gap: 8px;
    cursor: move;
    user-select: none;
}

.floating-content {
    flex: 1;
    overflow: auto;
}

.floating-resize {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, var(--panel-border) 50%);
}

.floating-resize:hover {
    background: linear-gradient(135deg, transparent 50%, var(--panel-active-border) 50%);
}

/* ==========================================================================
   Mobile Layout
   ========================================================================== */

.mobile-panel-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mobile-panel-tabs {
    display: flex;
    background: var(--panel-header-bg);
    border-top: 1px solid var(--panel-border);
    overflow-x: auto;
    padding: 4px;
    gap: 4px;
}

.mobile-tab {
    flex: 1;
    min-width: 60px;
    max-width: 100px;
    padding: 8px 12px;
    border: none;
    background: var(--panel-bg);
    color: var(--text-dim);
    font-size: 11px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: background 0.15s, color 0.15s;
}

.mobile-tab:hover {
    background: var(--tab-hover-bg);
}

.mobile-tab.active {
    background: var(--tab-active-bg);
    color: var(--text-color);
}

.mobile-tab .tab-icon {
    font-size: 18px;
}

.mobile-tab .tab-title {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* ==========================================================================
   Built-in Panel Wrappers
   ========================================================================== */

.terminal-panel-wrapper,
.map-panel-wrapper {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Stats Panel
   ========================================================================== */

.stats-panel {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats-header {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--panel-border);
}

.character-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
}

.stats-bars {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    width: 24px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
}

.stat-bar {
    flex: 1;
    height: 18px;
    background: var(--bg-darker);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.stat-bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

.hp-bar .stat-bar-fill {
    background: var(--hp-color, #cc3333);
}

.mp-bar .stat-bar-fill {
    background: var(--mp-color, #3366cc);
}

.stamina-bar .stat-bar-fill {
    background: #33aa33;
}

.stat-bar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.stats-attributes {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--panel-border);
}

.attributes-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.attribute-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 11px;
}

.attribute-name {
    color: var(--text-dim);
}

.attribute-value {
    color: var(--text-color);
    font-weight: 500;
}

/* ==========================================================================
   NPC/Items Panel
   ========================================================================== */

.npc-items-panel {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.room-header {
    padding-bottom: 8px;
    border-bottom: 1px solid var(--panel-border);
}

.room-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-light);
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.section-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.entity-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.entity-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.15s;
}

.entity-item:hover {
    background: var(--tab-hover-bg);
}

.entity-icon {
    width: 16px;
    text-align: center;
}

.entity-name {
    flex: 1;
    color: var(--text-color);
}

.entity-item.hostile .entity-name {
    color: #cc3333;
}

.entity-item.player .entity-name {
    color: var(--accent-light);
}

.entity-item.friendly .entity-name {
    color: #33aa33;
}

.entity-item.item .entity-name {
    color: #ccaa33;
}

.entity-count {
    font-size: 10px;
    color: var(--text-dim);
}

.empty-message {
    text-align: center;
    padding: 16px;
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
}

/* ==========================================================================
   Text Panel (Script-created)
   ========================================================================== */

.text-panel {
    padding: 8px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.4;
    overflow-y: auto;
}

.text-line {
    white-space: pre-wrap;
    word-break: break-word;
}

/* ==========================================================================
   Table Panel (Script-created)
   ========================================================================== */

.table-panel {
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th,
.data-table td {
    padding: 6px 8px;
    text-align: left;
    border-bottom: 1px solid var(--panel-border);
}

.data-table th {
    background: var(--panel-header-bg);
    font-weight: 600;
    color: var(--text-dim);
    position: sticky;
    top: 0;
}

.data-table td {
    color: var(--text-color);
}

.data-table tr:hover td {
    background: var(--tab-hover-bg);
}

/* ==========================================================================
   Gauge Panel (Script-created)
   ========================================================================== */

.gauge-panel {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.gauge-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.gauge-label {
    font-size: 11px;
    color: var(--text-dim);
}

.gauge-bar {
    height: 20px;
    background: var(--bg-darker);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.gauge-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

.gauge-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 11px;
    font-weight: 600;
    color: white;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   Responsive Overrides
   ========================================================================== */

/* ==========================================================================
   Map Panel Container (Game.razor integration)
   ========================================================================== */

.map-panel-container {
    min-width: 200px;
    max-width: 60vw;
    flex-shrink: 0;
    background: var(--bg-darker);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--panel-border);
    position: relative;
    height: 100%;
}

.map-panel-container .map-panel {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
}

.map-panel-container .map-panel .map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}


.stats-panel-content,
.npc-items-panel-content,
.script-panel-content {
    flex: 1;
    overflow: auto;
}

.mobile-map-panel {
    height: 200px;
    flex-shrink: 0;
    background: var(--bg-darker);
    border-top: 1px solid var(--panel-border);
}

.mobile-map-panel .map-container {
    width: 100%;
    height: 100%;
}

/* Floating map panel */
.floating-map {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.floating-map .map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

/* ==========================================================================
   Responsive Overrides
   ========================================================================== */

@media (max-width: 768px) {
    .dock-container.desktop {
        display: flex;
        flex-direction: column;
    }

    .dock-zone-left,
    .dock-zone-right {
        display: none;
    }

    .dock-splitter {
        display: none;
    }

    .floating-panel {
        display: none;
    }

    .panel-tabs {
        display: none;
    }

    .map-panel-container {
        display: none;
    }
}
