/**
 * WMT Client Styles
 */

:root {
    --primary-color: #00ff00;
    --primary-dark: #00cc00;
    --primary-hover: #33ff33;
    --bg-dark: #1a1a2e;
    --bg-darker: #0f0f1a;
    --bg-main: #0f0f1a;
    --bg-panel: #16213e;
    --text-color: #ffffff;
    --text-muted: #888888;
    --border-color: rgba(255, 255, 255, 0.1);
    --error-color: #ff4444;
    --warning-color: #ffaa00;
    --font-mono: 'Consolas', 'Monaco', 'Courier New', monospace;
    --mud-font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-dark);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 20px;
}

.logo {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary-color);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
    color: var(--text-muted);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--error-color);
}

.status-indicator.connected {
    background: var(--primary-color);
}

.status-indicator.connecting {
    background: var(--warning-color);
    animation: pulse 1s infinite;
}

.status-indicator.authenticating {
    background: var(--warning-color);
    animation: pulse 0.5s infinite;
}

.status-indicator.mud_disconnected {
    background: var(--error-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* MIP Toggle */
.mip-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 15px;
    padding-left: 15px;
    border-left: 1px solid var(--border-color);
}

.mip-label {
    font-size: 0.85em;
    color: var(--text-muted);
    font-weight: 500;
}

.mip-toggle.active .mip-label {
    color: var(--primary-color);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: 0.2s;
    border-radius: 20px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: 0.2s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--primary-color);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(16px);
    background-color: white;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
}

.header-btn.primary {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
}

.header-btn.primary:hover {
    background: var(--primary-dark);
}

/* Hamburger Menu */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 20px;
    padding: 4px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}

.hamburger-btn span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-color);
    border-radius: 1px;
    transition: all 0.3s;
}

.hamburger-btn:hover {
    border-color: var(--primary-color);
}

.hamburger-btn:hover span {
    background: var(--primary-color);
}

.hamburger-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    min-width: 180px;
    z-index: 1000;
    overflow: hidden;
}

.hamburger-menu.open {
    display: block;
}

.hamburger-menu button {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-color);
    text-align: left;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.2s;
}

.hamburger-menu button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.hamburger-menu button:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.hamburger-menu .menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Header Dropdown Menu */
.header-dropdown {
    position: relative;
    display: inline-block;
}

.header-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    margin-top: 4px;
}

.header-dropdown-menu.open {
    display: block;
}

.header-dropdown-menu button {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-color);
    text-align: left;
    cursor: pointer;
    font-size: 0.9em;
}

.header-dropdown-menu button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.header-dropdown-menu button:first-child {
    border-radius: 6px 6px 0 0;
}

.header-dropdown-menu button:last-child {
    border-radius: 0 0 6px 6px;
}

/* Character Dropdown */
.character-btn {
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    padding: 8px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: all 0.2s;
}

.character-btn:hover {
    background: rgba(0, 255, 0, 0.1);
    border-color: var(--accent-color);
}

.character-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    min-width: 160px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    margin-top: 4px;
    overflow: hidden;
}

.character-menu.open {
    display: block;
}

.character-menu a {
    display: block;
    padding: 12px 16px;
    color: var(--text-color);
    text-decoration: none;
    font-size: 0.9em;
    transition: background 0.2s;
}

.character-menu a:hover {
    background: rgba(255, 255, 255, 0.1);
}

.character-menu button {
    display: block;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-color);
    text-align: left;
    font-size: 0.9em;
    cursor: pointer;
    transition: background 0.2s;
}

.character-menu button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.character-menu .menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.user-info {
    color: var(--text-muted);
    font-size: 0.9em;
}

.user-info strong {
    color: var(--text-color);
}
/* Main Content */
.main-content {
    display: flex;
    flex-direction: row;
    flex: 1;
    overflow: hidden;
}

.terminal-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

/* Output Area */
.output-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-darker);
    min-height: 0;
    overflow: hidden;
}

#mud-output {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    font-family: var(--mud-font, 'Consolas, Monaco, monospace');
    font-size: var(--mud-font-size, 14px);
    color: var(--mud-text-color, #00ff00);
    background: var(--mud-bg-color, #000000);
    line-height: 1.15;
    white-space: pre-wrap;
    word-wrap: break-word;
}

#mud-output .line {
    margin: 0;
    padding: 0;
}

#mud-output .line.system {
    color: #00ccff;
    font-style: italic;
}

#mud-output .line.error {
    color: var(--error-color);
}

#mud-output .line.command {
    color: #ffff00;
}

#mud-output .line.highlighted {
    background: rgba(255, 255, 0, 0.2);
}

