/* ==========================================================================
   Nokia 3310 USSD Simulator - Complete Stylesheet
   Aligned to index.php HTML class names
   ========================================================================== */

/* --------------------------------------------------------------------------
   Design Tokens
   -------------------------------------------------------------------------- */

:root {
    --phone-body: #2c3e50;
    --phone-body-accent: #34495e;
    --lcd-bg: #9bbc0f;
    --lcd-text: #0f380f;
    --lcd-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.3);
    --key-bg: #3d566e;
    --key-text: #ecf0f1;
    --key-active: #2c3e50;
    --key-sub: #8fa4b8;
    --btn-send: #27ae60;
    --btn-end: #e74c3c;
    --log-success: #27ae60;
    --log-error: #e74c3c;
    --log-bg: #1a1a2e;
    --log-text: #e0e0e0;
    --log-entry-bg: #16213e;
    --modal-overlay: rgba(0, 0, 0, 0.6);
}

/* --------------------------------------------------------------------------
   Reset & Base
   -------------------------------------------------------------------------- */

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

body {
    background: #0f0f23;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
}

/* --------------------------------------------------------------------------
   Page Layout
   -------------------------------------------------------------------------- */

.simulator-container {
    display: flex;
    flex-direction: row;
    gap: 30px;
    justify-content: center;
    align-items: flex-start;
    padding: 40px;
    min-height: 100vh;
}

/* --------------------------------------------------------------------------
   LEFT PANEL: Nokia Phone
   -------------------------------------------------------------------------- */

.phone-panel {
    flex-shrink: 0;
}

