/* ネットワークシミュレータ - メインスタイル */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ダブルタップズーム無効化 */
html, body {
    touch-action: manipulation; /* ダブルタップズーム無効化 */
    -webkit-text-size-adjust: 100%; /* iOS Safariでのテキストサイズ自動調整無効化 */
    -ms-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    overflow: hidden;
    height: 100vh;
}

/* モバイル・タブレット時はLayoutと協調（タッチデバイス判定） */
@media (max-width: 1024px) and (hover: none) and (pointer: coarse) {
    html, body {
        margin: 0;
        padding: 0;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
    }
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation; /* アプリ全体でダブルタップズーム無効化 */
}

/* 機器パレット（画面上部固定） */
.device-palette {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(env(safe-area-inset-top, 0px) + 4rem);
    height: 100px;
    background: white;
    border-bottom: 1px solid #ddd;
    display: flex;
    flex-direction: row;
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding-left: max(8px, env(safe-area-inset-left, 8px));
    padding-right: max(8px, env(safe-area-inset-right, 8px));
    transition: all 0.2s ease;
}

/* デバイスドラッグ中の削除ゾーン表示 */
.device-palette.delete-zone {
    background: #ffebee !important;
    border: 3px dashed #f44336 !important;
    border-bottom: 3px dashed #f44336 !important;
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3) !important;
}

.device-palette.delete-zone::before {
    content: "🗑️ ここにドロップすると削除されます";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(244, 67, 54, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    pointer-events: none;
    z-index: 10001;
    white-space: nowrap;
}

/* デバイスが削除ゾーン上にある場合の追加エフェクト */
.device-palette.delete-zone.delete-zone-active {
    background: #ffcdd2 !important;
    animation: pulse-delete 0.8s ease-in-out infinite alternate;
}

@keyframes pulse-delete {
    0% {
        box-shadow: 0 4px 12px rgba(244, 67, 54, 0.3);
    }
    100% {
        box-shadow: 0 6px 20px rgba(244, 67, 54, 0.6);
    }
}

.palette-content {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 12px !important;
    padding: 8px;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    width: 100% !important;
    height: 100% !important;
    box-sizing: border-box !important;
    flex-wrap: nowrap !important;
    touch-action: pan-x !important;
    
    /* スクロールバーを非表示にする */
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}

.palette-content::-webkit-scrollbar {
    display: none !important;
}

.device-item {
    flex-shrink: 0;
    width: 70px;
    height: 70px;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    user-select: none;
    box-sizing: border-box;
}

.device-item:hover {
    border-color: #2196f3;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.2);
}

.device-icon {
    font-size: 20px;
    margin-bottom: 4px;
}

.device-name {
    font-size: 10px;
    color: #666;
    font-weight: 500;
    line-height: 1.2;
}

/* メインキャンバス */
.main-canvas {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 4rem + 100px);
    left: env(safe-area-inset-left, 0px);
    right: env(safe-area-inset-right, 0px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 60px);
    background: white;
    overflow: hidden;
}

.canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
    touch-action: none;
}

#network-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 10px 10px, #ddd 1px, transparent 1px),
        radial-gradient(circle at 30px 30px, #ddd 1px, transparent 1px);
    background-size: 20px 20px;
    touch-action: manipulation; /* パン・ズームを許可しつつダブルタップズーム無効化 */
}

/* 状態表示 */
.status-panel {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.9);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

/* TCP状態パネル */
.tcp-status-panel {
    position: absolute;
    top: 80px;
    right: 10px;
    background: rgba(255,255,255,0.95);
    padding: 12px;
    border-radius: 8px;
    font-size: 11px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 250px;
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.tcp-status-panel h4 {
    margin: 0 0 8px 0;
    color: #2196f3;
    font-size: 12px;
}

.tcp-connection-item {
    background: #f8f9fa;
    padding: 6px 8px;
    margin: 4px 0;
    border-radius: 4px;
    border-left: 3px solid #28a745;
}

.tcp-connection-item.syn-sent {
    border-left-color: #ffc107;
}

.tcp-connection-item.established {
    border-left-color: #28a745;
}

.tcp-connection-item.closed {
    border-left-color: #dc3545;
}

/* HTTPステータスパネル */
.http-status-panel {
    position: absolute;
    top: 320px; /* TCPパネルの下、コントロールパネルより上に配置 */
    right: 10px; /* TCPパネルと同じ右端に配置 */
    background: rgba(255,255,255,0.95);
    padding: 12px;
    border-radius: 8px;
    font-size: 11px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    max-width: 250px; /* TCPパネルと同じ幅に調整 */
    max-height: 200px; /* コントロールパネルと重ならないよう高さを制限 */
    overflow-y: auto;
    display: none;
    z-index: 1500;
    pointer-events: auto;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.http-status-panel h4 {
    margin: 0 0 8px 0;
    color: #ff9800;
    font-size: 12px;
}

.http-session-item {
    background: #fff3e0;
    padding: 6px 8px;
    margin: 4px 0;
    border-radius: 4px;
    border-left: 3px solid #ff9800;
}

.http-log {
    background: #f5f5f5;
    padding: 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    max-height: 150px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 8px 0;
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    cursor: text;
}

/* パケットアニメーション */
.packet {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #ff4444;
    border-radius: 50%;
    z-index: 10;
    pointer-events: none;
}

.tcp-segment-animation {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #2196f3;
    border-radius: 50%;
    z-index: 15;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 8px;
    font-weight: bold;
}

.tcp-segment-animation.syn {
    background: #ff9800;
}

.tcp-segment-animation.ack {
    background: #4caf50;
}

.tcp-segment-animation.fin {
    background: #f44336;
}

.tcp-segment-animation.data {
    background: #9c27b0;
}