/* Split Screen Status Areas (TinTin++ #split) */
.split-area {
    display: none;
    font-family: var(--mud-font, 'Consolas, Monaco, monospace');
    font-size: var(--mud-font-size, 14px);
    color: var(--mud-text-color, #00ff00);
    background: #111;
    border-color: var(--border-color);
    white-space: pre;
    overflow: hidden;
}

.split-area.active {
    display: block;
}

.split-top {
    border-bottom: 1px solid var(--border-color);
}

.split-bottom {
    border-top: 1px solid var(--border-color);
}

.split-area .split-row {
    padding: 2px 15px;
    line-height: 1.4;
    height: 1.4em;
    overflow: hidden;
}

/* Input Area */
/* MIP Status Bar */
.mip-status-bar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 15px;
    background: linear-gradient(180deg, var(--bg-darker) 0%, var(--bg-panel) 100%);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.mip-status-bar.hidden {
    display: none;
}

.mip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.mip-row-primary {
    gap: 15px;
}

.mip-row-secondary {
    font-size: 0.85em;
    gap: 20px;
}

.mip-stat-block {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 100px;
    flex: 1;
    max-width: 180px;
}

.mip-stat-block.hidden {
    display: none;
}

.mip-stat-block .stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mip-stat-block .stat-label {
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    display: flex;
    align-items: center;
}

.mip-stat-block .stat-icon {
    width: calc(var(--mud-font-size, 14px) + 2px);
    height: calc(var(--mud-font-size, 14px) + 2px);
}

.mip-stat-block .stat-value {
    font-size: var(--mud-font-size, 14px);
    font-family: var(--mud-font, 'Consolas, Monaco, monospace');
    color: var(--text-color);
}

.mip-stat-block .stat-bar {
    height: calc(var(--mud-font-size, 14px) - 2px);
    min-height: 10px;
    background: var(--bg-darker);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}

.mip-stat-block .stat-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 2px;
    width: 0%;
}

