/**
 * SuperServ Web Client 样式
 * 移动端优先设计
 */

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #3b82f6;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --card-bg: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);

    /* 安全区域 */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-gradient);
    min-height: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    /* 防止 iOS 橡皮筋效果 */
    overscroll-behavior: none;
    /* 安全区域内边距 */
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

.container {
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* 卡片通用样式 */
.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.card + .card {
    margin-top: 0;
}

.card-header {
    text-align: center;
    margin-bottom: 24px;
}

.card-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.card-header .subtitle {
    font-size: 14px;
    color: var(--text-secondary);
}

/* 状态指示器 */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #f3f4f6;
    border-radius: 10px;
    margin-bottom: 16px;
}

.status-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #9ca3af;
    flex-shrink: 0;
}

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

.status-dot.connected {
    background: var(--info-color);
}

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

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

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

.status-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.account-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.account-info span {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 退出按钮 */
.btn-logout {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.btn-logout:active {
    background: rgba(239, 68, 68, 0.1);
    color: var(--error-color);
}

/* 表单样式 */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.2s;
    /* 防止 iOS 缩放 */
    font-size: 16px;
}

.form-group input:focus {
    border-color: var(--primary-color);
}

.form-group input::placeholder {
    color: #9ca3af;
}

/* 按钮样式 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
    /* 触摸优化 */
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:active {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.btn-danger {
    background: var(--error-color);
    color: white;
}

.btn-danger:active {
    background: #dc2626;
}

.btn-secondary {
    background: #f3f4f6;
    color: var(--text-primary);
}

.btn-secondary:active {
    background: #e5e7eb;
}

.btn-secondary.active {
    background: var(--warning-color);
    color: white;
}

/* 加载动画 */
.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

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

/* 拨号输入框 */
.dial-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.dial-input-group input {
    flex: 1;
    min-width: 0;
    padding: 14px 12px;
    font-size: 20px;
    font-weight: 500;
    letter-spacing: 2px;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    background: #f9fafb;
    color: var(--text-primary);
    /* 禁止选中和光标 */
    caret-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

.dial-input-group input:focus {
    border-color: var(--primary-color);
    background: white;
}

/* 退格按钮 */
.btn-backspace {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: #f3f4f6;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.btn-backspace:active {
    background: #e5e7eb;
    transform: scale(0.95);
}

/* 拨号按钮 */
.btn-dial {
    margin-top: 12px;
}

/* 数字键盘 */
.dial-pad, .dtmf-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.dial-pad .key, .dtmf-pad .key {
    aspect-ratio: 1.3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 500;
    background: #f9fafb;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.1s;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

.dial-pad .key:active, .dtmf-pad .key:active {
    background: #e5e7eb;
    transform: scale(0.95);
}

/* 通话界面 */
.calling-card {
    text-align: center;
}

.call-info {
    margin-bottom: 24px;
}

.call-number {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: 1px;
    word-break: break-all;
}

.call-status {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.call-duration {
    font-size: 40px;
    font-weight: 300;
    color: var(--primary-color);
    font-variant-numeric: tabular-nums;
}

/* DTMF 反馈 */
.dtmf-feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 72px;
    font-weight: bold;
    color: rgba(79, 70, 229, 0.7);
    pointer-events: none;
    transition: transform 0.08s;
    z-index: 100;
}

.dtmf-feedback.show {
    transform: translate(-50%, -50%) scale(1);
}

/* 通话控制按钮 */
.call-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.call-controls .btn {
    flex: 1;
    max-width: 140px;
    padding: 14px 16px;
    border-radius: 50px;
    font-size: 14px;
}

.call-controls .btn .icon {
    font-size: 18px;
}

/* 通话记录面板 */
.records-panel {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-radius: 0;
    margin-top: 0;
    margin-bottom: 0;
}

/* 底部标签栏 */
.tab-bar {
    display: flex;
    background: var(--card-bg);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    margin: 0 -12px -12px -12px;
    margin-top: auto;
    flex-shrink: 0;
}

.tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.tab-item.active {
    color: var(--primary-color);
}

.tab-item:active {
    opacity: 0.7;
}

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

.tab-label {
    font-size: 12px;
    font-weight: 500;
}

.records-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.records-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.records-header .btn-text {
    font-size: 13px;
    color: var(--error-color);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 12px;
    margin: -8px -12px;
    touch-action: manipulation;
}

.records-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -20px;
    padding: 0 20px;
}

.record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    touch-action: manipulation;
}

.record-item:last-child {
    border-bottom: none;
}

.record-item:active {
    background: #f9fafb;
    margin: 0 -20px;
    padding-left: 20px;
    padding-right: 20px;
}

.record-info {
    flex: 1;
    min-width: 0;
}

.record-number {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.record-time {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.record-duration {
    font-size: 14px;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-left: 12px;
}

.record-duration.missed {
    color: var(--error-color);
}

.empty-records {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 0;
    font-size: 14px;
}


/* Toast 提示 */
.toast-container {
    position: fixed;
    top: calc(12px + var(--safe-area-top));
    left: 12px;
    right: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 14px 18px;
    border-radius: 12px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow);
    animation: slideDown 0.3s ease;
    pointer-events: auto;
}

.toast.info {
    background: var(--info-color);
}

.toast.success {
    background: var(--success-color);
}

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

.toast.warning {
    background: var(--warning-color);
}

.toast.fade-out {
    animation: fadeUp 0.3s ease forwards;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeUp {
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* 状态卡片 */
.status-card {
    flex-shrink: 0;
    border-radius: 16px 16px 0 0;
    margin-bottom: 0;
    padding: 12px 20px;
}

.status-card .status-bar {
    margin-bottom: 0;
}

/* 内容面板 */
.content-panel {
    flex: 1;
    min-height: 0;
    border-radius: 0;
    margin-top: 0;
    margin-bottom: 0;
}

#dialerCard {
    display: flex;
    flex-direction: column;
}

#dialerCard form {
    flex-shrink: 0;
}

#dialerCard .dial-pad {
    flex-shrink: 0;
}



/* 登录卡片居中 */
#loginCard {
    margin: auto;
    max-width: 360px;
    width: 100%;
}

/* 隐藏元素 */
.hidden {
    display: none !important;
}

/* 小屏幕优化（iPhone SE 等） */
@media (max-height: 600px) {
    .container {
        padding: 8px;
    }

    .card {
        padding: 16px;
        border-radius: 12px;
    }

    .dial-pad, .dtmf-pad {
        gap: 6px;
        margin-bottom: 12px;
    }

    .dial-pad .key, .dtmf-pad .key {
        aspect-ratio: 1.5;
        font-size: 22px;
        border-radius: 10px;
    }

    .call-duration {
        font-size: 32px;
    }

    .card-header {
        margin-bottom: 16px;
    }

    .card-header h1 {
        font-size: 20px;
    }
}

/* 大屏幕优化（平板/横屏） */
@media (min-width: 500px) {
    .container {
        max-width: 420px;
        margin: 0 auto;
        padding: 20px;
    }

    .card {
        border-radius: 20px;
        padding: 24px;
    }

    #loginCard {
        margin-top: 60px;
    }

    .dial-pad .key, .dtmf-pad .key {
        aspect-ratio: 1.2;
        font-size: 28px;
    }
}

