/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* San Francisco on Apple (SF Pro); falls back elsewhere */
    --font-simulator-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-urbanist: 'Urbanist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --primary-color: #0c79ba;
    --secondary-color: #2196F3;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --dark-bg: #1a1a1a;
    --light-bg: #f5f5f5;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
    font-family: 'Urbanist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    /* background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); */
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

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

/* Header */
.header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Phone Panel */
.phone-panel {
    padding-top: 30px;
    position: relative;
}

/* Phone Container */
.phone-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 600px;
    position: relative;
}

/* Single handset mockup (static/images/iphone.svg as frame background) */
.phone-device {
    position: relative;
    transition: all 0.3s ease;
    width: min(380px, 100%);
    max-width: 380px;
    flex-shrink: 0;
    background: transparent;
    padding: 0;
    font-family: var(--font-simulator-ui);
}

.phone-device input,
.phone-device button,
.phone-device select,
.phone-device textarea {
    font-family: inherit;
}

.phone-frame {
    position: relative;
    display: block;
    width: 100%;
    max-width: 380px;
}

/* SVG background; padding-bottom gives height (only absolute overlay inside). */
.phone-device .phone-frame {
    height: 0;
    padding-bottom: calc(884 / 441 * 100%);
    background-image: var(--device-skin, none);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: contain;
    /* border-radius: 48px; */
    /* box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35); */
}

.phone-screen-area {
    position: absolute;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
    box-sizing: border-box;
    z-index: 1;
    /* viewBox 441×884 — screen rect x=26 y=20 w=390 h=844 */
    left: 5.894%;
    top: 2.263%;
    right: 5.666%;
    bottom: 2.262%;
    width: auto;
    height: auto;
    border-radius: 40px;
}

/* Asset already includes status bar — hide duplicate chrome */
.phone-device .phone-header,
.phone-device .phone-footer,
.phone-device .phone-notch {
    display: none;
}

.phone-device .phone-screen {
    flex: 1;
    min-height: 0;
    border-radius: inherit;
    background: transparent;
    padding-top: clamp(44px, 11%, 56px);
}

/* Phone Header */
.phone-header {
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    position: relative;
}

.phone-status {
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-size: 0.75rem;
    position: absolute;
    top: 8px;
    left: 20px;
}

.status-network {
    font-weight: 500;
}

/* Phone Screen */
.phone-screen {
    background: white;
    border-radius: 28px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* USSD Header */
.ussd-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #45a049 100%);
    color: white;
    padding: 15px 20px;
    text-align: center;
    font-weight: 500;
    font-size: 1.1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* USSD Content */
.ussd-content {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    background: #595959;
    display: flex;
    flex-direction: column;
}

/* Start Screen — grid pins #startForm to bottom of phone content */
.start-screen {
    flex: 1 1 0;
    min-height: 0;
    padding: 40px 30px;
    text-align: center;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-columns: 1fr;
    align-content: stretch;
}

.start-screen-body {
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow-y: auto;
    text-align: center;
}

.start-screen span {
    margin-top: 50px;
    font-size: 1rem;
    flex-shrink: 0;
    color: var(--light-bg);
    font-family: var(--font-simulator-ui);
}


#startForm {
    width: 100%;
    padding-top: 20px;
    align-self: stretch;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 9px;
    color: var(--light-bg);
    font-size: 0.8rem;
    font-family: var(--font-simulator-ui);

}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 13px;
    border: 0;
    /* border-bottom: 1px solid var(--border-color); */
    /* border-radius: 6px; */
    margin-top: 10px;
    text-align: center;
    color: var(--light-bg);
    background-color: #595959;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
}

.form-group.start-screen-msisdn {
    flex-shrink: 0;
}

.form-group.start-screen-msisdn input {
    margin-top: 1rem;
}

/* Buttons */
.btn-primary {
    width: 100%;
    padding: 14px 28px;
    background: var(--light-bg);
    color: #000000;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    /* font-weight: 500; */
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: var(--font-urbanist);
    /* box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3); */
}

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

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

/* USSD Messages — scroll area (message + input); Send pinned to bottom */
.ussd-messages {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    flex: 1 1 0;
    min-height: 0;
    padding: 20px;
    overflow: hidden;
}

.ussd-messages-scroll {
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.message-display {
    flex-shrink: 0;
    background: #595959;
    padding: 50px 20px 12px 20px;
    white-space: pre-wrap;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--light-bg);
    font-family: var(--font-simulator-ui);
    text-align: center;
    min-height: 120px;
}

.ussd-input-field {
    margin-top: 40px;
    flex-shrink: 0;
    width: 100%;
    padding: 0 4px 8px 4px;
}

.ussd-input-field input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    border: 0;
    text-align: center;
    color: var(--light-bg);
    background-color: #595959;
    font-size: 1rem;
}

.ussd-input-field input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.ussd-response-form {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    padding-top: 8px;
    box-sizing: border-box;
}