/* HP bar - green, yellow when medium, red when low */
.mip-stat-block.hp .stat-fill {
    background: linear-gradient(90deg, #22c55e 0%, #4ade80 100%);
}
.mip-stat-block.hp .stat-fill.low {
    background: linear-gradient(90deg, #ef4444 0%, #f87171 100%);
}
.mip-stat-block.hp .stat-fill.medium {
    background: linear-gradient(90deg, #f97316 0%, #fbbf24 100%);
}
.mip-stat-block.hp .stat-label,
.mip-stat-block.hp .stat-icon {
    color: #ef4444;
}

/* SP bar - blue */
.mip-stat-block.sp .stat-fill {
    background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
}
.mip-stat-block.sp .stat-label,
.mip-stat-block.sp .stat-icon {
    color: #60a5fa;
}

/* GP1 bar - purple */
.mip-stat-block.gp1 .stat-fill {
    background: linear-gradient(90deg, #8b5cf6 0%, #a78bfa 100%);
}
.mip-stat-block.gp1 .stat-label,
.mip-stat-block.gp1 .stat-icon {
    color: #a78bfa;
}

/* GP2 bar - cyan */
.mip-stat-block.gp2 .stat-fill {
    background: linear-gradient(90deg, #06b6d4 0%, #22d3ee 100%);
}
.mip-stat-block.gp2 .stat-label,
.mip-stat-block.gp2 .stat-icon {
    color: #22d3ee;
}

/* Enemy bar - red */
.mip-stat-block.enemy .stat-fill {
    background: linear-gradient(90deg, #dc2626 0%, #ef4444 100%);
}
.mip-stat-block.enemy .stat-label {
    color: #ef4444;
}
.mip-stat-block.enemy .stat-enemy-name {
    flex: 1;
    font-size: 0.85em;
    font-weight: 500;
    color: #fca5a5;
    margin-left: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mip-stat-block.enemy .stat-enemy-name:empty {
    display: none;
}

/* Guild lines - flexbox for smart wrapping on mobile */
.mip-guild-line {
    font-family: var(--mud-font, 'Consolas, Monaco, monospace');
    font-size: var(--mud-font-size, 14px);
    color: var(--text-color);
    display: flex;
    flex-wrap: wrap;
    gap: 0.25em 0.75em;  /* row-gap, column-gap */
    align-items: baseline;
}

.mip-guild-line:empty {
    display: none;
}

/* Each stat item stays together, won't break mid-value */
.guild-stat-item {
    white-space: nowrap;
}

/* Location info */
.mip-location {
    display: flex;
    gap: 15px;
    margin-left: auto;
    font-family: var(--mud-font, 'Consolas, Monaco, monospace');
    font-size: var(--mud-font-size, 14px);
}

.mip-room {
    color: var(--text-color);
    font-weight: 500;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mip-exits {
    color: var(--text-muted);
}

.mip-exits:not(:empty):before {
    content: "Exits: ";
    color: var(--primary-color);
}

/* Clickable stat bars */
.mip-stat-block {
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}

.mip-stat-block:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 255, 0, 0.2);
}

/* MIP Conditions Modal */
.mip-current-value {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-darker);
    border-radius: 6px;
    margin-bottom: 15px;
}

.mip-value-display {
    font-size: 1.5em;
    font-weight: bold;
    color: var(--primary-color);
    font-family: var(--font-mono);
}

.mip-conditions-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.mip-condition-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-darker);
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
}

.mip-condition-item.disabled {
    opacity: 0.5;
}

.mip-condition-expr {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.mip-condition-cmd {
    flex: 2;
    color: var(--text-muted);
    font-size: 0.85em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mip-condition-actions {
    display: flex;
    gap: 5px;
}

.mip-condition-actions button {
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.mip-condition-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.mip-condition-actions button.delete:hover {
    background: var(--error-color);
}

.mip-add-condition {
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
}

.mip-add-condition h4 {
    margin-bottom: 12px;
    color: var(--primary-color);
    font-size: 0.95em;
}

.mip-sub-condition-buttons {
    display: flex;
    gap: 8px;
    margin: 10px 0;
}

.mip-sub-condition-buttons .btn-small {
    padding: 4px 10px;
    font-size: 0.85em;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
}

.mip-sub-condition-buttons .btn-small:hover {
    background: var(--primary-color);
    color: #000;
}

.mip-sub-condition-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
    padding: 8px;
    background: rgba(0, 255, 0, 0.05);
    border-radius: 4px;
    border-left: 3px solid var(--primary-color);
}

.mip-sub-condition-row .logic-label {
    font-weight: bold;
    color: var(--primary-color);
    min-width: 35px;
}

.mip-sub-condition-row select,
.mip-sub-condition-row input {
    padding: 6px 8px;
    font-size: 0.9em;
}

.mip-sub-condition-row .remove-sub {
    background: #ff4444;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.85em;
}

.mip-sub-condition-row .remove-sub:hover {
    background: #ff6666;
}

/* Display sub-conditions in condition list */
.mip-condition-subs {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: 4px;
    padding-left: 10px;
    border-left: 2px solid var(--border-color);
}

/* Channel Settings Modal */
.channel-settings-list {
    max-height: 300px;
    overflow-y: auto;
}

.channel-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    background: var(--bg-darker);
    border-radius: 6px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
}

.channel-row-main {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.channel-webhook-row {
    display: flex;
    width: 100%;
}

.channel-webhook {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-size: 12px;
    font-family: var(--font-mono);
}

.channel-webhook:focus {
    outline: none;
    border-color: var(--primary-color);
}

.channel-webhook::placeholder {
    color: var(--text-muted);
}

.channel-color-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.channel-color-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.channel-color-row input[type="color"] {
    width: 28px;
    height: 22px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    cursor: pointer;
    background: transparent;
    padding: 0;
}

.btn-reset-colors {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: auto;
}

.channel-name {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.95em;
    color: var(--primary-color);
}

.channel-option {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.channel-option input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.channel-icon {
    font-size: 1.1em;
    opacity: 0.7;
}

.channel-option input:checked + .channel-icon {
    opacity: 1;
}

.no-channels {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
    font-style: italic;
}

.input-container {
    padding: 15px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#command-input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-darker);
    color: var(--text-color);
    font-family: 'Consolas', monospace;
    font-size: 1em;
    resize: none;
    overflow-y: hidden;
    min-height: 42px;
    max-height: 150px;
    line-height: 1.4;
    box-sizing: border-box;
}

#command-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

#send-btn {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: #000;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

#send-btn:hover {
    background: var(--primary-dark);
}

/* Side Panel */
.side-panel {
    width: 350px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
}

.side-panel.open {
    display: flex;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
    font-size: 1.1em;
    color: var(--primary-color);
}

.panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5em;
    cursor: pointer;
    line-height: 1;
}

.panel-close:hover {
    color: var(--text-color);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Settings panel with sticky footer */
.panel-content:has(.settings-sticky-footer) {
    display: flex;
    flex-direction: column;
    padding: 0;
}

.settings-scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 10px;
}

.settings-sticky-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-darker);
    flex-shrink: 0;
    display: flex;
    gap: 10px;
}

.settings-sticky-footer .btn {
    flex: 1;
    padding: 10px 20px;
}

.settings-sticky-footer .btn.saved {
    background: var(--primary-color);
    color: #000;
}

.settings-support-link {
    text-align: center;
    padding: 15px 20px 5px;
    margin-top: 10px;
    border-top: 1px solid var(--border-color);
}

.settings-support-link a {
    color: #666;
    text-decoration: none;
    font-size: 0.85em;
    transition: color 0.3s;
}

.settings-support-link a:hover {
    color: #ffdd00;
}

/* Scripts Sidebar (docked, resizable) */
.scripts-sidebar {
    position: relative;
    width: 320px;
    min-width: 200px;
    max-width: 600px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    z-index: 50;
}

.scripts-sidebar.open {
    display: flex;
}

.scripts-resize-handle {
    position: absolute;
    left: -5px;
    top: 0;
    bottom: 0;
    width: 10px;
    cursor: ew-resize;
    z-index: 51;
}

.scripts-resize-handle:hover,
.scripts-resize-handle.dragging {
    background: linear-gradient(90deg, transparent, var(--primary-color), transparent);
    opacity: 0.5;
}

.scripts-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-darker);
}

.scripts-sidebar-header h3 {
    font-size: 1em;
    color: var(--primary-color);
    margin: 0;
}

.scripts-sidebar-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3em;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.scripts-sidebar-close:hover {
    color: var(--text-color);
}

