/* === Global === */
body {
    background: #f0f2f5;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.container {
    max-width: 960px;
    padding-top: 16px;
    padding-bottom: 32px;
}

.content {
    padding: 10px 0;
}

/* === Page Header === */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.6em;
    font-weight: 700;
    color: #1a1a2e;
}

.app-version {
    font-size: 0.5em;
    color: #888;
    font-weight: normal;
}

/* === Connection badge === */
.connection-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 500;
}

.connection-badge.disconnected {
    background: #f8d7da;
    color: #721c24;
}

.connection-badge.connected {
    background: #d4edda;
    color: #155724;
}

.connection-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.connection-badge.disconnected .connection-dot {
    background: #dc3545;
}

.connection-badge.connected .connection-dot {
    background: #28a745;
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {

    0%,
    100% {
        box-shadow: 0 0 2px #28a745;
    }

    50% {
        box-shadow: 0 0 6px #28a745;
    }
}

/* === Cards === */
.card {
    background: #fff;
    border: none;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    margin-bottom: 12px;
    overflow: hidden;
}

.card-header {
    background: #1a73e8;
    color: #fff;
    font-weight: 600;
    font-size: 0.9em;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.card-body {
    padding: 16px;
}

/* === Collapsible sections === */
.card-header-collapsible {
    cursor: pointer;
    justify-content: space-between;
    user-select: none;
}

.card-header-collapsible:hover {
    background: #1565c0;
}

.section-collapse-icon {
    transition: transform 0.2s;
}

.section-collapse-icon.open {
    transform: rotate(90deg);
}

.card-body-collapsed {
    display: none;
    padding: 16px;
}

.card-body-collapsed.open {
    display: block;
}

/* === Two-column layout === */
.two-col-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
}

@media (max-width: 768px) {
    .two-col-layout {
        grid-template-columns: 1fr;
    }
}

/* === Server collapsible bar === */
.srv-bar {
    margin-bottom: 12px;
}

.card-header-bar {
    background: #fff;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid #e9ecef;
    transition: background 0.15s;
}

.card-header-bar:hover {
    background: #f8f9fa;
}

.srv-bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9em;
    color: #333;
}

.srv-bar-left i.bi-cloud {
    color: #1a73e8;
    font-size: 1.1em;
}

.srv-bar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.srv-bar-summary {
    font-size: 0.8em;
    color: #666;
}

.srv-collapse-icon {
    transition: transform 0.2s;
    color: #999;
}

.srv-collapse-icon.open {
    transform: rotate(180deg);
}

.card-body-collapsible {
    padding: 12px 16px;
    display: none;
}

.card-body-collapsible.open {
    display: block;
}

/* === Server config === */
.srv-config {
    margin: 0;
}

.srv-login-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.srv-login-row .srv-field {
    flex: 1;
}

.srv-login-row .btn {
    white-space: nowrap;
    height: 31px;
}

.srv-logged-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.srv-session-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

#srv-user-info {
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
}

#srv-status {
    margin-top: 8px;
    font-size: 0.85em;
    padding: 6px 10px;
    border-radius: 4px;
}

#srv-status.error {
    background: #f8d7da;
    color: #721c24;
}

.srv-token-expiry {
    font-size: 0.75em;
    color: #888;
}

.srv-token-expiry.expiry-warning {
    color: #e0a800;
    font-weight: 600;
}

.srv-token-expiry.expiry-danger {
    color: #dc3545;
    font-weight: 600;
}

/* === Server badge === */
.srv-server-badge {
    font-size: 0.75em;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
}

.srv-server-badge i {
    font-size: 0.6em;
}

.srv-server-badge.online {
    background: #d4edda;
    color: #155724;
}

.srv-server-badge.offline {
    background: #f8d7da;
    color: #721c24;
}


/* === Device lookup status === */
#srv-device-status {
    margin-top: 8px;
    font-size: 0.8em;
    padding: 4px 8px;
    border-radius: 4px;
}

#srv-device-status.device-found {
    background: #d4edda;
    color: #155724;
}

#srv-device-status.device-not-found {
    background: #fff3cd;
    color: #856404;
}

#srv-device-status.device-searching {
    background: #e9ecef;
    color: #666;
}

/* === Device info table (inside card) === */
.card-body table {
    width: 100%;
    border-collapse: collapse;
}

.card-body table th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8em;
    color: #fff;
    background: #1a73e8;
    white-space: nowrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.card-body table td {
    padding: 8px 12px;
    text-align: left;
    font-size: 0.85em;
    background: #fff;
    border-bottom: 1px solid #f0f0f0;
}

.card-body table tr:last-child th,
.card-body table tr:last-child td {
    border-bottom: none;
}

/* Image active/standby card styles inside the new card */
.image {
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}

.image.active {
    border-color: #1a73e8;
}

.image.active table th {
    background: #1a73e8;
}

.image.standby {
    border-color: #aaa;
}

.image.standby table th {
    background: #6c757d;
}

/* === NAND Storage === */
.nand-info {
    margin-bottom: 12px;
}

.nand-info table {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
}

.nand-info table th {
    width: 1%;
}

.nand-bar-container {
    position: relative;
    height: 22px;
    background: #e9ecef;
    border-radius: 11px;
    margin-top: 10px;
    overflow: hidden;
}