.nokia-phone {
    background: var(--phone-body);
    width: 280px;
    padding: 20px 15px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Speaker Grille */
.phone-speaker {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 8px 0 12px;
}

.speaker-hole {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #1a252f;
}

/* Screen Bezel */
.phone-screen-bezel {
    background: #222;
    border-radius: 6px;
    padding: 4px;
}

/* Screen */
.phone-screen {
    background: var(--lcd-bg);
    border-radius: 3px;
    box-shadow: var(--lcd-shadow);
    height: 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Screen Title Bar */
.screen-title-bar {
    text-align: center;
    font-size: 10px;
    padding: 6px;
    color: var(--lcd-text);
    opacity: 0.6;
    font-family: "Press Start 2P", "Courier New", monospace;
}

/* Screen Separator */
.screen-separator {
    height: 1px;
    background: rgba(15, 56, 15, 0.3);
}

/* Screen Content */
.screen-content {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    font-family: "Press Start 2P", "Courier New", monospace;
    font-size: 11px;
    line-height: 1.6;
    color: var(--lcd-text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Screen Input Area */
.screen-input-area {
    margin-top: auto;
}

.screen-input {
    border-top: 1px solid rgba(15, 56, 15, 0.3);
    padding: 8px 12px;
    min-height: 28px;
    font-family: "Press Start 2P", "Courier New", monospace;
    font-size: 11px;
    color: var(--lcd-text);
    display: flex;
    align-items: center;
}

/* Blinking Cursor */
.blinking-cursor {
    display: inline-block;
    animation: blink 1s step-end infinite;
    font-family: "Press Start 2P", "Courier New", monospace;
}

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

/* Soft Keys */
.soft-keys {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 5px;
    margin-top: 8px;
}

.soft-key {
    background: transparent;
    border: none;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 4px;
    color: var(--key-sub);
}

.soft-key:hover {
    opacity: 0.8;
}

.soft-key-send {
    color: var(--btn-send);
}

.soft-key-cancel {
    color: var(--btn-end);
}

.soft-key-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--key-sub);
}

.soft-key-send .soft-key-dot {
    background: var(--btn-send);
}

.soft-key-cancel .soft-key-dot {
    background: var(--btn-end);
}

/* Nav Ring */
.nav-ring {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid var(--key-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-ring-inner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--key-bg);
}

/* Call Buttons */
.call-buttons {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 10px 5px;
    margin-top: 4px;
}

.call-button {
    width: 50px;
    height: 36px;
    border-radius: 18px;
    border: none;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.1s ease;
}

.call-button-dial {
    background: var(--btn-send);
    color: white;
}

.call-button-end {
    background: var(--btn-end);
    color: white;
}

.call-button:hover {
    filter: brightness(1.1);
}

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

.call-icon {
    pointer-events: none;
}

/* Keypad */
.keypad {
    padding: 8px 5px;
    margin-top: 4px;
}

.keypad-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.keypad-row:last-child {
    margin-bottom: 0;
}

/* Key Button */
.key {
    background: var(--key-bg);
    color: var(--key-text);
    border: none;
    border-radius: 8px;
    flex: 1;
    height: 44px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.key:hover {
    background: #4a6a85;
}

.key:active {
    transform: scale(0.95);
    background: var(--key-active);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.key-main {
    font-size: 16px;
    line-height: 1;
}

.key-sub {
    font-size: 7px;
    color: var(--key-sub);
    letter-spacing: 1px;
    margin-top: 1px;
}

/* Phone Bottom */
.phone-bottom {
    padding-top: 10px;
}

.phone-brand {
    text-align: center;
    font-size: 14px;
    letter-spacing: 4px;
    color: #8fa4b8;
    font-weight: bold;
}

/* --------------------------------------------------------------------------
   RIGHT PANEL
   -------------------------------------------------------------------------- */

.right-panel {
    flex: 1;
    max-width: 550px;
    min-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* --------------------------------------------------------------------------
   Network Log Panel
   -------------------------------------------------------------------------- */

.network-log-section {
    background: var(--log-bg);
    border-radius: 10px;
    flex: 1;
    min-height: 400px;
    max-height: 600px;
    display: flex;
    flex-direction: column;
}

/* Log Header */
.network-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.network-log-title {
    color: var(--log-text);
    font-size: 14px;
}

.network-log-actions {
    display: flex;
    gap: 8px;
}

/* Network Log Entries Container */
.network-log {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.network-log-empty {
    color: #555;
    text-align: center;
    padding: 40px 20px;
    font-size: 13px;
}

.network-log-empty p {
    margin-bottom: 4px;
}

/* Log Footer */
.network-log-footer {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* --------------------------------------------------------------------------
   Generic Button System (matches HTML .btn .btn-small .btn-outline etc.)
   -------------------------------------------------------------------------- */

.btn {
    border: none;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    padding: 8px 16px;
    transition: filter 0.1s ease;
}

.btn:hover {
    filter: brightness(1.1);
}

.btn-small {
    padding: 4px 10px;
    font-size: 11px;
}

.btn-tiny {
    padding: 2px 8px;
    font-size: 12px;
}

.btn-primary {
    background: #3498db;
    color: white;
}

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

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

.btn-outline {
    background: rgba(255, 255, 255, 0.1);
    color: var(--log-text);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --------------------------------------------------------------------------
   Log Entry (JS-generated via createLogEntryElement)
   -------------------------------------------------------------------------- */

.log-entry {
    background: var(--log-entry-bg);
    border-radius: 6px;
    margin-bottom: 6px;
    border-left: 3px solid var(--log-success);
    overflow: hidden;
}

.log-entry--error {
    border-left-color: var(--log-error);
}

.log-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 12px;
    color: var(--log-text);
}

.log-entry-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.log-entry-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.log-entry-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.log-timestamp {
    color: #666;
    font-size: 11px;
    flex-shrink: 0;
}

.log-method {
    font-weight: bold;
    font-size: 11px;
    flex-shrink: 0;
}

.log-url {
    color: #888;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.log-duration {
    color: #888;
    font-size: 11px;
    flex-shrink: 0;
}

.log-toggle-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 10px;
    padding: 2px;
}

/* Status Badge */
.log-status-badge {
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}

.status-badge--success {
    background: rgba(39, 174, 96, 0.2);
    color: var(--log-success);
}

.status-badge--error {
    background: rgba(231, 76, 60, 0.2);
    color: var(--log-error);
}

.status-badge--warning {
    background: rgba(241, 196, 15, 0.2);
    color: #f1c40f;
}

/* Log Detail */
.log-entry-detail {
    padding: 0 12px 12px;
    font-size: 11px;
    color: #aaa;
}

.log-entry.expanded .log-entry-detail {
    display: block;
}

/* Log Tabs */
.log-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
}

.log-tab {
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.05);
    color: #888;
    border: none;
    font-size: 11px;
    cursor: pointer;
}

.log-tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--log-text);
}

.log-tab-content {
    /* tab content containers */
}

/* Log Pre */
.log-pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 11px;
    white-space: pre-wrap;
    color: #ccc;
    margin: 0;
}

.log-request-body,
.log-response-body {
    font-family: "Courier New", monospace;
    font-size: 11px;
}

/* --------------------------------------------------------------------------
   Settings Bar
   -------------------------------------------------------------------------- */

.settings-bar {
    background: var(--log-bg);
    border-radius: 10px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.settings-bar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-label {
    color: #888;
    font-size: 12px;
    white-space: nowrap;
}

/* Settings Inputs (by ID for specificity + class fallback) */
#endpoint-select,
#phone-number,
#ussd-code,
.settings-select,
.settings-input {
    background: var(--log-entry-bg);
    color: var(--log-text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    outline: none;
}

#endpoint-select:focus,
#phone-number:focus,
#ussd-code:focus,
.settings-select:focus,
.settings-input:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

#endpoint-select {
    flex: 1;
    min-width: 150px;
}

#phone-number {
    width: 140px;
}

#ussd-code {
    width: 120px;
}