.scripts-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.scripts-sidebar-footer {
    padding: 10px 15px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-darker);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.scripts-sidebar-footer .btn {
    flex: 1;
}

.scripts-sidebar-footer .btn-close-sidebar {
    flex: none;
    padding: 6px 15px;
}

/* Class Section */
.class-section {
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-darker);
    overflow: hidden;
}

.class-section.disabled {
    opacity: 0.6;
}

.class-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    user-select: none;
}

.class-header:hover {
    background: rgba(0, 0, 0, 0.3);
}

.class-header.drag-over {
    background: rgba(100, 200, 255, 0.15);
    outline: 1px dashed #8cf;
    outline-offset: -1px;
}

.class-expand {
    width: 20px;
    color: var(--text-muted);
    font-size: 0.8em;
    transition: transform 0.2s;
}

.class-section.expanded .class-expand {
    transform: rotate(90deg);
}

.class-name {
    flex: 1;
    min-width: 0;
    font-weight: bold;
    font-size: 0.9em;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.class-count {
    flex-shrink: 0;
    font-size: 0.75em;
    color: var(--text-muted);
    margin-right: 8px;
}

.class-toggle {
    flex-shrink: 0;
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
}

.class-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.2s;
}

.class-toggle.enabled {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.class-toggle.enabled::after {
    left: 18px;
    background: #000;
}

.class-actions {
    flex-shrink: 0;
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

.class-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 0.8em;
}

.class-actions button:hover {
    color: var(--text-color);
}

.class-items {
    display: none;
    padding: 5px;
}

.class-section.expanded .class-items {
    display: block;
}

/* Script Item (trigger/alias in sidebar) */
.script-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    margin: 2px 0;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: background 0.15s;
}

.script-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.script-item[draggable="true"] {
    cursor: grab;
}

.script-item.dragging {
    opacity: 0.35;
}

.script-item.disabled {
    opacity: 0.5;
}

.script-item-icon {
    width: 20px;
    font-size: 0.7em;
    color: var(--text-muted);
    text-transform: uppercase;
}

.script-item-icon.trigger {
    color: #ff9966;
}

.script-item-icon.alias {
    color: #66ccff;
}

.script-item-icon.gag {
    color: #999999;
}

.script-item-icon.highlight {
    color: #ffff66;
}

.script-item-icon.substitute {
    color: #88ccff;
}

.script-item-icon.ticker {
    color: #66ff99;
}

.script-item-name {
    flex: 1;
    font-size: 0.85em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.script-item-toggle {
    width: 28px;
    height: 16px;
    border-radius: 8px;
    background: var(--bg-darker);
    border: 1px solid var(--border-color);
    cursor: pointer;
    position: relative;
    margin-left: 5px;
}

.script-item-toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.2s;
}

.script-item-toggle.enabled::after {
    left: 14px;
    background: var(--primary-color);
}

.script-item-actions {
    display: none;
    gap: 2px;
    margin-left: 5px;
}

.script-item:hover .script-item-actions {
    display: flex;
}

.script-item-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    font-size: 0.75em;
}

.script-item-actions button:hover {
    color: var(--error-color);
}

/* Unassigned Section */
.unassigned-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.unassigned-header {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-bottom: 5px;
    padding: 0 5px;
}

.unassigned-section.drag-over {
    background: rgba(100, 200, 255, 0.1);
    outline: 1px dashed #8cf;
    outline-offset: -1px;
    border-radius: 4px;
}

/* Add buttons in sidebar */
.sidebar-add-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 10px;
}

.sidebar-add-buttons button {
    flex: 1 1 45%;
    min-width: 70px;
    font-size: 0.8em;
    padding: 6px 8px;
}

.panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.panel-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9em;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.panel-tab:hover {
    color: var(--text-color);
}

.panel-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.9em;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-darker);
    color: var(--text-color);
    font-size: 0.95em;
}

.form-group input[type="checkbox"] {
    width: auto;
    padding: 0;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input[type="color"] {
    height: 40px;
    padding: 5px;
    cursor: pointer;
}

.form-group input[type="range"] {
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 10px;
}

.form-row .form-group {
    flex: 1;
}

.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.8em;
    color: #888;
}

/* Color Preset Grid */
.color-preset-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}

.color-preset {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.color-preset:hover {
    transform: scale(1.1);
    border-color: #fff;
}

.color-preset.selected {
    border-color: #fff;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: #000;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-danger {
    background: var(--error-color);
    color: #fff;
}

.btn-danger:hover {
    background: #cc3333;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85em;
}

/* List Items */
.item-list {
    list-style: none;
}

.item-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-darker);
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.item-list li.disabled {
    opacity: 0.5;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-weight: bold;
    margin-bottom: 4px;
    word-break: break-word;
}

.item-pattern {
    font-family: monospace;
    font-size: 0.85em;
    color: var(--text-muted);
    word-break: break-all;
}

.item-actions {
    display: flex;
    gap: 8px;
    margin-left: 10px;
}

.item-actions button {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.8em;
}

.item-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.item-actions button.delete:hover {
    background: var(--error-color);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-panel);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

#mip-conditions-modal .modal {
    max-width: 650px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.2em;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