.nand-bar-fill {
    height: 100%;
    border-radius: 11px;
    background: linear-gradient(90deg, #1a73e8, #1565c0);
    transition: width 0.5s ease;
    min-width: 0;
}

.nand-bar-fill.bar-warning {
    background: linear-gradient(90deg, #ffc107, #e0a800);
}

.nand-bar-fill.bar-danger {
    background: linear-gradient(90deg, #dc3545, #bd2130);
}

.nand-bar-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.7em;
    font-weight: 600;
    color: #333;
}

.nand-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}

/* === Sync readiness === */
.sync-readiness {
    margin: 10px 0;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8em;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sync-readiness.sync-ready {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.sync-readiness.sync-partial {
    background: #fff3cd;
    border: 1px solid #ffeeba;
    color: #856404;
}

.sync-readiness.sync-not-ready {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

/* === Progress bars === */
#nand-fetch-progress {
    margin-top: 10px;
}

.progress-bar-container {
    height: 18px;
    background: #e9ecef;
    border-radius: 9px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 9px;
    background: linear-gradient(90deg, #1a73e8, #4285f4);
    transition: width 0.3s ease;
    width: 0%;
}

.progress-bar-fill.progress-bar-done {
    background: linear-gradient(90deg, #28a745, #20c997);
}

.progress-bar-fill.progress-bar-error {
    background: linear-gradient(90deg, #dc3545, #bd2130);
}

.progress-bar-fill.progress-bar-empty {
    background: #6c757d;
}

.progress-bar-fill.progress-bar-pulse {
    background: linear-gradient(90deg, #1a73e8, #4285f4, #1a73e8);
    background-size: 200% 100%;
    animation: pulse-bar 1.5s ease-in-out infinite;
}

@keyframes pulse-bar {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

.progress-bar-text {
    font-size: 0.8em;
    font-weight: 500;
    color: #555;
    margin-top: 4px;
    display: block;
}

/* === NAND status & result === */
#nand-status {
    margin-top: 10px;
    padding: 8px 12px;
    background: #e9ecef;
    border-radius: 4px;
    font-size: 0.85em;
}

#nand-result {
    margin-top: 10px;
}

/* === Firmware upload === */
.firmware-card .card-body-collapsed {
    padding: 24px;
    flex-direction: column;
    gap: 16px;
}

.firmware-card .card-body-collapsed.open {
    display: flex;
}

.firmware-card .form-group {
    margin: 0;
}

.firmware-card .btn {
    align-self: flex-start;
}

.file-status {
    margin: 0;
    color: #666;
    font-size: 0.9em;
}

/* === Battery icon === */
.battery-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 0.85em;
    white-space: nowrap;
}

.battery-icon {
    display: inline-block;
    width: 26px;
    height: 13px;
    border: 2px solid #555;
    border-radius: 3px;
    position: relative;
    background: #fff;
}

.battery-icon::after {
    content: '';
    position: absolute;
    right: -5px;
    top: 2px;
    width: 3px;
    height: 5px;
    background: #555;
    border-radius: 0 2px 2px 0;
}

.battery-icon .battery-level {
    height: 100%;
    border-radius: 1px;
    transition: width 0.3s, background 0.3s;
}

.battery-level.battery-high {
    background: #28a745;
}

.battery-level.battery-medium {
    background: #ffc107;
}

.battery-level.battery-low {
    background: #dc3545;
}

.battery-charging {
    font-size: 0.75em;
    color: #28a745;
}

/* === Device Debug section === */
.device-debug {
    font-size: 0.9em;
}

.debug-empty {
    color: #888;
    font-style: italic;
}

.debug-block + .debug-block {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.debug-title {
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    font-size: 0.75em;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.provision-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95em;
}

.provision-status.ok {
    color: #28a745;
}

.provision-status.fail {
    color: #dc3545;
    font-weight: 600;
}

.debug-table {
    width: 100%;
    margin-top: 6px;
    border-collapse: collapse;
}

.debug-table th {
    text-align: left;
    font-weight: 500;
    color: #666;
    padding: 2px 8px 2px 0;
    white-space: nowrap;
    vertical-align: top;
    width: 1%;
}

.debug-table td {
    padding: 2px 0;
    word-break: break-word;
}

.debug-table code {
    font-size: 0.85em;
    background: #f4f4f4;
    padding: 1px 5px;
    border-radius: 3px;
}

.debug-servermsg {
    color: #dc3545;
}

.debug-hint {
    margin-top: 8px;
    padding: 6px 8px;
    background: #fff8e1;
    border-left: 3px solid #ffc107;
    border-radius: 3px;
    color: #7a5b00;
    font-size: 0.9em;
}

/* === Copy IMEI button === */
.copy-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 1px 6px;
    margin-left: 6px;
    cursor: pointer;
    font-size: 0.75em;
    color: #666;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: #e9ecef;
    border-color: #999;
    color: #333;
}

.copy-btn.copied {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
}

/* === Toast notifications === */
.toast-notification {
    position: fixed;
    top: 16px;
    right: 20px;
    padding: 12px 18px;
    border-radius: 8px;
    color: #fff;
    font-weight: 500;
    font-size: 0.85em;
    z-index: 9999;
    animation: toast-in 0.3s ease, toast-out 0.3s ease 4.7s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toast-notification.toast-info {
    background: #1a73e8;
}

.toast-notification.toast-success {
    background: #28a745;
}

.toast-notification.toast-warning {
    background: #ffc107;
    color: #333;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}