/* --------------------------------------------------------------------------
   Settings Modal (class="modal-overlay" in HTML, toggled via JS display)
   -------------------------------------------------------------------------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay[style*="flex"] {
    /* When JS sets display:flex, this ensures alignment */
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--modal-overlay);
}

.modal-card {
    position: relative;
    background: #1a1a2e;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

/* Modal Header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-title {
    color: var(--log-text);
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

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

/* Modal Body */
.modal-body {
    display: flex;
    min-height: 400px;
}

/* Modal Sidebar (left: endpoint list) */
.modal-sidebar {
    width: 200px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
}

.modal-sidebar-header {
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-sidebar-header h4 {
    color: var(--log-text);
    font-size: 12px;
}

.modal-sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.preset-row {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.preset-row .settings-select {
    flex: 1;
    font-size: 11px;
    padding: 4px 6px;
}

/* Endpoint List */
.endpoint-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.endpoint-list-item {
    padding: 8px 12px;
    cursor: pointer;
    color: #aaa;
    font-size: 12px;
    border-radius: 4px;
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
}

.endpoint-list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.endpoint-list-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--log-text);
}

.endpoint-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.endpoint-item-method {
    font-size: 10px;
    color: #666;
    margin-left: 6px;
    flex-shrink: 0;
}

/* Modal Form (right side) */
.modal-form {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
}

/* Form Group */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    color: #888;
    font-size: 11px;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.form-hint {
    color: #555;
    font-size: 11px;
    margin-bottom: 8px;
}

/* Form Input */
.form-input {
    width: 100%;
    background: var(--log-entry-bg);
    color: var(--log-text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
}

.form-input:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

.form-input-small {
    width: auto;
    flex: 1;
}

.form-select {
    width: 100%;
    background: var(--log-entry-bg);
    color: var(--log-text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 13px;
    outline: none;
}

.form-select:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

/* Form Row (side-by-side groups) */
.form-row {
    display: flex;
    gap: 12px;
}

.form-group-half {
    flex: 1;
}

/* Radio Group */
.radio-group {
    display: flex;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--log-text);
    font-size: 12px;
    cursor: pointer;
}

/* Param Mapping */
.param-mapping {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.param-mapping-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.param-label {
    color: #888;
    font-size: 12px;
    min-width: 100px;
    font-family: "Courier New", monospace;
}

.param-arrow {
    color: #555;
    flex-shrink: 0;
}

/* Custom Headers */
.custom-headers {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.custom-header-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.custom-header-row .form-input {
    flex: 1;
    width: auto;
}

.btn-remove-header {
    background: rgba(231, 76, 60, 0.2);
    color: var(--btn-end);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
}

.btn-add-header-action {
    width: 100%;
    margin-top: 4px;
    border: 1px dashed rgba(255, 255, 255, 0.2) !important;
    background: rgba(255, 255, 255, 0.05);
}

/* Modal Footer */
.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    gap: 8px;
}

.modal-footer-left {
    display: flex;
    gap: 8px;
}

.modal-footer-right {
    display: flex;
    gap: 8px;
}

.btn-close-modal {
    /* inherits from .btn .btn-outline */
}

/* --------------------------------------------------------------------------
   Loading State
   -------------------------------------------------------------------------- */

.loading .screen-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --------------------------------------------------------------------------
   Scrollbar Styling (Dark Panels)
   -------------------------------------------------------------------------- */

.network-log::-webkit-scrollbar,
.screen-content::-webkit-scrollbar,
.endpoint-list::-webkit-scrollbar,
.modal-form::-webkit-scrollbar {
    width: 6px;
}

.network-log::-webkit-scrollbar-track,
.screen-content::-webkit-scrollbar-track,
.endpoint-list::-webkit-scrollbar-track,
.modal-form::-webkit-scrollbar-track {
    background: transparent;
}

.network-log::-webkit-scrollbar-thumb,
.screen-content::-webkit-scrollbar-thumb,
.endpoint-list::-webkit-scrollbar-thumb,
.modal-form::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.network-log::-webkit-scrollbar-thumb:hover,
.screen-content::-webkit-scrollbar-thumb:hover,
.endpoint-list::-webkit-scrollbar-thumb:hover,
.modal-form::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
    .simulator-container {
        flex-direction: column;
        align-items: center;
        padding: 20px;
    }

    .right-panel {
        min-width: unset;
        width: 100%;
        max-width: 500px;
    }

    .modal-body {
        flex-direction: column;
    }

    .modal-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
}