/* Settings Panel */
.settings-section {
    margin-bottom: 25px;
}

.settings-section h4 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1em;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.settings-hint {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: 8px;
    margin-bottom: 0;
}

.color-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 5px;
}

.color-preview span {
    padding: 5px 10px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

/* Export Options */
.export-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
}

.export-options .checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    cursor: pointer;
}

.export-options input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Copy mode segmented control */
.copy-mode-group {
    display: flex;
    border: 1px solid #444;
    border-radius: 6px;
    overflow: hidden;
}
.copy-mode-opt {
    flex: 1;
    text-align: center;
    padding: 7px 0;
    font-size: 0.85em;
    color: #aaa;
    cursor: pointer;
    border-right: 1px solid #444;
    transition: background 0.15s, color 0.15s;
    margin: 0;
}
.copy-mode-opt:last-child { border-right: none; }
.copy-mode-opt input { display: none; }
.copy-mode-opt:hover { background: #2a2a2a; }
.copy-mode-opt.selected { background: #1a3a5c; color: #fff; }

/* Script Files List */
.script-files-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px;
    background: var(--bg-darker);
}

.script-file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
}

.script-file-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.script-file-name {
    flex: 1;
    font-size: 0.9em;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.script-file-item .btn {
    padding: 4px 8px;
    font-size: 0.8em;
    min-width: 28px;
}

.script-folder-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    color: #8cf;
}

.script-folder-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.script-folder-item .folder-icon {
    font-size: 0.85em;
}

.script-folder-item .folder-name {
    flex: 1;
    font-family: monospace;
}

.script-folder-item .btn {
    padding: 2px 6px;
    font-size: 0.75em;
    min-width: 22px;
    opacity: 0;
    transition: opacity 0.15s;
}

.script-folder-item:hover .btn {
    opacity: 1;
}

.script-folder-contents {
    padding-left: 16px;
}

.script-folder-contents.collapsed {
    display: none;
}

.script-files-list .folder-actions-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.script-files-list .folder-actions-bar .btn {
    font-size: 0.8em;
    padding: 4px 10px;
}

/* Drag-and-drop states */
.script-file-item.dragging {
    opacity: 0.35;
}

.script-file-item[draggable="true"] {
    cursor: grab;
}

.script-file-item[draggable="true"]:active {
    cursor: grabbing;
}

.script-folder-item.drag-over {
    background: rgba(100, 200, 255, 0.15);
    outline: 1px dashed #8cf;
    outline-offset: -1px;
    border-radius: 4px;
}

.btn-danger {
    background: #c44;
    color: #fff;
}

.btn-danger:hover {
    background: #a33;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state p {
    margin-bottom: 15px;
}

/* Toggle Switch - Generic Styles */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-switch input {
    display: none;
}

.toggle-switch label {
    position: relative;
    width: 50px;
    height: 26px;
    background: var(--bg-darker);
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle-switch label::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.3s;
}

.toggle-switch input:checked + label {
    background: var(--primary-color);
}

.toggle-switch input:checked + label::after {
    left: 27px;
    background: #000;
}

/* Settings Panel Toggle Rows */
.settings-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-toggle:last-child {
    border-bottom: none;
}

.settings-toggle-label {
    color: var(--text-color);
    font-size: 0.95em;
}

.settings-toggle-switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
    flex-shrink: 0;
    margin-left: 15px;
}

.settings-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.settings-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-darker);
    border: 1px solid var(--border-color);
    transition: 0.3s;
    border-radius: 24px;
}

.settings-toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    transition: 0.3s;
    border-radius: 50%;
}

.settings-toggle-switch input:checked + .settings-toggle-slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.settings-toggle-switch input:checked + .settings-toggle-slider:before {
    transform: translateX(22px);
    background-color: #000;
}

/* MIP disabled state - grey out sub-options */
.mip-disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-darker);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Actions Panel */
.action-list {
    margin-top: 10px;
}

.action-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-bottom: 5px;
}

.action-item > select.action-type {
    flex: 0 0 auto;
    width: auto;
    min-width: 140px;
}

.action-item input,
.action-item textarea {
    flex: 1;
    min-width: 0;
}

.action-item textarea {
    resize: vertical;
    font-family: inherit;
    font-size: inherit;
}

.action-item > .remove-action {
    flex: 0 0 auto;
}

.add-action-btn {
    margin-top: 10px;
}

.action-fields {
    flex: 1;
    min-width: 0;
}

.action-fields textarea,
.action-fields input {
    width: 100%;
    box-sizing: border-box;
}

