/* ====================================================================
   Claude Code Web Wrapper - Styles
   モバイルファーストアプローチ
==================================================================== */

/* ====================================================================
   CSS Variables & Root Styles
==================================================================== */
:root {
    /* Color Scheme - Dark Theme (Default) */
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #404040;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #888888;
    --border-color: #444444;
    --input-border: #555555;
    
    /* Accent Colors */
    --accent-primary: #00ff88;
    --accent-secondary: #ff6b6b;
    --accent-tertiary: #4dabf7;
    --accent-warning: #ffd43b;
    
    /* Status Colors */
    --status-connected: #51cf66;
    --status-connecting: #ffd43b;
    --status-disconnected: #ff6b6b;
    --status-activity: #4dabf7;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.5);
    
    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Light Theme */
@media (prefers-color-scheme: light) {
    :root {
        --bg-primary: #ffffff;
        --bg-secondary: #f8f9fa;
        --bg-tertiary: #e9ecef;
        --text-primary: #212529;
        --text-secondary: #495057;
        --text-muted: #6c757d;
        --border-color: #dee2e6;
        --input-border: #ced4da;
    }
}

/* ====================================================================
   Reset & Base Styles
==================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    line-height: 1.6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
                 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
}

@supports (height: 100dvh) {
    body {
        height: 100dvh;
    }
}

/* ====================================================================
   Main Layout - CSS Grid
==================================================================== */
.app-container {
    display: grid;
    grid-template-rows: 
        1fr                    /* claude-output */
        auto                   /* mode-buttons */
        auto                   /* input-area */
        auto;                  /* action-buttons (always visible) */
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
    position: relative;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

@supports (height: 100dvh) {
    .app-container {
        min-height: 100dvh;
        max-height: 100dvh;
    }
}

/* ====================================================================
   Claude Output Display Area
==================================================================== */
.claude-output {
    grid-area: 1 / 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    scroll-behavior: smooth;
    
    /* Custom Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

.claude-output::-webkit-scrollbar {
    width: 6px;
}

.claude-output::-webkit-scrollbar-track {
    background: transparent;
}

.claude-output::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.claude-output::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

/* Message Styles */
.message {
    margin-bottom: var(--spacing-lg);
}


.message-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    font-size: 0.875rem;
    color: var(--text-muted);
}

.avatar {
    font-size: 1.25rem;
}

.sender {
    font-weight: 600;
    color: var(--text-secondary);
}

.time {
    margin-left: auto;
    font-size: 0.75rem;
}

.message-content {
    line-height: 1.6;
}

.message-content h2 {
    color: var(--accent-primary);
    margin-bottom: var(--spacing-md);
    font-size: 1.5rem;
    font-weight: 600;
}

.message-content h3 {
    color: var(--text-primary);
    margin: var(--spacing-lg) 0 var(--spacing-sm) 0;
    font-size: 1.125rem;
    font-weight: 600;
}

.message-content p {
    margin-bottom: var(--spacing-md);
    color: var(--text-secondary);
}

.message-content ul, .message-content ol {
    margin: var(--spacing-md) 0;
    padding-left: var(--spacing-xl);
}

.message-content li {
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
}

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

/* Demo Actions */
.demo-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
    flex-wrap: wrap;
}

.demo-button {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.demo-button:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-tertiary);
}

.demo-button:active {
    transform: scale(0.98);
}

/* ====================================================================
   Mode Buttons
==================================================================== */
.mode-buttons {
    grid-area: 2 / 1;
    display: flex;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.mode-button {
    flex: 0 0 auto;
    min-width: 35px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.mode-button:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.mode-button.active {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-sm);
}

.mode-button .icon {
    font-size: 1rem;
}

.mode-button .text {
    font-weight: 600;
}

/* ====================================================================
   Input Area
==================================================================== */
.input-area {
    grid-area: 3 / 1;
    padding: var(--spacing-md) var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.input-textarea {
    width: 100%;
    min-height: 24px;
    max-height: 120px;
    resize: vertical;
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--input-border);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 16px;
    line-height: 1.5;
    transition: all var(--transition-fast);
    outline: none;
}

.input-textarea:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.1);
}

.input-textarea::placeholder {
    color: var(--text-muted);
}

/* ====================================================================
   Action Buttons (Send / Y/N)
==================================================================== */
.action-buttons {
    grid-area: 4 / 1;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    box-shadow: var(--shadow-md);
    min-height: 22px;
    display: flex;
}