/* Only New Session visible — one full-width column */
.ussd-response-form:has(#ussdInputFooter[style*="display: none"]),
.ussd-response-form:has(#ussdInputFooter[style*="display:none"]) {
    grid-template-columns: 1fr;
}

.ussd-response-form .btn-new-session {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.ussd-send-wrap {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    align-items: stretch;
    box-sizing: border-box;
}

.ussd-send-wrap form {
    width: 100%;
    min-width: 0;
    height: 100%;
    display: flex;
}

.ussd-send-wrap .btn-send {
    flex: 1;
    min-width: 0;
}

.btn-send {
    width: 100%;
    padding: 12px 24px;
    background: #000;
    color: white;
    border: none;
    border-radius: 8px;
    /* font-weight: 500; */
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-send:hover {
    cursor: pointer;
}

/* Session ID (under Current Session in history panel) */
.history-session-id {
    padding: 15px 25px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

#sessionIdDisplay {
    color: var(--text-secondary);
    word-break: break-all;
    font-family: 'Courier New', monospace;
}

.btn-new-session {
    padding: 12px 16px;
    background: #fff;
    color: #000;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.btn-new-session:hover {
    cursor: pointer;
}

/* Phone Footer */
.phone-footer {
    height: 30px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.home-indicator {
    width: 120px;
    height: 5px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    border-radius: 20px;
    z-index: 100;
    font-family: var(--font-simulator-ui);
}

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

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

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

.loading-overlay p {
    margin-top: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* History Panel */
.history-panel {
    background: var(--card-bg);
    border-radius: 20px;
    padding: 0;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: 700px;
    display: flex;
    flex-direction: column;
    margin-top: 30px;
    margin-right: 30px;
}

/* Panel Tabs */
.panel-tabs {
    display: flex;
    background: #f5f5f5;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 15px 20px;
    background: transparent;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    position: relative;
    font-family: 'Courier New', monospace;
}

.tab-btn:hover {
    background: rgba(76, 175, 80, 0.1);
}

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

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-color);
}

/* Tab Content */
.tab-content {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.tab-content.active {
    display: flex;
}

/* History Header */
.history-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
}

.history-header h3 {
    font-size: 1.2rem;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

.history-controls {
    display: flex;
    gap: 10px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    outline: none;
}

.btn-icon:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.btn-icon i {
    font-size: 1rem;
    line-height: 1;
}

.btn-icon:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    transform: translateY(-2px);
}

.btn-icon:hover i {
    color: #fff;
}

/* History Content */
.history-content,
.sessions-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 25px;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 1rem;
    font-family: 'Courier New', monospace;
}

/* History Item */
.history-item {
    background: #f9f9f9;
    border-left: 4px solid var(--primary-color);
    padding: 15px;
    margin-bottom: 15px;
    transition: all 0.3s ease;
}

/* .history-item:hover {
    box-shadow: var(--shadow);
    transform: translateX(4px);
} */

.history-item.init {
    border-left-color: var(--secondary-color);
}

.history-item.user-input {
    border-left-color: var(--warning-color);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.history-type {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

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

.history-data {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: white;
    padding: 10px;
    border-radius: 6px;
    max-height: 150px;
    overflow-y: auto;
}

.history-input {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 8px;
}

.history-response {
    white-space: pre-wrap;
    line-height: 1.5;
}

/* Session Card */
.session-card {
    background: #f9f9f9;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    border: 2px solid var(--border-color);
    transition: all 0.3s ease;
}

.session-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.session-card.active {
    border-color: var(--primary-color);
    background: #f0f8f0;
}

.session-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.session-msisdn {
    font-weight: 600;
    color: var(--text-primary);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.session-msisdn i {
    color: var(--primary-color);
    font-size: 0.95rem;
}

.session-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.session-status.active {
    background: #e8f5e9;
    color: #2e7d32;
}

.session-status.ended {
    background: #fce4ec;
    color: #c2185b;
}

.session-details {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

/* Toast Notifications */
#toastContainer {
    position: fixed;
    top: 21px;
    right: 21px;
    z-index: 1000;
}

.toast {
    background: white;
    padding: 15px 20px;
    box-shadow: var(--shadow-lg);
    margin-bottom: 10px;
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

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

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

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

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

.toast-icon {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

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

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

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

.toast-message {
    flex: 1;
    color: var(--text-primary);
}

/* Scrollbar Styling */
.history-content::-webkit-scrollbar,
.sessions-content::-webkit-scrollbar,
.ussd-content::-webkit-scrollbar {
    width: 8px;
}

.history-content::-webkit-scrollbar-track,
.sessions-content::-webkit-scrollbar-track,
.ussd-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.history-content::-webkit-scrollbar-thumb,
.sessions-content::-webkit-scrollbar-thumb,
.ussd-content::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

.history-content::-webkit-scrollbar-thumb:hover,
.sessions-content::-webkit-scrollbar-thumb:hover,
.ussd-content::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .phone-device {
        width: min(320px, 100%);
        max-width: 320px;
    }

    .phone-frame {
        max-width: min(320px, 100%);
    }

    .main-content {
        gap: 20px;
    }
}