.discord-fields {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.discord-fields input {
    width: 100%;
}

.action-webhook {
    font-size: 0.9em;
}

.action-message {
    font-size: 0.9em;
}

.highlight-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.highlight-colors {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.highlight-styles {
    display: flex;
    align-items: center;
    gap: 12px;
}

.highlight-fields label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
    color: #aaa;
}

.highlight-fields .bg-color-label input[type="color"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.highlight-fields input[type="color"] {
    width: 40px;
    height: 28px;
    padding: 0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
}

.highlight-fields input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Blink animation for highlighted text */
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.gag-note {
    color: #888;
    font-style: italic;
    font-size: 0.9em;
}

.chatmon-fields {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.chatmon-fields input {
    width: 100%;
}

.action-chatmon-msg {
    font-size: 0.9em;
}

.action-chatmon-channel {
    font-size: 0.85em;
    max-width: 150px;
}

/* Responsive - Large screens (below 1200px) */
@media (max-width: 1200px) {
    .header-right {
        gap: 8px;
    }

    .header-btn {
        padding: 6px 12px;
        font-size: 0.85em;
    }

    .mip-stat-block {
        min-width: 80px;
        max-width: 150px;
    }
}

/* Responsive - Medium screens (below 1024px) */
@media (max-width: 1024px) {
    .header {
        padding: 8px 12px;
    }

    .header-left {
        gap: 12px;
    }

    .logo {
        font-size: 1.2em;
    }

    .header-right {
        gap: 6px;
    }

    .header-btn {
        padding: 5px 10px;
        font-size: 0.8em;
    }

    /* Hide less critical buttons on medium screens */
    #disconnect-btn {
        display: none;
    }

    .mip-row-secondary {
        flex-wrap: wrap;
        gap: 10px;
    }

}

/* Responsive - Small screens (below 768px) */
@media (max-width: 768px) {
    /* Settings panel - full screen on mobile */
    .side-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        z-index: 100;
    }

    /* Ensure panel content area scrolls properly */
    .side-panel .panel-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .side-panel .panel-header {
        padding-top: calc(15px + env(safe-area-inset-top, 0px));
    }

    /* Scripts/Actions sidebar - full screen on mobile */
    .scripts-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        min-width: unset;
        z-index: 100;
        border-left: none;
    }

    .scripts-sidebar .scripts-sidebar-header {
        padding-top: calc(15px + env(safe-area-inset-top, 0px));
    }

    .scripts-sidebar .scripts-sidebar-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    /* Hide resize handle on mobile */
    .scripts-resize-handle {
        display: none;
    }

    .header {
        gap: 8px;
        padding: 8px 10px;
        /* iOS safe area - fixed minimum + safe area for notch */
        padding-top: max(25px, calc(8px + env(safe-area-inset-top, 12px)));
    }

    .header-left {
        gap: 8px;
    }

    .logo {
        font-size: 1.1em;
    }

    .connection-status {
        font-size: 0.8em;
    }

    /* Hide regular header buttons on small screens, but keep character dropdown */
    .header-right > .header-btn,
    .header-right > .header-dropdown:not(.hamburger-container):not(.character-dropdown) {
        display: none !important;
    }

    .header-right {
        gap: 8px;
    }

    /* Show hamburger menu */
    .hamburger-container {
        display: block !important;
    }

    .hamburger-btn {
        display: flex !important;
    }

    /* Compact character button on mobile */
    .character-btn {
        padding: 4px 8px;
        font-size: 0.8em;
    }

    .user-info {
        display: none;
    }

    #logout-btn {
        display: none;
    }

    /* MIP Status Bar - Compact horizontal layout on small screens */
    .mip-status-bar {
        padding: 4px 8px;
        gap: 4px;
    }

    .mip-row {
        gap: 6px;
    }

    .mip-row-primary {
        flex-wrap: nowrap;  /* Keep HP/SP/GP/Enemy on one line */
    }

    /* Hide enemy name on mobile - just show % */
    .mip-stat-block.enemy .stat-enemy-name {
        display: none;
    }

    /* Compact inline stat blocks */
    .mip-stat-block {
        flex-direction: row;
        align-items: center;
        gap: 4px;
        min-width: auto;
        max-width: none;
        flex: 1 1 auto;  /* Allow shrinking to fit */
    }

    .mip-stat-block .stat-header {
        flex-direction: row;
        gap: 4px;
    }

    .mip-stat-block .stat-label {
        font-size: 0.65em;
    }

    .mip-stat-block .stat-value {
        font-size: 0.8em;
        white-space: nowrap;
    }

    .mip-stat-block .stat-bar {
        display: none;
    }

    /* Keep icons visible, add spacing */
    .mip-stat-block .stat-icon {
        width: 14px;
        height: 14px;
    }

    .mip-row-primary {
        gap: 12px;
    }

    /* Guild lines and location - compact, allow wrapping */
    .mip-row-secondary {
        font-size: 0.75em;
        gap: 6px 12px;
        flex-wrap: wrap;
    }

    .mip-guild-line {
        /* Flexbox wraps at item boundaries, gap handles spacing */
        gap: 0.2em 0.5em;
        line-height: 1.3;
        width: 100%;
    }

    .mip-location {
        margin-left: 0;
        width: 100%;
        flex-direction: row;
        gap: 8px;
    }

    .mip-room, .mip-exits {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mip-room {
        max-width: 60%;
        flex-shrink: 1;
    }

    .mip-exits {
        color: var(--text-muted);
        flex-shrink: 1;
    }

    /* ChatMon - anchor to top half on mobile */
    .chat-window.floating {
        position: fixed !important;
        top: 60px !important;
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        height: 45vh !important;
        min-height: 150px;
        max-height: 50vh;
        border-radius: 0;
        resize: none;
    }

    .chat-window.docked {
        height: 40vh;
        max-height: 45vh;
    }

    /* Simplify chat controls on mobile */
    .chat-controls .chat-btn:not(.chat-close) {
        display: none;
    }

    /* Full-screen modals on mobile - no keyboard fighting */
    .modal-overlay {
        padding: 0;
        align-items: stretch;
    }

    .modal {
        max-width: none;
        max-height: none;
        height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        flex-shrink: 0;
        padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }

    /* Channel Settings - fill available space on mobile */
    .channel-settings-list {
        max-height: none;
        flex: 1;
    }
}

