/* Base styles and mobile optimizations */
* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%; /* Prevent font scaling in iOS */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin: 0;
    padding: 0;
    color: #333;
    min-height: 100vh;
    overflow-x: hidden; /* Prevent horizontal scroll */
    /* Safe area insets for iPhone */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    color: #2c3e50;
    padding: 8px 0;
    text-align: center;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    align-items: center;
}

.header-logo {
    height: 48px;
    width: 48px;
    margin-left: 20px;
}

.header-button {
    background: #667eea;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    margin-right: 20px;
    transition: background 0.3s ease;
}
.header-button:hover {
    background: #5a67d8;
}


header h1 {
    margin: 0;
    font-size: 2.2em;
    font-weight: 300;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

main {
    width: 75%;
    max-width: 100vw;
    height: 100%;
    margin: 16px auto;
    padding: 0 16px;
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 12px 24px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
    /* Safe area insets with fallback */
    margin-left: max(0px, env(safe-area-inset-left));
    margin-right: max(0px, env(safe-area-inset-right));
}

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

.status-label {
    font-weight: 600;
    color: #666;
    font-size: 14px;
}

.status-value {
    font-weight: 500;
    font-size: 14px;
}

.status-value.connected {
    color: #28a745;
}

.status-value.disconnected {
    color: #dc3545;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.transaction-card {
    grid-column: 1 / -1;
}

/* Metric Cards */
.metric-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
    transition: all 0.3s ease;
}

.metric-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px 16px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

.card-header h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.3em;
    font-weight: 600;
}

.card-icon {
    font-size: 1.5em;
    opacity: 0.8;
}

.card-content {
    padding: 16px 24px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.metric:last-child {
    border-bottom: none;
}

.metric-label {
    font-weight: 500;
    color: #666;
    font-size: 14px;
}

.metric-value {
    font-weight: 600;
    color: #2c3e50;
    font-size: 16px;
    text-align: right;
}

.metric-value.status-good {
    color: #28a745;
}

.metric-value.status-warning {
    color: #ffc107;
}

.metric-value.status-error {
    color: #dc3545;
}

.metric-value.hash {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 400;
}

/* Transaction Card */
.transaction-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.transaction-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 0;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.transaction {
    background: rgba(248, 249, 250, 0.8);
    padding: 15px 20px;
    margin: 8px;
    border-radius: 10px;
    border-left: 4px solid #667eea;
    transition: all 0.3s ease;
    position: relative;
    backdrop-filter: blur(5px);
    min-height: 44px; /* iOS touch target requirement */
    cursor: pointer;
}

.transaction:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateX(5px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.transaction.new-transaction {
    animation: slideIn 0.6s ease-out;
    background: linear-gradient(135deg, rgba(40, 167, 69, 0.1) 0%, rgba(255, 255, 255, 0.9) 100%);
    border-left-color: #28a745;
    box-shadow: 0 4px 15px rgba(40, 167, 69, 0.2);
}

.transaction.new-transaction::before {
    content: '⚡';
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 16px;
    animation: pulse 2s infinite;
}

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

.transaction-type {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.transaction.new-transaction .transaction-type {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.transaction-time {
    color: #6c757d;
    font-size: 12px;
    font-weight: 500;
}

.transaction-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 13px;
}

.transaction-details p {
    margin: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.transaction-details strong {
    color: #495057;
    font-weight: 600;
    min-width: 60px;
}

.hash, .tx-hash, .account {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    color: #6c757d;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.no-transactions {
    text-align: center;
    padding: 60px 20px;
    color: #6c757d;
    font-style: italic;
    font-size: 16px;
}

.error {
    text-align: center;
    padding: 40px;
    color: #dc3545;
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.2);
    border-radius: 8px;
    margin: 20px;
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Transaction Bucket Styles */
.transaction-bucket {
    width: 100%;
}

.transaction-bucket canvas {
    width: 100% !important;
    height: auto !important;
    max-width: 100%;
    display: block;
}

.transaction-legend {
    margin-top: 15px;
    padding: 15px;
    background: rgba(248, 249, 250, 0.8);
    border-radius: 8px;
    backdrop-filter: blur(5px);
}

.legend-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 10px;
    font-size: 14px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.legend-item {
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #666;
}

.color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* Transaction Bucket Responsive Styles */
@media (max-width: 480px) {
    .transaction-bucket {
        margin: 0 -8px; /* Use negative margins instead of full-width hack */
        width: calc(100% + 16px); /* Account for parent padding */
    }

    .transaction-bucket canvas {
        width: 100% !important;
        max-width: 100vw !important;
    }

    .transaction-legend {
        margin: 10px;
        padding: 12px;
    }

    .legend-items {
        justify-content: space-around;
        gap: 8px;
        flex-wrap: wrap;
    }

    .legend-item {
        font-size: 10px;
        flex: 0 0 auto;
        min-width: 80px;
    }

    .color-dot {
        width: 6px;
        height: 6px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .legend-items {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
        justify-content: center;
    }

    .legend-item {
        font-size: 11px;
        flex: 0 0 auto;
    }
}/* Transaction Modal */
.tx-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.tx-modal-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 25px;
    border-radius: 16px;
    min-width: 320px;
    max-width: 500px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: modalSlideIn 0.3s ease-out;
}

.tx-modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    cursor: pointer;
    color: #666;
    transition: color 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tx-modal-close:hover {
    color: #333;
}

.tx-modal-content h3 {
    margin: 0 0 20px 0;
    color: #2c3e50;
    font-size: 1.4em;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tx-details p {
    margin: 12px 0;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.tx-details p:last-child {
    border-bottom: none;
}

.tx-details strong {
    color: #495057;
    font-weight: 600;
    min-width: 100px;
}

.tx-hash, .account {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px 8px;
    border-radius: 6px;
    color: #6c757d;
    word-break: break-all;
}

/* Animations */
@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Responsive Design - Mobile First Approach */
/* Small phones: 320px - 480px */
@media (max-width: 480px) {
    main {
        width: 100%;
        margin: 8px auto;
        padding: 0 8px 16px;
    }

    header h1 {
        font-size: 1rem;
    }

    .header-button {
        padding: 8px 16px;
        font-size: 12px;
        margin-right: 10px;
    }

    .status-bar {
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .card-header {
        padding: 15px;
    }

    .card-header h2 {
        font-size: 1.1em;
    }

    .card-content {
        padding: 8px;
    }

    .transaction {
        padding: 12px;
        margin: 5px;
    }

    .transaction-list {
        max-height: 300px;
    }

    .tx-modal-content {
        min-width: 280px;
        max-width: 90vw;
        margin: 20px;
    }

    .tx-details p {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .tx-details strong {
        min-width: auto;
    }
}

/* Large phones and small tablets: 481px - 768px */
@media (min-width: 481px) and (max-width: 768px) {
    header h1 {
        font-size: 1.8em;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .status-bar {
        padding: 12px 20px;
    }

    .transaction-list {
        max-height: 350px;
    }
}

/* Tablets and small desktops: 769px - 1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .transaction-card {
        grid-column: 1 / -1;
    }
}

/* Large screens: 1025px+ */
@media (min-width: 1025px) {
    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .transaction-bucket canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .transaction-bucket canvas {
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        -webkit-tap-highlight-color: transparent;
    }

    .tx-modal-content {
        -webkit-overflow-scrolling: touch;
    }
}

/* Real mobile device optimizations */
@media (pointer: coarse) {
    .transaction-bucket {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    .transaction-bucket canvas {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        -webkit-perspective: 1000px;
        perspective: 1000px;
    }
}