.action-button {
    flex: 1;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.action-button:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

.action-button:hover {
    background: var(--bg-tertiary);
}

.action-button:active {
    transform: scale(0.95);
}

/* Send button styling */
.action-button.send-action {
    background: var(--accent-primary);
    color: var(--bg-primary);
}

.action-button.send-action:hover {
    background: var(--accent-tertiary);
    transform: translateY(-1px);
}

/* Y/N button specific colors */
.action-button.yes {
    color: var(--status-connected);
}

.action-button.yes:hover {
    background: rgba(81, 207, 102, 0.1);
}

.action-button.no {
    color: var(--accent-secondary);
}

.action-button.no:hover {
    background: rgba(255, 107, 107, 0.1);
}

.action-button.always {
    color: var(--accent-tertiary);
}

.action-button.always:hover {
    background: rgba(0, 255, 136, 0.1);
}

/* ====================================================================
   Status Indicator
==================================================================== */
.status-indicator {
    position: fixed;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 0.75rem;
    color: var(--text-muted);
    backdrop-filter: blur(10px);
    z-index: 1000;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-disconnected);
    transition: background-color var(--transition-normal);
}

.status-dot.connected {
    background: var(--status-connected);
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background: var(--accent-secondary);
    animation: blink 1s infinite;
}

.status-dot.reconnecting {
    background: var(--accent-warning);
    animation: spin 1s linear infinite;
}

.status-dot.error {
    background: var(--accent-secondary);
    animation: none;
}

.status-dot.demo {
    background: var(--accent-tertiary);
    animation: pulse 3s infinite;
}

.status-dot.connecting {
    background: var(--status-connecting);
    animation: blink 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ====================================================================
   Responsive Design
==================================================================== */

/* Small Mobile (320px～375px) */
@media (max-width: 375px) {
    .mode-buttons {
        padding: var(--spacing-xs) var(--spacing-sm);
        gap: var(--spacing-xs);
    }
    
    .mode-button {
        min-width: 30px;
        font-size: 0.625rem;
    }
    
    .mode-button .text {
        display: none;
    }
    
    .input-area {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .claude-output {
        padding: var(--spacing-md);
        gap: var(--spacing-sm);
    }
    
    .demo-actions {
        flex-direction: column;
    }
}

/* Mobile Touch Optimizations */
@media (max-width: 767px) {
    body {
        -webkit-text-size-adjust: none;
        text-size-adjust: none;
    }
    
    .input-textarea {
        -webkit-appearance: none;
        -webkit-border-radius: 0;
        border-radius: var(--radius-md);
        font-size: 16px !important;
        transform: translateZ(0) scale(1);
        -webkit-transform-style: preserve-3d;
        transform-style: preserve-3d;
        will-change: transform;
    }
    
    .input-textarea:focus {
        -webkit-user-select: text;
        user-select: text;
        -webkit-transform: translateZ(0) scale(1);
        transform: translateZ(0) scale(1);
        -webkit-text-size-adjust: none;
        text-size-adjust: none;
    }
}

/* Tablet (768px～1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .app-container {
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }
    
    .mode-button {
        min-width: 50px;
        font-size: 0.875rem;
    }
    
    .input-textarea {
        font-size: 1rem;
    }
}

/* Desktop (1024px～) */
@media (min-width: 1024px) {
    .app-container {
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        margin-top: var(--spacing-lg);
        margin-bottom: var(--spacing-lg);
        min-height: calc(100vh - 2 * var(--spacing-lg));
        max-height: calc(100vh - 2 * var(--spacing-lg));
    }

    @supports (height: 100dvh) {
        .app-container {
            min-height: calc(100dvh - 2 * var(--spacing-lg));
            max-height: calc(100dvh - 2 * var(--spacing-lg));
        }
    }
    
    body {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        padding: 0;
    }
    
    .mode-buttons {
        gap: var(--spacing-md);
    }
    
    .mode-button {
        min-width: 60px;
        height: 22px;
        font-size: 0.875rem;
    }
    
    .input-textarea {
        font-size: 1rem;
        padding: var(--spacing-lg);
    }
    
    .claude-output {
        padding: var(--spacing-xl);
    }
    
    /* Desktop hover effects */
    .demo-button:hover,
    .mode-button:hover,
    .action-button:hover {
        transform: translateY(-1px);
    }
}

/* ====================================================================
   Accessibility & Motion
==================================================================== */

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .status-dot.connected,
    .status-dot.connecting {
        animation: none;
    }
}

/* High Contrast */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #1a1a1a;
        --text-primary: #ffffff;
        --border-color: #ffffff;
        --accent-primary: #00ff00;
    }
}

/* Focus Styles */
.mode-button:focus,
.yn-button:focus,
.send-button:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.input-textarea:focus {
    outline: none;
}

/* ====================================================================
   Utility Classes
==================================================================== */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ====================================================================
   Loading States
==================================================================== */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}