/* Responsive - Extra small screens (below 480px) */
@media (max-width: 480px) {
    .header {
        padding: 6px 8px;
        padding-top: max(25px, calc(6px + env(safe-area-inset-top, 12px)));
    }

    .header-left {
        gap: 6px;
    }

    .logo {
        font-size: 1em;
    }

    .connection-status .status-text {
        display: none;
    }

    /* Even more compact MIP bar */
    .mip-status-bar {
        padding: 3px 6px;
        gap: 3px;
    }

    .mip-row-primary {
        gap: 6px;  /* Tighter on very small screens */
    }

    .mip-stat-block .stat-label {
        font-size: 0.55em;
    }

    .mip-stat-block .stat-value {
        font-size: 0.7em;
    }

    .mip-stat-block .stat-icon {
        width: 10px;
        height: 10px;
    }


    .mip-row-secondary {
        font-size: 0.65em;
        gap: 4px 8px;
    }

    .mip-guild-line {
        font-size: 0.9em;
    }

    .mip-location {
        gap: 6px;
    }

    .mip-room {
        max-width: 50%;
    }
}

/* ==========================================
   Chat Window Styles
   ========================================== */

.chat-window {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 50;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.chat-window.hidden {
    display: none !important;
}

/* Docked mode - at top of main content */
.chat-window.docked {
    position: relative;
    width: 100%;
    height: 25vh;
    min-height: 100px;
    max-height: 40vh;
    border-radius: 0;
    resize: vertical;
    overflow: hidden;
    flex-shrink: 0;
}

/* Floating mode - draggable/resizable */
.chat-window.floating {
    position: fixed;
    top: 100px;
    left: 100px;
    width: 500px;
    height: 350px;
    min-width: 300px;
    min-height: 200px;
    border-radius: 8px;
    resize: both;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-color);
    cursor: move;
    user-select: none;
    flex-shrink: 0;
}

.chat-window.docked .chat-header {
    cursor: default;
}

.chat-title {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 0.95em;
}

.chat-controls {
    display: flex;
    gap: 4px;
}

.chat-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-btn:hover {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
}

.chat-btn.active {
    background: var(--primary-color);
    color: #000;
    border-color: var(--primary-color);
}

.chat-btn.chat-close:hover {
    background: #ff4444;
    border-color: #ff4444;
    color: white;
}

.chat-btn svg {
    width: 14px;
    height: 14px;
}

.chat-output {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    font-family: var(--mud-font-family);
    font-size: var(--mud-font-size);
    line-height: 1.4;
    background: var(--bg-main);
}

.chat-output .chat-line {
    margin-bottom: 4px;
    padding: 2px 4px;
    border-radius: 2px;
}

.chat-output .chat-line.tell {
    background: rgba(255, 100, 100, 0.1);
    border-left: 2px solid #ff6464;
    padding-left: 8px;
}

.chat-output .chat-line.channel {
    background: rgba(100, 200, 255, 0.1);
    border-left: 2px solid #64c8ff;
    padding-left: 8px;
}

.chat-input-container {
    display: flex;
    gap: 8px;
    padding: 10px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    font-family: var(--mud-font-family);
    font-size: var(--mud-font-size);
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.chat-send-btn {
    padding: 8px 16px;
    background: var(--primary-color);
    color: #000;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.chat-send-btn:hover {
    background: var(--primary-hover);
}

.chat-resize-handle {
    display: none;
}

.chat-window.floating .chat-resize-handle {
    display: block;
    position: absolute;
    bottom: 0;
    right: 0;
    width: 15px;
    height: 15px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, var(--border-color) 50%);
}

/* Output container takes remaining space when chat is docked */
.terminal-area.chat-docked .output-container {
    flex: 1;
    min-height: 0;
}

/* Side-docked modes (left/right) - desktop only */
.terminal-area.chat-docked-left,
.terminal-area.chat-docked-right {
    flex-direction: row;
    align-items: stretch;
}

.terminal-area.chat-docked-left .output-container,
.terminal-area.chat-docked-right .output-container {
    flex: 1;
    min-width: 0;
    height: auto;
}

/* Left-docked chat window */
.chat-window.docked-left {
    position: relative;
    width: 30%;
    min-width: 250px;
    max-width: 500px;
    height: 100%;
    border-radius: 0;
    resize: horizontal;
    overflow: hidden;
    flex-shrink: 0;
    order: -1; /* Place before output container */
}