/* 横屏模式 */
@media (orientation: landscape) and (max-height: 500px) {
    .container {
        flex-direction: row;
        gap: 12px;
        padding: 8px;
    }

    .card {
        flex: 1;
        margin: 0;
        overflow-y: auto;
    }

    #loginCard {
        max-width: 320px;
        margin: auto;
    }

    .dial-pad, .dtmf-pad {
        gap: 4px;
    }

    .dial-pad .key, .dtmf-pad .key {
        aspect-ratio: 1.8;
        font-size: 18px;
        border-radius: 8px;
    }

    .call-info {
        margin-bottom: 12px;
    }

    .call-number {
        font-size: 20px;
    }

    .call-duration {
        font-size: 28px;
    }
}

/* 通话质量指示器 */
.quality-indicator {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
}

/* 通话中全屏覆盖 */
#callingCard {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card-bg);
    z-index: 100;
    padding: 20px;
    padding-top: calc(20px + var(--safe-area-top));
    padding-bottom: calc(20px + var(--safe-area-bottom));
    display: none;
    flex-direction: column;
}

#callingCard.active {
    display: flex;
}

#callingCard .call-info {
    flex-shrink: 0;
}

#callingCard .dtmf-pad {
    flex-shrink: 0;
}

#callingCard .call-controls {
    margin-top: auto;
    padding-top: 16px;
}

.calling-card {
    position: relative;
}

.signal-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 20px;
    cursor: pointer;
    padding: 8px;
    margin: -8px;
}

.signal-bars .bar {
    width: 5px;
    background: #d1d5db;
    border-radius: 2px;
    transition: background-color 0.2s;
}

.signal-bars .bar:nth-child(1) { height: 5px; }
.signal-bars .bar:nth-child(2) { height: 9px; }
.signal-bars .bar:nth-child(3) { height: 13px; }
.signal-bars .bar:nth-child(4) { height: 17px; }

/* 信号等级颜色 */
.signal-bars.excellent .bar { background: var(--success-color); }
.signal-bars.good .bar.active { background: #84cc16; }
.signal-bars.fair .bar.active { background: var(--warning-color); }
.signal-bars.poor .bar.active { background: var(--error-color); }

.signal-bars.excellent .bar { background: var(--success-color); }

.signal-bars.good .bar:nth-child(1),
.signal-bars.good .bar:nth-child(2),
.signal-bars.good .bar:nth-child(3) { background: #84cc16; }

.signal-bars.fair .bar:nth-child(1),
.signal-bars.fair .bar:nth-child(2) { background: var(--warning-color); }

.signal-bars.poor .bar:nth-child(1) { background: var(--error-color); }

/* 质量详情面板 */
.quality-details {
    position: absolute;
    top: 32px;
    right: 0;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 12px 14px;
    min-width: 140px;
    font-size: 12px;
    z-index: 20;
}

.quality-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.quality-row:not(:last-child) {
    border-bottom: 1px solid #f3f4f6;
}

.quality-row .label {
    color: var(--text-secondary);
}

.quality-row .value {
    font-weight: 500;
    color: var(--text-primary);
}

.quality-row .value.excellent { color: var(--success-color); }
.quality-row .value.good { color: #84cc16; }
.quality-row .value.fair { color: var(--warning-color); }
.quality-row .value.poor { color: var(--error-color); }
