/* ========================================
   CTI System - PIYO SIS
   cti-piyo-sis.com
   ======================================== */

:root {
    /* Color Palette - Warm Professional */
    --color-bg: #0f0f12;
    --color-bg-elevated: #1a1a20;
    --color-bg-card: #22222a;
    --color-bg-hover: #2a2a35;
    
    --color-primary: #f59e0b;
    --color-primary-light: #fbbf24;
    --color-primary-dark: #d97706;
    
    --color-success: #10b981;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    
    --color-text: #f4f4f5;
    --color-text-muted: #a1a1aa;
    --color-text-faint: #71717a;
    
    --color-border: #3f3f46;
    --color-border-light: #52525b;
    
    /* Typography */
    --font-sans: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(245, 158, 11, 0.3);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

/* ========================================
   Reset & Base
   ======================================== */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    font-weight: 400;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(245, 158, 11, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(245, 158, 11, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* ========================================
   Header
   ======================================== */

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 15, 18, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-md) var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    width: 40px;
    height: 40px;
    color: var(--color-primary);
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    background: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border);
}

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

.status-indicator.online {
    background: var(--color-success);
    box-shadow: 0 0 8px var(--color-success);
    animation: pulse 2s infinite;
}

.status-indicator.error {
    background: var(--color-error);
}

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

.status-text {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* ========================================
   Main Content
   ======================================== */

.main-content {
    position: relative;
    z-index: 1;
    padding: var(--space-xl) var(--space-lg);
}

.container {
    max-width: 800px;
    margin: 0 auto;
}

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

.tab-nav {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-xl);
    border: 1px solid var(--color-border);
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
}

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

.tab-btn.active {
    background: var(--color-primary);
    color: var(--color-bg);
}

.tab-icon {
    width: 20px;
    height: 20px;
}

/* ========================================
   Panels & Cards
   ======================================== */

.tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-panel.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.panel-card {
    background: var(--color-bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    overflow: hidden;
    margin-bottom: var(--space-lg);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
}

.card-header p {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

.card-body {
    padding: var(--space-lg);
}

/* ========================================
   Phone Dialer
   ======================================== */

.phone-display {
    margin-bottom: var(--space-lg);
}

.phone-input {
    width: 100%;
    padding: var(--space-lg);
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 500;
    text-align: center;
    letter-spacing: 0.1em;
    transition: all var(--transition-normal);
}

.phone-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--shadow-glow);
}

.phone-input::placeholder {
    color: var(--color-text-faint);
    font-size: 1rem;
    letter-spacing: normal;
}

.phone-format-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--color-text-faint);
    margin-top: var(--space-sm);
}

.dialpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
    max-width: 320px;
    margin: 0 auto var(--space-xl);
}