/* Right-docked chat window */
.chat-window.docked-right {
    position: relative;
    width: 30%;
    min-width: 250px;
    max-width: 500px;
    height: 100%;
    border-radius: 0;
    resize: horizontal;
    overflow: hidden;
    flex-shrink: 0;
    order: 1; /* Place after output container (which defaults to order: 0) */
}

/* No drag cursor when side-docked */
.chat-window.docked-left .chat-header,
.chat-window.docked-right .chat-header {
    cursor: default;
}

/* Chat button notification indicator */
#chat-toggle-btn.has-new {
    position: relative;
    animation: chat-glow 1.5s ease-in-out infinite;
}

#chat-toggle-btn.has-new::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    animation: notification-pulse 1s ease-in-out infinite;
}

@keyframes chat-glow {
    0%, 100% { box-shadow: 0 0 5px var(--primary-color); }
    50% { box-shadow: 0 0 15px var(--primary-color); }
}

@keyframes notification-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.2); }
}

/* Chat window notification highlight */
.chat-window.has-new .chat-header {
    background: linear-gradient(90deg, var(--bg-panel), rgba(68, 221, 68, 0.2));
    animation: header-glow 1.5s ease-in-out infinite;
}

@keyframes header-glow {
    0%, 100% { border-bottom-color: var(--border-color); }
    50% { border-bottom-color: var(--primary-color); }
}

#chat-toggle-btn.active {
    background: var(--primary-color);
    color: #000;
}

/* ==========================================
   iOS PWA (Standalone) Safe Area Handling
   Only applies when installed as web app
   ========================================== */

@media (display-mode: standalone) {
    /* Header - add safe area padding for notch/dynamic island */
    .header {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }

    /* Input container - add safe area padding for home indicator */
    .input-container {
        padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }

    /* Side panel - offset from top for status bar */
    .side-panel {
        top: env(safe-area-inset-top, 0px);
    }

    /* Modal headers - safe area for close button */
    .modal-header {
        padding-top: calc(15px + env(safe-area-inset-top, 0px));
    }
}

/* PWA on smaller screens */
@media (display-mode: standalone) and (max-width: 768px) {
    .header {
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }

    .input-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    /* Settings panel - full screen in PWA mode */
    .side-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
    }

    .side-panel .panel-header {
        padding-top: calc(15px + env(safe-area-inset-top, 0px));
    }

    .side-panel .panel-content {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .modal-header {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }

    /* Scripts/Actions sidebar - full screen in PWA mode */
    .scripts-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        min-width: unset;
    }

    .scripts-sidebar .scripts-sidebar-header {
        padding-top: calc(15px + env(safe-area-inset-top, 0px));
    }

    .scripts-sidebar .scripts-sidebar-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

@media (display-mode: standalone) and (max-width: 480px) {
    .header {
        padding-top: calc(6px + env(safe-area-inset-top, 0px));
    }

    .input-container {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    /* Settings panel - full screen in PWA mode */
    .side-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
    }

    .side-panel .panel-header {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }

    .side-panel .panel-content {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    .modal-header {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }

    /* Scripts/Actions sidebar - full screen in PWA mode */
    .scripts-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        min-width: unset;
    }

    .scripts-sidebar .scripts-sidebar-header {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }

    .scripts-sidebar .scripts-sidebar-footer {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
}

/* ─── Bot Control Panel ──────────────────────────────── */
.bot-panel {
    padding: 0;
}

.bot-status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
}
.bot-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.bot-idle { background: #1a1a2a; }
.bot-idle .bot-status-dot { background: #666; }
.bot-running { background: #1a2a1a; }
.bot-running .bot-status-dot { background: #4f4; animation: bot-pulse 1.5s infinite; }
.bot-paused { background: #2a2a1a; }
.bot-paused .bot-status-dot { background: #fa0; }
.bot-combat { background: #2a1a1a; }
.bot-combat .bot-status-dot { background: #f44; animation: bot-pulse 0.8s infinite; }

@keyframes bot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.bot-name {
    margin-left: auto;
    font-weight: 400;
    color: #999;
    font-size: 12px;
}

.bot-progress-section {
    margin-bottom: 12px;
}
.bot-step-info {
    font-size: 12px;
    color: #aaa;
    margin-bottom: 4px;
    text-align: center;
}
.bot-progress-bar {
    height: 6px;
    background: #222;
    border-radius: 3px;
    overflow: hidden;
}
.bot-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4a4, #6f6);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.bot-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}
.bot-ctrl-btn {
    flex: 1;
    padding: 10px !important;
    font-size: 13px !important;
}

.bot-stats-section {
    background: #111;
    border-radius: 6px;
    padding: 10px 12px;
}
.bot-stat {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 13px;
    color: #aaa;
}
.bot-stat strong {
    color: #ddd;
}

.bot-fav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #555;
    padding: 0 4px;
    vertical-align: middle;
    transition: color 0.15s;
}
.bot-fav-btn:hover { color: #e8a83c; }
.bot-fav-btn.active { color: #e8a83c; }