.dial-btn {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 1.5rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dial-btn small {
    display: block;
    font-size: 0.625rem;
    color: var(--color-text-faint);
    letter-spacing: 0.1em;
    margin-top: 2px;
}

.dial-btn:hover {
    background: var(--color-bg-hover);
    border-color: var(--color-primary);
    transform: scale(1.05);
}

.dial-btn:active {
    transform: scale(0.95);
    background: var(--color-primary);
    color: var(--color-bg);
}

/* ========================================
   Form Elements
   ======================================== */

.input-group {
    margin-bottom: var(--space-lg);
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

.input-group input,
.input-group textarea {
    width: 100%;
    padding: var(--space-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 1rem;
    transition: all var(--transition-normal);
}

.input-group input:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.input-group textarea {
    resize: vertical;
    min-height: 100px;
}

.char-count {
    text-align: right;
    font-size: 0.75rem;
    color: var(--color-text-faint);
    margin-top: var(--space-xs);
}

.char-count.warning {
    color: var(--color-warning);
}

.char-count.error {
    color: var(--color-error);
}

/* ========================================
   Buttons
   ======================================== */

.action-buttons {
    display: flex;
    gap: var(--space-md);
    justify-content: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-xl);
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn svg {
    width: 20px;
    height: 20px;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-bg);
}

.btn-primary:hover {
    background: var(--color-primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

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

.btn-secondary {
    background: var(--color-bg-elevated);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

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

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    padding: var(--space-sm);
}

.btn-ghost:hover {
    color: var(--color-primary);
    background: rgba(245, 158, 11, 0.1);
}

.btn-call {
    min-width: 160px;
    background: linear-gradient(135deg, #10b981, #059669);
}

.btn-call:hover {
    background: linear-gradient(135deg, #34d399, #10b981);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.btn-sms {
    min-width: 160px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ========================================
   Message List
   ======================================== */

.message-list,
.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    color: var(--color-text-faint);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-md);
    opacity: 0.5;
}

.message-item,
.history-item {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    transition: background var(--transition-fast);
}

.message-item:hover,
.history-item:hover {
    background: var(--color-bg-hover);
}

.message-item.outbound {
    flex-direction: row-reverse;
}

.message-bubble {
    max-width: 70%;
    padding: var(--space-md);
    border-radius: var(--radius-lg);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
}

.message-item.outbound .message-bubble {
    background: var(--color-primary);
    color: var(--color-bg);
    border-color: var(--color-primary);
}

.message-meta {
    font-size: 0.75rem;
    color: var(--color-text-faint);
    margin-top: var(--space-xs);
}

.message-item.outbound .message-meta {
    color: rgba(0, 0, 0, 0.5);
    text-align: right;
}

.history-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--color-bg-elevated);
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.history-icon svg {
    width: 20px;
    height: 20px;
}

.history-icon.outbound {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-success);
}

.history-icon.inbound {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.history-content {
    flex: 1;
}

.history-number {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 500;
}

.history-details {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-top: var(--space-xs);
}

.history-time {
    font-size: 0.75rem;
    color: var(--color-text-faint);
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    margin-left: var(--space-sm);
}

.status-badge.completed {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-success);
}

.status-badge.failed,
.status-badge.busy,
.status-badge.no-answer {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-error);
}

.status-badge.queued,
.status-badge.ringing {
    background: rgba(245, 158, 11, 0.15);
    color: var(--color-warning);
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    min-width: 280px;
}

@keyframes slideIn {
    from { 
        opacity: 0; 
        transform: translateX(100%); 
    }
    to { 
        opacity: 1; 
        transform: translateX(0); 
    }
}

.toast.success {
    border-left: 4px solid var(--color-success);
}

.toast.error {
    border-left: 4px solid var(--color-error);
}

.toast.warning {
    border-left: 4px solid var(--color-warning);
}

.toast-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--color-success); }
.toast.error .toast-icon { color: var(--color-error); }
.toast.warning .toast-icon { color: var(--color-warning); }

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 500;
    margin-bottom: 2px;
}

.toast-message {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.toast-close {
    background: none;
    border: none;
    color: var(--color-text-faint);
    cursor: pointer;
    padding: var(--space-xs);
    transition: color var(--transition-fast);
}

.toast-close:hover {
    color: var(--color-text);
}

/* ========================================
   Loading Overlay
   ======================================== */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 18, 0.9);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-lg);
    z-index: 2000;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-text {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

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

@media (max-width: 640px) {
    .header-content {
        padding: var(--space-md);
    }
    
    .logo-text {
        font-size: 1rem;
    }
    
    .main-content {
        padding: var(--space-md);
    }
    
    .tab-nav {
        padding: var(--space-xs);
    }
    
    .tab-btn {
        padding: var(--space-sm);
        font-size: 0.8125rem;
    }
    
    .tab-btn .tab-icon {
        display: none;
    }
    
    .phone-input {
        font-size: 1.25rem;
        padding: var(--space-md);
    }
    
    .dialpad {
        max-width: 280px;
    }
    
    .dial-btn {
        font-size: 1.25rem;
    }
    
    .card-header,
    .card-body {
        padding: var(--space-md);
    }
    
    .toast-container {
        left: var(--space-md);
        right: var(--space-md);
        bottom: var(--space-md);
    }
    
    .toast {
        min-width: auto;
    }
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-border-light);
}
